Skip to content

Commit 9fa2796

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 4f43ec0 commit 9fa2796

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
@@ -66,13 +66,18 @@ enum lxcfs_virt_t {
6666

6767
LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE,
6868
#define LXC_TYPE_SYS_DEVICES_SYSTEM_CPU_ONLINE_PATH "/sys/devices/system/cpu/online"
69+
70+
LXC_TYPE_LXCFS,
71+
72+
6973
LXC_TYPE_MAX,
7074
};
7175

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

7883
/*

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

@@ -452,6 +476,7 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
452476
if (strcmp(path, "/") == 0) {
453477
if (dir_filler(filler, buf, ".", 0) != 0 ||
454478
dir_filler(filler, buf, "..", 0) != 0 ||
479+
dir_filler(filler, buf, "lxcfs", 0) != 0 ||
455480
dir_filler(filler, buf, "proc", 0) != 0 ||
456481
dir_filler(filler, buf, "sys", 0) != 0 ||
457482
(cgroup_is_enabled && dir_filler(filler, buf, "cgroup", 0) != 0))
@@ -481,6 +506,13 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
481506
return ret;
482507
}
483508

509+
if (strncmp(path, "/lxcfs", 6) == 0) {
510+
up_users();
511+
ret = do_lxcfsctl_readdir(path, buf, filler, offset, fi);
512+
down_users();
513+
return ret;
514+
}
515+
484516
return -ENOENT;
485517
}
486518

@@ -512,6 +544,13 @@ static int lxcfs_access(const char *path, int mode)
512544
return ret;
513545
}
514546

547+
if (strncmp(path, "/lxcfs", 6) == 0) {
548+
up_users();
549+
ret = do_lxcfsctl_access(path, mode);
550+
down_users();
551+
return ret;
552+
}
553+
515554
return -EACCES;
516555
}
517556

@@ -536,6 +575,13 @@ static int lxcfs_releasedir(const char *path, struct fuse_file_info *fi)
536575
return ret;
537576
}
538577

578+
if (LXCFS_TYPE_LXCFS(type)) {
579+
up_users();
580+
ret = do_lxcfsctl_releasedir(path, fi);
581+
down_users();
582+
return ret;
583+
}
584+
539585
if (path) {
540586
if (strcmp(path, "/") == 0)
541587
return 0;
@@ -574,6 +620,13 @@ static int lxcfs_open(const char *path, struct fuse_file_info *fi)
574620
return ret;
575621
}
576622

623+
if (strncmp(path, "/lxcfs", 6) == 0) {
624+
up_users();
625+
ret = do_lxcfsctl_open(path, fi);
626+
down_users();
627+
return ret;
628+
}
629+
577630
return -EACCES;
578631
}
579632

@@ -603,6 +656,13 @@ static int lxcfs_read(const char *path, char *buf, size_t size, off_t offset,
603656
return ret;
604657
}
605658

659+
if (strncmp(path, "/lxcfs", 6) == 0) {
660+
up_users();
661+
ret = do_lxcfsctl_read(path, buf, size, offset, fi);
662+
down_users();
663+
return ret;
664+
}
665+
606666
return -EINVAL;
607667
}
608668

@@ -625,6 +685,13 @@ int lxcfs_write(const char *path, const char *buf, size_t size, off_t offset,
625685
return ret;
626686
}
627687

688+
if (strncmp(path, "/lxcfs", 6) == 0) {
689+
up_users();
690+
ret = do_lxcfsctl_write(path, buf, size, offset, fi);
691+
down_users();
692+
return ret;
693+
}
694+
628695
return -EINVAL;
629696
}
630697

@@ -639,6 +706,13 @@ int lxcfs_readlink(const char *path, char *buf, size_t size)
639706
return ret;
640707
}
641708

709+
if (strncmp(path, "/lxcfs", 6) == 0) {
710+
up_users();
711+
ret = do_lxcfsctl_readlink(path, buf, size);
712+
down_users();
713+
return ret;
714+
}
715+
642716
return -EINVAL;
643717
}
644718

@@ -675,6 +749,13 @@ static int lxcfs_release(const char *path, struct fuse_file_info *fi)
675749
return ret;
676750
}
677751

752+
if (LXCFS_TYPE_LXCFS(type)) {
753+
up_users();
754+
ret = do_lxcfsctl_release(path, fi);
755+
down_users();
756+
return ret;
757+
}
758+
678759
lxcfs_error("unknown file type: path=%s, type=%d, fi->fh=%" PRIu64,
679760
path, type, fi->fh);
680761

@@ -721,6 +802,9 @@ int lxcfs_chown(const char *path, uid_t uid, gid_t gid)
721802
if (strncmp(path, "/sys", 4) == 0)
722803
return -EPERM;
723804

805+
if (strncmp(path, "/lxcfs", 6) == 0)
806+
return -EPERM;
807+
724808
return -ENOENT;
725809
}
726810

@@ -741,6 +825,9 @@ int lxcfs_truncate(const char *path, off_t newsize)
741825
if (strncmp(path, "/sys", 4) == 0)
742826
return 0;
743827

828+
if (strncmp(path, "/lxcfs", 6) == 0)
829+
return 0;
830+
744831
return -EPERM;
745832
}
746833

@@ -779,6 +866,9 @@ int lxcfs_chmod(const char *path, mode_t mode)
779866
if (strncmp(path, "/sys", 4) == 0)
780867
return -EPERM;
781868

869+
if (strncmp(path, "/lxcfs", 6) == 0)
870+
return -EPERM;
871+
782872
return -ENOENT;
783873
}
784874

0 commit comments

Comments
 (0)