Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 151232
b: refs/heads/master
c: 3959214
h: refs/heads/master
v: v3
  • Loading branch information
Kay Sievers authored and Greg Kroah-Hartman committed Jun 16, 2009
1 parent 644530c commit df0db7f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f6ee649f4b191d316a463ce7e514f9d12fa31c01
refs/heads/master: 3959214f971417f4162926ac52ad4cd042958caa
2 changes: 1 addition & 1 deletion trunk/include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ struct user_struct {
struct task_group *tg;
#ifdef CONFIG_SYSFS
struct kobject kobj;
struct work_struct work;
struct delayed_work work;
#endif
#endif

Expand Down
67 changes: 39 additions & 28 deletions trunk/kernel/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,6 @@ static void uid_hash_remove(struct user_struct *up)
put_user_ns(up->user_ns);
}

static struct user_struct *uid_hash_find(uid_t uid, struct hlist_head *hashent)
{
struct user_struct *user;
struct hlist_node *h;

hlist_for_each_entry(user, h, hashent, uidhash_node) {
if (user->uid == uid) {
atomic_inc(&user->__count);
return user;
}
}

return NULL;
}

#ifdef CONFIG_USER_SCHED

static void sched_destroy_user(struct user_struct *up)
Expand Down Expand Up @@ -119,6 +104,23 @@ static int sched_create_user(struct user_struct *up) { return 0; }

#if defined(CONFIG_USER_SCHED) && defined(CONFIG_SYSFS)

static struct user_struct *uid_hash_find(uid_t uid, struct hlist_head *hashent)
{
struct user_struct *user;
struct hlist_node *h;

hlist_for_each_entry(user, h, hashent, uidhash_node) {
if (user->uid == uid) {
/* possibly resurrect an "almost deleted" object */
if (atomic_inc_return(&user->__count) == 1)
cancel_delayed_work(&user->work);
return user;
}
}

return NULL;
}

static struct kset *uids_kset; /* represents the /sys/kernel/uids/ directory */
static DEFINE_MUTEX(uids_mutex);

Expand Down Expand Up @@ -283,12 +285,12 @@ int __init uids_sysfs_init(void)
return uids_user_create(&root_user);
}

/* work function to remove sysfs directory for a user and free up
/* delayed work function to remove sysfs directory for a user and free up
* corresponding structures.
*/
static void cleanup_user_struct(struct work_struct *w)
{
struct user_struct *up = container_of(w, struct user_struct, work);
struct user_struct *up = container_of(w, struct user_struct, work.work);
unsigned long flags;
int remove_user = 0;

Expand All @@ -297,15 +299,12 @@ static void cleanup_user_struct(struct work_struct *w)
*/
uids_mutex_lock();

local_irq_save(flags);

if (atomic_dec_and_lock(&up->__count, &uidhash_lock)) {
spin_lock_irqsave(&uidhash_lock, flags);
if (atomic_read(&up->__count) == 0) {
uid_hash_remove(up);
remove_user = 1;
spin_unlock_irqrestore(&uidhash_lock, flags);
} else {
local_irq_restore(flags);
}
spin_unlock_irqrestore(&uidhash_lock, flags);

if (!remove_user)
goto done;
Expand All @@ -331,16 +330,28 @@ static void cleanup_user_struct(struct work_struct *w)
*/
static void free_user(struct user_struct *up, unsigned long flags)
{
/* restore back the count */
atomic_inc(&up->__count);
spin_unlock_irqrestore(&uidhash_lock, flags);

INIT_WORK(&up->work, cleanup_user_struct);
schedule_work(&up->work);
INIT_DELAYED_WORK(&up->work, cleanup_user_struct);
schedule_delayed_work(&up->work, msecs_to_jiffies(1000));
}

#else /* CONFIG_USER_SCHED && CONFIG_SYSFS */

static struct user_struct *uid_hash_find(uid_t uid, struct hlist_head *hashent)
{
struct user_struct *user;
struct hlist_node *h;

hlist_for_each_entry(user, h, hashent, uidhash_node) {
if (user->uid == uid) {
atomic_inc(&user->__count);
return user;
}
}

return NULL;
}

int uids_sysfs_init(void) { return 0; }
static inline int uids_user_create(struct user_struct *up) { return 0; }
static inline void uids_mutex_lock(void) { }
Expand Down

0 comments on commit df0db7f

Please sign in to comment.