virprocess.h 3.8 KB
Newer Older
1 2 3
/*
 * virprocess.h: interaction with processes
 *
4
 * Copyright (C) 2010-2015 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

22
#pragma once
23

24
#include <sys/types.h>
25

26 27 28 29
#include "internal.h"
#include "virbitmap.h"
#include "virutil.h"
#include "virenum.h"
30 31 32 33 34 35 36 37 38 39 40 41

typedef enum {
    VIR_PROC_POLICY_NONE = 0,
    VIR_PROC_POLICY_BATCH,
    VIR_PROC_POLICY_IDLE,
    VIR_PROC_POLICY_FIFO,
    VIR_PROC_POLICY_RR,

    VIR_PROC_POLICY_LAST
} virProcessSchedPolicy;

VIR_ENUM_DECL(virProcessSchedPolicy);
42

43 44 45 46 47 48
char *
virProcessTranslateStatus(int status);

void
virProcessAbort(pid_t pid);

49 50
void virProcessExitWithStatus(int status) ATTRIBUTE_NORETURN;

51
int
52
virProcessWait(pid_t pid, int *exitstatus, bool raw)
53 54
    ATTRIBUTE_RETURN_CHECK;

55 56
int virProcessKill(pid_t pid, int sig);

57
int virProcessKillPainfully(pid_t pid, bool force);
58 59 60
int virProcessKillPainfullyDelay(pid_t pid,
                                 bool force,
                                 unsigned int extradelay);
61

62 63
int virProcessSetAffinity(pid_t pid, virBitmapPtr map);

64
virBitmapPtr virProcessGetAffinity(pid_t pid);
65

66 67
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids);

68 69 70
int virProcessGetStartTime(pid_t pid,
                           unsigned long long *timestamp);

71 72 73 74 75 76 77
int virProcessGetNamespaces(pid_t pid,
                            size_t *nfdlist,
                            int **fdlist);

int virProcessSetNamespaces(size_t nfdlist,
                            int *fdlist);

78 79 80
int virProcessSetMaxMemLock(pid_t pid, unsigned long long bytes);
int virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
int virProcessSetMaxFiles(pid_t pid, unsigned int files);
81
int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes);
82

83 84
int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes);

85 86 87 88
/* Callback to run code within the mount namespace tied to the given
 * pid.  This function must use only async-signal-safe functions, as
 * it gets run after a fork of a multi-threaded process.  The return
 * value of this function is passed to _exit(), except that a
89
 * negative value is treated as EXIT_CANCELED.  */
90 91 92 93 94
typedef int (*virProcessNamespaceCallback)(pid_t pid, void *opaque);

int virProcessRunInMountNamespace(pid_t pid,
                                  virProcessNamespaceCallback cb,
                                  void *opaque);
95

96 97 98 99 100 101 102 103 104 105 106 107 108 109
/**
 * virProcessForkCallback:
 * @ppid: parent's pid
 * @opaque: opaque data
 *
 * Callback to run in fork()-ed process.
 *
 * Returns: 0 on success,
 *         -1 on error (treated as EXIT_CANCELED)
 */
typedef int (*virProcessForkCallback)(pid_t ppid,
                                      void *opaque);

int virProcessRunInFork(virProcessForkCallback cb,
110 111
                        void *opaque)
    ATTRIBUTE_NOINLINE;
112

113 114
int virProcessSetupPrivateMountNS(void);

115 116 117
int virProcessSetScheduler(pid_t pid,
                           virProcessSchedPolicy policy,
                           int priority);
118 119 120 121 122 123 124 125 126 127
typedef enum {
    VIR_PROCESS_NAMESPACE_MNT = (1 << 1),
    VIR_PROCESS_NAMESPACE_IPC = (1 << 2),
    VIR_PROCESS_NAMESPACE_NET = (1 << 3),
    VIR_PROCESS_NAMESPACE_PID = (1 << 4),
    VIR_PROCESS_NAMESPACE_USER = (1 << 5),
    VIR_PROCESS_NAMESPACE_UTS = (1 << 6),
} virProcessNamespaceFlags;

int virProcessNamespaceAvailable(unsigned int ns);