diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2011-06-17 16:33:20 -0400 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2012-11-20 07:19:19 -0500 |
commit | 33d6dce607573b5fd7a43168e0d91221b3ca532b (patch) | |
tree | c7743ed6aab1fe2026f20e6a1ddf708a16aa1c84 | |
parent | 4f326c0064b20b78b8041f4d2f6fe188a1129f18 (diff) |
proc: Generalize proc inode allocation
Generalize the proc inode allocation so that it can be
used without having to having to create a proc_dir_entry.
This will allow namespace file descriptors to remain light
weight entitities but still have the same inode number
when the backing namespace is the same.
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
-rw-r--r-- | fs/proc/generic.c | 26 | ||||
-rw-r--r-- | include/linux/proc_fs.h | 10 |
2 files changed, 23 insertions, 13 deletions
diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 0d80cef4cfb9..7b3ae3cc0ef9 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c | |||
@@ -350,14 +350,14 @@ static DEFINE_SPINLOCK(proc_inum_lock); /* protects the above */ | |||
350 | * Return an inode number between PROC_DYNAMIC_FIRST and | 350 | * Return an inode number between PROC_DYNAMIC_FIRST and |
351 | * 0xffffffff, or zero on failure. | 351 | * 0xffffffff, or zero on failure. |
352 | */ | 352 | */ |
353 | static unsigned int get_inode_number(void) | 353 | int proc_alloc_inum(unsigned int *inum) |
354 | { | 354 | { |
355 | unsigned int i; | 355 | unsigned int i; |
356 | int error; | 356 | int error; |
357 | 357 | ||
358 | retry: | 358 | retry: |
359 | if (ida_pre_get(&proc_inum_ida, GFP_KERNEL) == 0) | 359 | if (!ida_pre_get(&proc_inum_ida, GFP_KERNEL)) |
360 | return 0; | 360 | return -ENOMEM; |
361 | 361 | ||
362 | spin_lock(&proc_inum_lock); | 362 | spin_lock(&proc_inum_lock); |
363 | error = ida_get_new(&proc_inum_ida, &i); | 363 | error = ida_get_new(&proc_inum_ida, &i); |
@@ -365,18 +365,19 @@ retry: | |||
365 | if (error == -EAGAIN) | 365 | if (error == -EAGAIN) |
366 | goto retry; | 366 | goto retry; |
367 | else if (error) | 367 | else if (error) |
368 | return 0; | 368 | return error; |
369 | 369 | ||
370 | if (i > UINT_MAX - PROC_DYNAMIC_FIRST) { | 370 | if (i > UINT_MAX - PROC_DYNAMIC_FIRST) { |
371 | spin_lock(&proc_inum_lock); | 371 | spin_lock(&proc_inum_lock); |
372 | ida_remove(&proc_inum_ida, i); | 372 | ida_remove(&proc_inum_ida, i); |
373 | spin_unlock(&proc_inum_lock); | 373 | spin_unlock(&proc_inum_lock); |
374 | return 0; | 374 | return -ENOSPC; |
375 | } | 375 | } |
376 | return PROC_DYNAMIC_FIRST + i; | 376 | *inum = PROC_DYNAMIC_FIRST + i; |
377 | return 0; | ||
377 | } | 378 | } |
378 | 379 | ||
379 | static void release_inode_number(unsigned int inum) | 380 | void proc_free_inum(unsigned int inum) |
380 | { | 381 | { |
381 | spin_lock(&proc_inum_lock); | 382 | spin_lock(&proc_inum_lock); |
382 | ida_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST); | 383 | ida_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST); |
@@ -554,13 +555,12 @@ static const struct inode_operations proc_dir_inode_operations = { | |||
554 | 555 | ||
555 | static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp) | 556 | static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp) |
556 | { | 557 | { |
557 | unsigned int i; | ||
558 | struct proc_dir_entry *tmp; | 558 | struct proc_dir_entry *tmp; |
559 | int ret; | ||
559 | 560 | ||
560 | i = get_inode_number(); | 561 | ret = proc_alloc_inum(&dp->low_ino); |
561 | if (i == 0) | 562 | if (ret) |
562 | return -EAGAIN; | 563 | return ret; |
563 | dp->low_ino = i; | ||
564 | 564 | ||
565 | if (S_ISDIR(dp->mode)) { | 565 | if (S_ISDIR(dp->mode)) { |
566 | if (dp->proc_iops == NULL) { | 566 | if (dp->proc_iops == NULL) { |
@@ -764,7 +764,7 @@ EXPORT_SYMBOL(proc_create_data); | |||
764 | 764 | ||
765 | static void free_proc_entry(struct proc_dir_entry *de) | 765 | static void free_proc_entry(struct proc_dir_entry *de) |
766 | { | 766 | { |
767 | release_inode_number(de->low_ino); | 767 | proc_free_inum(de->low_ino); |
768 | 768 | ||
769 | if (S_ISLNK(de->mode)) | 769 | if (S_ISLNK(de->mode)) |
770 | kfree(de->data); | 770 | kfree(de->data); |
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index 31447819bc55..bf1d000fbba6 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h | |||
@@ -176,6 +176,8 @@ extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name, | |||
176 | extern struct file *proc_ns_fget(int fd); | 176 | extern struct file *proc_ns_fget(int fd); |
177 | extern bool proc_ns_inode(struct inode *inode); | 177 | extern bool proc_ns_inode(struct inode *inode); |
178 | 178 | ||
179 | extern int proc_alloc_inum(unsigned int *pino); | ||
180 | extern void proc_free_inum(unsigned int inum); | ||
179 | #else | 181 | #else |
180 | 182 | ||
181 | #define proc_net_fops_create(net, name, mode, fops) ({ (void)(mode), NULL; }) | 183 | #define proc_net_fops_create(net, name, mode, fops) ({ (void)(mode), NULL; }) |
@@ -235,6 +237,14 @@ static inline bool proc_ns_inode(struct inode *inode) | |||
235 | return false; | 237 | return false; |
236 | } | 238 | } |
237 | 239 | ||
240 | static inline int proc_alloc_inum(unsigned int *inum) | ||
241 | { | ||
242 | *inum = 1; | ||
243 | return 0; | ||
244 | } | ||
245 | static inline void proc_free_inum(unsigned int inum) | ||
246 | { | ||
247 | } | ||
238 | #endif /* CONFIG_PROC_FS */ | 248 | #endif /* CONFIG_PROC_FS */ |
239 | 249 | ||
240 | #if !defined(CONFIG_PROC_KCORE) | 250 | #if !defined(CONFIG_PROC_KCORE) |