Skip to content

Commit 9486c98

Browse files
committed
src/bindings: add features bitmask to struct pidns_store
This bitmask can be used to represent a per-instance (technically, per pid namespace) features configuration (toggle-like). Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
1 parent 52f814d commit 9486c98

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

src/bindings.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static void save_initpid(ino_t pidns_inode, pid_t pid)
362362

363363
ino_hash = HASH(pidns_inode);
364364
*entry = (struct pidns_store){
365-
.version = 1,
365+
.version = 2,
366366
.ino = pidns_inode,
367367
.initpid = pid,
368368
.ctime = st.st_ctime,
@@ -643,6 +643,55 @@ pid_t lookup_initpid_in_store(pid_t pid)
643643
return hashed_pid;
644644
}
645645

646+
bool check_set_lxcfs_feature(pid_t pid, enum lxcfs_feature_op op, __u64 feature)
647+
{
648+
bool ret = false;
649+
struct pidns_store *entry;
650+
ino_t pidns_ino;
651+
652+
pidns_ino = get_pidns_ino(pid);
653+
if (!pidns_ino)
654+
return ret;
655+
656+
store_lock();
657+
658+
entry = lookup_verify_pidns_entry(pidns_ino);
659+
if (!entry)
660+
goto out;
661+
662+
if (entry->version < 2)
663+
goto out;
664+
665+
switch (op) {
666+
case LXCFS_FEATURE_CHECK:
667+
ret = entry->features & feature;
668+
669+
break;
670+
case LXCFS_FEATURE_SET:
671+
entry->features |= feature;
672+
673+
/*
674+
* As we have enabled feature, this entry
675+
* must be kept across lxcfs live reloads.
676+
*/
677+
entry->keep_on_reload = true;
678+
679+
ret = true;
680+
681+
break;
682+
case LXCFS_FEATURE_CLEAR:
683+
entry->features &= ~feature;
684+
ret = true;
685+
686+
break;
687+
}
688+
689+
out:
690+
store_unlock();
691+
692+
return ret;
693+
}
694+
646695
/*
647696
* Functions needed to setup cgroups in the __constructor__.
648697
*/

src/bindings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ struct file_info {
108108
int cached;
109109
};
110110

111+
enum lxcfs_feature_op {
112+
LXCFS_FEATURE_CHECK,
113+
LXCFS_FEATURE_SET,
114+
LXCFS_FEATURE_CLEAR,
115+
};
116+
111117
/*
112118
* A table caching which pid is init for a pid namespace.
113119
* When looking up which pid is init for $qpid, we first
@@ -139,6 +145,9 @@ struct pidns_store {
139145

140146
/* Do not free on liblxcfs reload (contains useful persistent data) */
141147
bool keep_on_reload;
148+
149+
/* bit mask for per-instance configuration options (on/off) */
150+
__u64 features;
142151
};
143152

144153
/* lol - look at how they are allocated in the kernel */
@@ -176,6 +185,7 @@ typedef int (*pidns_store_iter_func_t) (struct pidns_store *cur, void *data);
176185

177186
extern int iter_initpid_store(pidns_store_iter_func_t f, void *data);
178187
extern pid_t lookup_initpid_in_store(pid_t qpid);
188+
extern bool check_set_lxcfs_feature(pid_t pid, enum lxcfs_feature_op op, __u64 feature);
179189
extern void prune_init_slice(char *cg);
180190
extern bool supports_pidfd(void);
181191
extern bool liblxcfs_functional(void);

0 commit comments

Comments
 (0)