mirror of
https://github.com/lxc/lxcfs.git
synced 2026-02-05 09:46:18 +01:00
lxcfs: add enable-psi-poll cmdline option
Let's make PSI triggers virtulization opt-in feature. Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
This commit is contained in:
@@ -142,17 +142,19 @@ struct lxcfs_opts {
|
||||
* and the use of bool instead of explicited __u32 and __u64 we can't.
|
||||
*/
|
||||
__u32 version;
|
||||
// As of opts version 2.
|
||||
char runtime_path[PATH_MAX];
|
||||
// As of opts version 2.
|
||||
char runtime_path[PATH_MAX];
|
||||
bool zswap_off;
|
||||
bool psi_poll_on;
|
||||
};
|
||||
|
||||
typedef enum lxcfs_opt_t {
|
||||
LXCFS_SWAP_ON = 0,
|
||||
LXCFS_PIDFD_ON = 1,
|
||||
LXCFS_CFS_ON = 2,
|
||||
LXCFS_ZSWAP_ON = 3,
|
||||
LXCFS_OPTS_MAX = LXCFS_ZSWAP_ON,
|
||||
LXCFS_SWAP_ON = 0,
|
||||
LXCFS_PIDFD_ON = 1,
|
||||
LXCFS_CFS_ON = 2,
|
||||
LXCFS_ZSWAP_ON = 3,
|
||||
LXCFS_PSI_POLL_ON = 4,
|
||||
LXCFS_OPTS_MAX = LXCFS_PSI_POLL_ON,
|
||||
} lxcfs_opt_t;
|
||||
|
||||
|
||||
@@ -189,6 +191,8 @@ static inline bool lxcfs_has_opt(struct lxcfs_opts *opts, lxcfs_opt_t opt)
|
||||
if (opts->version >= 3 && !opts->zswap_off)
|
||||
return liblxcfs_can_use_zswap();
|
||||
return false;
|
||||
case LXCFS_PSI_POLL_ON:
|
||||
return (opts->version >= 4 && opts->psi_poll_on);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -976,6 +976,7 @@ static const struct option long_options[] = {
|
||||
{"enable-cfs", no_argument, 0, 0 },
|
||||
{"enable-pidfd", no_argument, 0, 0 },
|
||||
{"enable-cgroup", no_argument, 0, 0 },
|
||||
{"enable-psi-poll", no_argument, 0, 0 },
|
||||
|
||||
{"pidfile", required_argument, 0, 'p' },
|
||||
{"runtime-dir", required_argument, 0, 0 },
|
||||
@@ -1050,7 +1051,8 @@ int main(int argc, char *argv[])
|
||||
opts->zswap_off = false;
|
||||
opts->use_pidfd = false;
|
||||
opts->use_cfs = false;
|
||||
opts->version = 3;
|
||||
opts->psi_poll_on = false;
|
||||
opts->version = 4;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "dulfhvso:p:", long_options, &idx)) != -1) {
|
||||
switch (c) {
|
||||
@@ -1061,6 +1063,8 @@ int main(int argc, char *argv[])
|
||||
opts->use_cfs = true;
|
||||
else if (strcmp(long_options[idx].name, "enable-cgroup") == 0)
|
||||
cgroup_is_enabled = true;
|
||||
else if (strcmp(long_options[idx].name, "enable-psi-poll") == 0)
|
||||
opts->psi_poll_on = true;
|
||||
else if (strcmp(long_options[idx].name, "runtime-dir") == 0)
|
||||
runtime_path_arg = optarg;
|
||||
else
|
||||
|
||||
@@ -1938,6 +1938,7 @@ static int proc_psi_trigger_write(const char *path, const char *buf, size_t size
|
||||
off_t offset, struct fuse_file_info *fi)
|
||||
{
|
||||
struct fuse_context *fc = fuse_get_context();
|
||||
bool psi_virtualization_enabled = lxcfs_has_opt(fc->private_data, LXCFS_PSI_POLL_ON);
|
||||
struct file_info *f = INTTYPE_TO_PTR(fi->fh);
|
||||
__do_free psi_trigger_t *t = NULL;
|
||||
__do_free char *cgroup = NULL;
|
||||
@@ -1955,6 +1956,9 @@ static int proc_psi_trigger_write(const char *path, const char *buf, size_t size
|
||||
if (!liblxcfs_functional())
|
||||
return -EIO;
|
||||
|
||||
if (!psi_virtualization_enabled)
|
||||
return -EINVAL;
|
||||
|
||||
/* mimic logic from kernel/sched/psi.c psi_write() */
|
||||
if (f->private_data)
|
||||
return -EBUSY;
|
||||
|
||||
@@ -51,7 +51,7 @@ if [ -x ${lxcfs} ]; then
|
||||
export LD_LIBRARY_PATH="{{LXCFS_BUILD_ROOT}}"
|
||||
fi
|
||||
echo "=> Spawning ${lxcfs} ${LXCFSDIR}"
|
||||
${lxcfs} --enable-cgroup -p ${pidfile} ${LXCFSDIR} &
|
||||
${lxcfs} --enable-cgroup --enable-psi-poll -p ${pidfile} ${LXCFSDIR} &
|
||||
LXCFSPID=$!
|
||||
else
|
||||
UNSHARE=0
|
||||
|
||||
@@ -45,7 +45,7 @@ if [ -x ${lxcfs} ]; then
|
||||
export LD_LIBRARY_PATH="{{LXCFS_BUILD_ROOT}}"
|
||||
fi
|
||||
echo "=> Spawning ${lxcfs} ${LXCFSDIR}"
|
||||
${lxcfs} --enable-cgroup -p ${pidfile} ${LXCFSDIR} &
|
||||
${lxcfs} --enable-cgroup --enable-psi-poll -p ${pidfile} ${LXCFSDIR} &
|
||||
LXCFSPID=$!
|
||||
else
|
||||
UNSHARE=0
|
||||
|
||||
Reference in New Issue
Block a user