Skip to content

Commit bd8f51f

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 23fc603 commit bd8f51f

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
@@ -380,7 +380,7 @@ static void save_initpid(ino_t pidns_inode, pid_t pid)
380380

381381
ino_hash = HASH(pidns_inode);
382382
*entry = (struct pidns_store){
383-
.version = 1,
383+
.version = 2,
384384
.ino = pidns_inode,
385385
.initpid = pid,
386386
.ctime = st.st_ctime,
@@ -661,6 +661,55 @@ pid_t lookup_initpid_in_store(pid_t pid)
661661
return hashed_pid;
662662
}
663663

664+
bool check_set_lxcfs_feature(pid_t pid, enum lxcfs_feature_op op, __u64 feature)
665+
{
666+
bool ret = false;
667+
struct pidns_store *entry;
668+
ino_t pidns_ino;
669+
670+
pidns_ino = get_pidns_ino(pid);
671+
if (!pidns_ino)
672+
return ret;
673+
674+
store_lock();
675+
676+
entry = lookup_verify_pidns_entry(pidns_ino);
677+
if (!entry)
678+
goto out;
679+
680+
if (entry->version < 2)
681+
goto out;
682+
683+
switch (op) {
684+
case LXCFS_FEATURE_CHECK:
685+
ret = entry->features & feature;
686+
687+
break;
688+
case LXCFS_FEATURE_SET:
689+
entry->features |= feature;
690+
691+
/*
692+
* As we have enabled feature, this entry
693+
* must be kept across lxcfs live reloads.
694+
*/
695+
entry->keep_on_reload = true;
696+
697+
ret = true;
698+
699+
break;
700+
case LXCFS_FEATURE_CLEAR:
701+
entry->features &= ~feature;
702+
ret = true;
703+
704+
break;
705+
}
706+
707+
out:
708+
store_unlock();
709+
710+
return ret;
711+
}
712+
664713
/*
665714
* Functions needed to setup cgroups in the __constructor__.
666715
*/

src/bindings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ struct file_info {
104104
int cached;
105105
};
106106

107+
enum lxcfs_feature_op {
108+
LXCFS_FEATURE_CHECK,
109+
LXCFS_FEATURE_SET,
110+
LXCFS_FEATURE_CLEAR,
111+
};
112+
107113
/*
108114
* A table caching which pid is init for a pid namespace.
109115
* When looking up which pid is init for $qpid, we first
@@ -135,6 +141,9 @@ struct pidns_store {
135141

136142
/* Do not free on liblxcfs reload (contains useful persistent data) */
137143
bool keep_on_reload;
144+
145+
/* bit mask for per-instance configuration options (on/off) */
146+
__u64 features;
138147
};
139148

140149
/* lol - look at how they are allocated in the kernel */
@@ -174,6 +183,7 @@ typedef int (*pidns_store_iter_func_t) (struct pidns_store *cur, void *data);
174183

175184
extern int iter_initpid_store(pidns_store_iter_func_t f, void *data);
176185
extern pid_t lookup_initpid_in_store(pid_t qpid);
186+
extern bool check_set_lxcfs_feature(pid_t pid, enum lxcfs_feature_op op, __u64 feature);
177187
extern void prune_init_slice(char *cg);
178188
extern bool supports_pidfd(void);
179189
extern bool liblxcfs_functional(void);

0 commit comments

Comments
 (0)