Skip to content

Commit 6ee0659

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 <[email protected]>
1 parent 3707a33 commit 6ee0659

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

src/api_extensions.h

+1
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

+5
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,18 @@ enum lxcfs_virt_t {
6767

6868
LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE,
6969
#define LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE_PATH "/sys/devices/system/cpu/online"
70+
71+
LXC_TYPE_LXCFS,
72+
73+
7074
LXC_TYPE_MAX,
7175
};
7276

7377
/* Macros below used to check the class from the file types above */
7478
#define LXCFS_TYPE_CGROUP(type) (type >= LXC_TYPE_CGDIR && type <= LXC_TYPE_CGFILE)
7579
#define LXCFS_TYPE_PROC(type) (type >= LXC_TYPE_PROC_MEMINFO && type <= LXC_TYPE_PROC_SLABINFO)
7680
#define LXCFS_TYPE_SYS(type) (type >= LXC_TYPE_SYS && type <= LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE)
81+
#define LXCFS_TYPE_LXCFS(type) (type >= LXC_TYPE_LXCFS && type < LXC_TYPE_MAX)
7782
#define LXCFS_TYPE_OK(type) (type >= LXC_TYPE_CGDIR && type < LXC_TYPE_MAX)
7883

7984
/*

src/lxcfs.c

+90
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,22 @@ static int do_##type##_##fsop(LIB_FS_##fsop##_OP_ARGS_TYPE) \
297297
DEF_LIB_FS_OP(cg , getattr)
298298
DEF_LIB_FS_OP(proc , getattr)
299299
DEF_LIB_FS_OP(sys , getattr)
300+
DEF_LIB_FS_OP(lxcfsctl, getattr)
300301

301302
#define LIB_FS_read_OP_ARGS_TYPE const char *path, char *buf, size_t size, \
302303
off_t offset, struct fuse_file_info *fi
303304
#define LIB_FS_read_OP_ARGS path, buf, size, offset, fi
304305
DEF_LIB_FS_OP(cg , read)
305306
DEF_LIB_FS_OP(proc , read)
306307
DEF_LIB_FS_OP(sys , read)
308+
DEF_LIB_FS_OP(lxcfsctl, read)
307309

308310
#define LIB_FS_write_OP_ARGS_TYPE const char *path, const char *buf, size_t size, \
309311
off_t offset, struct fuse_file_info *fi
310312
#define LIB_FS_write_OP_ARGS path, buf, size, offset, fi
311313
DEF_LIB_FS_OP(cg , write)
312314
DEF_LIB_FS_OP(sys , write)
315+
DEF_LIB_FS_OP(lxcfsctl, write)
313316

314317
#define LIB_FS_mkdir_OP_ARGS_TYPE const char *path, mode_t mode
315318
#define LIB_FS_mkdir_OP_ARGS path, mode
@@ -333,38 +336,45 @@ DEF_LIB_FS_OP(cg, chmod)
333336
DEF_LIB_FS_OP(cg , readdir)
334337
DEF_LIB_FS_OP(proc , readdir)
335338
DEF_LIB_FS_OP(sys , readdir)
339+
DEF_LIB_FS_OP(lxcfsctl, readdir)
336340

337341
#define LIB_FS_readlink_OP_ARGS_TYPE const char *path, char *buf, size_t size
338342
#define LIB_FS_readlink_OP_ARGS path, buf, size
339343
DEF_LIB_FS_OP(sys , readlink)
344+
DEF_LIB_FS_OP(lxcfsctl, readlink)
340345

341346
#define LIB_FS_open_OP_ARGS_TYPE const char *path, struct fuse_file_info *fi
342347
#define LIB_FS_open_OP_ARGS path, fi
343348
DEF_LIB_FS_OP(cg , open)
344349
DEF_LIB_FS_OP(proc , open)
345350
DEF_LIB_FS_OP(sys , open)
351+
DEF_LIB_FS_OP(lxcfsctl, open)
346352

347353
#define LIB_FS_access_OP_ARGS_TYPE const char *path, int mode
348354
#define LIB_FS_access_OP_ARGS path, mode
349355
DEF_LIB_FS_OP(cg , access)
350356
DEF_LIB_FS_OP(proc , access)
351357
DEF_LIB_FS_OP(sys , access)
358+
DEF_LIB_FS_OP(lxcfsctl, access)
352359

353360
#define LIB_FS_opendir_OP_ARGS_TYPE const char *path, struct fuse_file_info *fi
354361
#define LIB_FS_opendir_OP_ARGS path, fi
355362
DEF_LIB_FS_OP(cg , opendir)
356363
DEF_LIB_FS_OP(sys , opendir)
364+
DEF_LIB_FS_OP(lxcfsctl, opendir)
357365

358366
#define LIB_FS_release_OP_ARGS_TYPE const char *path, struct fuse_file_info *fi
359367
#define LIB_FS_release_OP_ARGS path, fi
360368
DEF_LIB_FS_OP(cg , release)
361369
DEF_LIB_FS_OP(proc , release)
362370
DEF_LIB_FS_OP(sys , release)
371+
DEF_LIB_FS_OP(lxcfsctl, release)
363372

364373
#define LIB_FS_releasedir_OP_ARGS_TYPE const char *path, struct fuse_file_info *fi
365374
#define LIB_FS_releasedir_OP_ARGS path, fi
366375
DEF_LIB_FS_OP(cg , releasedir)
367376
DEF_LIB_FS_OP(sys , releasedir)
377+
DEF_LIB_FS_OP(lxcfsctl, releasedir)
368378

369379
static bool cgroup_is_enabled = false;
370380

@@ -409,6 +419,13 @@ static int lxcfs_getattr(const char *path, struct stat *sb)
409419
return ret;
410420
}
411421

422+
if (strncmp(path, "/lxcfs", 6) == 0) {
423+
up_users();
424+
ret = do_lxcfsctl_getattr(path, sb);
425+
down_users();
426+
return ret;
427+
}
428+
412429
return -ENOENT;
413430
}
414431

@@ -436,6 +453,13 @@ static int lxcfs_opendir(const char *path, struct fuse_file_info *fi)
436453
return ret;
437454
}
438455

456+
if (strncmp(path, "/lxcfs", 6) == 0) {
457+
up_users();
458+
ret = do_lxcfsctl_opendir(path, fi);
459+
down_users();
460+
return ret;
461+
}
462+
439463
return -ENOENT;
440464
}
441465

@@ -455,6 +479,7 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
455479
if (strcmp(path, "/") == 0) {
456480
if (dir_filler(filler, buf, ".", 0) != 0 ||
457481
dir_filler(filler, buf, "..", 0) != 0 ||
482+
dir_filler(filler, buf, "lxcfs", 0) != 0 ||
458483
dir_filler(filler, buf, "proc", 0) != 0 ||
459484
dir_filler(filler, buf, "sys", 0) != 0 ||
460485
(cgroup_is_enabled && dir_filler(filler, buf, "cgroup", 0) != 0))
@@ -484,6 +509,13 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
484509
return ret;
485510
}
486511

512+
if (strncmp(path, "/lxcfs", 6) == 0) {
513+
up_users();
514+
ret = do_lxcfsctl_readdir(path, buf, filler, offset, fi);
515+
down_users();
516+
return ret;
517+
}
518+
487519
return -ENOENT;
488520
}
489521

@@ -515,6 +547,13 @@ static int lxcfs_access(const char *path, int mode)
515547
return ret;
516548
}
517549

550+
if (strncmp(path, "/lxcfs", 6) == 0) {
551+
up_users();
552+
ret = do_lxcfsctl_access(path, mode);
553+
down_users();
554+
return ret;
555+
}
556+
518557
return -EACCES;
519558
}
520559

@@ -539,6 +578,13 @@ static int lxcfs_releasedir(const char *path, struct fuse_file_info *fi)
539578
return ret;
540579
}
541580

581+
if (LXCFS_TYPE_LXCFS(type)) {
582+
up_users();
583+
ret = do_lxcfsctl_releasedir(path, fi);
584+
down_users();
585+
return ret;
586+
}
587+
542588
if (path) {
543589
if (strcmp(path, "/") == 0)
544590
return 0;
@@ -577,6 +623,13 @@ static int lxcfs_open(const char *path, struct fuse_file_info *fi)
577623
return ret;
578624
}
579625

626+
if (strncmp(path, "/lxcfs", 6) == 0) {
627+
up_users();
628+
ret = do_lxcfsctl_open(path, fi);
629+
down_users();
630+
return ret;
631+
}
632+
580633
return -EACCES;
581634
}
582635

@@ -609,6 +662,13 @@ static int lxcfs_read(const char *path, char *buf, size_t size, off_t offset,
609662
return ret;
610663
}
611664

665+
if (strncmp(path, "/lxcfs", 6) == 0) {
666+
up_users();
667+
ret = do_lxcfsctl_read(path, buf, size, offset, fi);
668+
down_users();
669+
return ret;
670+
}
671+
612672
lxcfs_error("unknown file type: path=%s, type=%d, fi->fh=%" PRIu64,
613673
path, type, fi->fh);
614674

@@ -637,6 +697,13 @@ int lxcfs_write(const char *path, const char *buf, size_t size, off_t offset,
637697
return ret;
638698
}
639699

700+
if (strncmp(path, "/lxcfs", 6) == 0) {
701+
up_users();
702+
ret = do_lxcfsctl_write(path, buf, size, offset, fi);
703+
down_users();
704+
return ret;
705+
}
706+
640707
return -EINVAL;
641708
}
642709

@@ -651,6 +718,13 @@ int lxcfs_readlink(const char *path, char *buf, size_t size)
651718
return ret;
652719
}
653720

721+
if (strncmp(path, "/lxcfs", 6) == 0) {
722+
up_users();
723+
ret = do_lxcfsctl_readlink(path, buf, size);
724+
down_users();
725+
return ret;
726+
}
727+
654728
return -EINVAL;
655729
}
656730

@@ -687,6 +761,13 @@ static int lxcfs_release(const char *path, struct fuse_file_info *fi)
687761
return ret;
688762
}
689763

764+
if (LXCFS_TYPE_LXCFS(type)) {
765+
up_users();
766+
ret = do_lxcfsctl_release(path, fi);
767+
down_users();
768+
return ret;
769+
}
770+
690771
lxcfs_error("unknown file type: path=%s, type=%d, fi->fh=%" PRIu64,
691772
path, type, fi->fh);
692773

@@ -733,6 +814,9 @@ int lxcfs_chown(const char *path, uid_t uid, gid_t gid)
733814
if (strncmp(path, "/sys", 4) == 0)
734815
return -EPERM;
735816

817+
if (strncmp(path, "/lxcfs", 6) == 0)
818+
return -EPERM;
819+
736820
return -ENOENT;
737821
}
738822

@@ -753,6 +837,9 @@ int lxcfs_truncate(const char *path, off_t newsize)
753837
if (strncmp(path, "/sys", 4) == 0)
754838
return 0;
755839

840+
if (strncmp(path, "/lxcfs", 6) == 0)
841+
return 0;
842+
756843
return -EPERM;
757844
}
758845

@@ -791,6 +878,9 @@ int lxcfs_chmod(const char *path, mode_t mode)
791878
if (strncmp(path, "/sys", 4) == 0)
792879
return -EPERM;
793880

881+
if (strncmp(path, "/lxcfs", 6) == 0)
882+
return -EPERM;
883+
794884
return -ENOENT;
795885
}
796886

0 commit comments

Comments
 (0)