Skip to content

Commit 4f8674b

Browse files
committed
lxcfs: introduce a new "lxcfs" subtree
Like we have "cgroup", "sys", "proc" subtrees, let's introduce the "lxcfs" subtree which will contain LXCFS filesystem-related data and will be used as an interface to interact and configure LXCFS in runtime. Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
1 parent 82af069 commit 4f8674b

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

src/api_extensions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static char *api_extensions[] = {
2727
"cpuview_daemon",
2828
"loadavg_daemon",
2929
"pidfds",
30+
"per_instance_configuration",
3031
};
3132

3233
static size_t nr_api_extensions = sizeof(api_extensions) / sizeof(*api_extensions);

src/bindings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,18 @@ enum lxcfs_virt_t {
7070

7171
LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE,
7272
#define LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE_PATH "/sys/devices/system/cpu/online"
73+
74+
LXC_TYPE_LXCFS,
75+
76+
7377
LXC_TYPE_MAX,
7478
};
7579

7680
/* Macros below used to check the class from the file types above */
7781
#define LXCFS_TYPE_CGROUP(type) (type >= LXC_TYPE_CGDIR && type <= LXC_TYPE_CGFILE)
7882
#define LXCFS_TYPE_PROC(type) (type >= LXC_TYPE_PROC_MEMINFO && type <= LXC_TYPE_PROC_SLABINFO)
7983
#define LXCFS_TYPE_SYS(type) (type >= LXC_TYPE_SYS && type <= LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE)
84+
#define LXCFS_TYPE_LXCFS(type) (type >= LXC_TYPE_LXCFS && type < LXC_TYPE_MAX)
8085
#define LXCFS_TYPE_OK(type) (type >= LXC_TYPE_CGDIR && type < LXC_TYPE_MAX)
8186

8287
/*

src/lxcfs.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,22 @@ static int do_##type##_##fsop(LIB_FS_##fsop##_OP_ARGS_TYPE) \
294294
DEF_LIB_FS_OP(cg , getattr)
295295
DEF_LIB_FS_OP(proc , getattr)
296296
DEF_LIB_FS_OP(sys , getattr)
297+
DEF_LIB_FS_OP(lxcfsctl, getattr)
297298

298299
#define LIB_FS_read_OP_ARGS_TYPE const char *path, char *buf, size_t size, \
299300
off_t offset, struct fuse_file_info *fi
300301
#define LIB_FS_read_OP_ARGS path, buf, size, offset, fi
301302
DEF_LIB_FS_OP(cg , read)
302303
DEF_LIB_FS_OP(proc , read)
303304
DEF_LIB_FS_OP(sys , read)
305+
DEF_LIB_FS_OP(lxcfsctl, read)
304306

305307
#define LIB_FS_write_OP_ARGS_TYPE const char *path, const char *buf, size_t size, \
306308
off_t offset, struct fuse_file_info *fi
307309
#define LIB_FS_write_OP_ARGS path, buf, size, offset, fi
308310
DEF_LIB_FS_OP(cg , write)
309311
DEF_LIB_FS_OP(sys , write)
312+
DEF_LIB_FS_OP(lxcfsctl, write)
310313

311314
#define LIB_FS_mkdir_OP_ARGS_TYPE const char *path, mode_t mode
312315
#define LIB_FS_mkdir_OP_ARGS path, mode
@@ -330,38 +333,45 @@ DEF_LIB_FS_OP(cg, chmod)
330333
DEF_LIB_FS_OP(cg , readdir)
331334
DEF_LIB_FS_OP(proc , readdir)
332335
DEF_LIB_FS_OP(sys , readdir)
336+
DEF_LIB_FS_OP(lxcfsctl, readdir)
333337

334338
#define LIB_FS_readlink_OP_ARGS_TYPE const char *path, char *buf, size_t size
335339
#define LIB_FS_readlink_OP_ARGS path, buf, size
336340
DEF_LIB_FS_OP(sys , readlink)
341+
DEF_LIB_FS_OP(lxcfsctl, readlink)
337342

338343
#define LIB_FS_open_OP_ARGS_TYPE const char *path, struct fuse_file_info *fi
339344
#define LIB_FS_open_OP_ARGS path, fi
340345
DEF_LIB_FS_OP(cg , open)
341346
DEF_LIB_FS_OP(proc , open)
342347
DEF_LIB_FS_OP(sys , open)
348+
DEF_LIB_FS_OP(lxcfsctl, open)
343349

344350
#define LIB_FS_access_OP_ARGS_TYPE const char *path, int mode
345351
#define LIB_FS_access_OP_ARGS path, mode
346352
DEF_LIB_FS_OP(cg , access)
347353
DEF_LIB_FS_OP(proc , access)
348354
DEF_LIB_FS_OP(sys , access)
355+
DEF_LIB_FS_OP(lxcfsctl, access)
349356

350357
#define LIB_FS_opendir_OP_ARGS_TYPE const char *path, struct fuse_file_info *fi
351358
#define LIB_FS_opendir_OP_ARGS path, fi
352359
DEF_LIB_FS_OP(cg , opendir)
353360
DEF_LIB_FS_OP(sys , opendir)
361+
DEF_LIB_FS_OP(lxcfsctl, opendir)
354362

355363
#define LIB_FS_release_OP_ARGS_TYPE const char *path, struct fuse_file_info *fi
356364
#define LIB_FS_release_OP_ARGS path, fi
357365
DEF_LIB_FS_OP(cg , release)
358366
DEF_LIB_FS_OP(proc , release)
359367
DEF_LIB_FS_OP(sys , release)
368+
DEF_LIB_FS_OP(lxcfsctl, release)
360369

361370
#define LIB_FS_releasedir_OP_ARGS_TYPE const char *path, struct fuse_file_info *fi
362371
#define LIB_FS_releasedir_OP_ARGS path, fi
363372
DEF_LIB_FS_OP(cg , releasedir)
364373
DEF_LIB_FS_OP(sys , releasedir)
374+
DEF_LIB_FS_OP(lxcfsctl, releasedir)
365375

366376
static bool cgroup_is_enabled = false;
367377

@@ -406,6 +416,13 @@ static int lxcfs_getattr(const char *path, struct stat *sb)
406416
return ret;
407417
}
408418

419+
if (strncmp(path, "/lxcfs", 6) == 0) {
420+
up_users();
421+
ret = do_lxcfsctl_getattr(path, sb);
422+
down_users();
423+
return ret;
424+
}
425+
409426
return -ENOENT;
410427
}
411428

@@ -433,6 +450,13 @@ static int lxcfs_opendir(const char *path, struct fuse_file_info *fi)
433450
return ret;
434451
}
435452

453+
if (strncmp(path, "/lxcfs", 6) == 0) {
454+
up_users();
455+
ret = do_lxcfsctl_opendir(path, fi);
456+
down_users();
457+
return ret;
458+
}
459+
436460
return -ENOENT;
437461
}
438462

@@ -449,6 +473,7 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
449473
if (strcmp(path, "/") == 0) {
450474
if (dir_filler(filler, buf, ".", 0) != 0 ||
451475
dir_filler(filler, buf, "..", 0) != 0 ||
476+
dir_filler(filler, buf, "lxcfs", 0) != 0 ||
452477
dir_filler(filler, buf, "proc", 0) != 0 ||
453478
dir_filler(filler, buf, "sys", 0) != 0 ||
454479
(cgroup_is_enabled && dir_filler(filler, buf, "cgroup", 0) != 0))
@@ -478,6 +503,13 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
478503
return ret;
479504
}
480505

506+
if (strncmp(path, "/lxcfs", 6) == 0) {
507+
up_users();
508+
ret = do_lxcfsctl_readdir(path, buf, filler, offset, fi);
509+
down_users();
510+
return ret;
511+
}
512+
481513
return -ENOENT;
482514
}
483515

@@ -509,6 +541,13 @@ static int lxcfs_access(const char *path, int mode)
509541
return ret;
510542
}
511543

544+
if (strncmp(path, "/lxcfs", 6) == 0) {
545+
up_users();
546+
ret = do_lxcfsctl_access(path, mode);
547+
down_users();
548+
return ret;
549+
}
550+
512551
return -EACCES;
513552
}
514553

@@ -533,6 +572,13 @@ static int lxcfs_releasedir(const char *path, struct fuse_file_info *fi)
533572
return ret;
534573
}
535574

575+
if (LXCFS_TYPE_LXCFS(type)) {
576+
up_users();
577+
ret = do_lxcfsctl_releasedir(path, fi);
578+
down_users();
579+
return ret;
580+
}
581+
536582
if (path) {
537583
if (strcmp(path, "/") == 0)
538584
return 0;
@@ -571,6 +617,13 @@ static int lxcfs_open(const char *path, struct fuse_file_info *fi)
571617
return ret;
572618
}
573619

620+
if (strncmp(path, "/lxcfs", 6) == 0) {
621+
up_users();
622+
ret = do_lxcfsctl_open(path, fi);
623+
down_users();
624+
return ret;
625+
}
626+
574627
return -EACCES;
575628
}
576629

@@ -600,6 +653,13 @@ static int lxcfs_read(const char *path, char *buf, size_t size, off_t offset,
600653
return ret;
601654
}
602655

656+
if (strncmp(path, "/lxcfs", 6) == 0) {
657+
up_users();
658+
ret = do_lxcfsctl_read(path, buf, size, offset, fi);
659+
down_users();
660+
return ret;
661+
}
662+
603663
return -EINVAL;
604664
}
605665

@@ -622,6 +682,13 @@ int lxcfs_write(const char *path, const char *buf, size_t size, off_t offset,
622682
return ret;
623683
}
624684

685+
if (strncmp(path, "/lxcfs", 6) == 0) {
686+
up_users();
687+
ret = do_lxcfsctl_write(path, buf, size, offset, fi);
688+
down_users();
689+
return ret;
690+
}
691+
625692
return -EINVAL;
626693
}
627694

@@ -636,6 +703,13 @@ int lxcfs_readlink(const char *path, char *buf, size_t size)
636703
return ret;
637704
}
638705

706+
if (strncmp(path, "/lxcfs", 6) == 0) {
707+
up_users();
708+
ret = do_lxcfsctl_readlink(path, buf, size);
709+
down_users();
710+
return ret;
711+
}
712+
639713
return -EINVAL;
640714
}
641715

@@ -672,6 +746,13 @@ static int lxcfs_release(const char *path, struct fuse_file_info *fi)
672746
return ret;
673747
}
674748

749+
if (LXCFS_TYPE_LXCFS(type)) {
750+
up_users();
751+
ret = do_lxcfsctl_release(path, fi);
752+
down_users();
753+
return ret;
754+
}
755+
675756
lxcfs_error("unknown file type: path=%s, type=%d, fi->fh=%" PRIu64,
676757
path, type, fi->fh);
677758

@@ -718,6 +799,9 @@ int lxcfs_chown(const char *path, uid_t uid, gid_t gid)
718799
if (strncmp(path, "/sys", 4) == 0)
719800
return -EPERM;
720801

802+
if (strncmp(path, "/lxcfs", 6) == 0)
803+
return -EPERM;
804+
721805
return -ENOENT;
722806
}
723807

@@ -738,6 +822,9 @@ int lxcfs_truncate(const char *path, off_t newsize)
738822
if (strncmp(path, "/sys", 4) == 0)
739823
return 0;
740824

825+
if (strncmp(path, "/lxcfs", 6) == 0)
826+
return 0;
827+
741828
return -EPERM;
742829
}
743830

@@ -776,6 +863,9 @@ int lxcfs_chmod(const char *path, mode_t mode)
776863
if (strncmp(path, "/sys", 4) == 0)
777864
return -EPERM;
778865

866+
if (strncmp(path, "/lxcfs", 6) == 0)
867+
return -EPERM;
868+
779869
return -ENOENT;
780870
}
781871

0 commit comments

Comments
 (0)