Skip to content

Commit 3b8b487

Browse files
author
Al Viro
committed
ecryptfs: don't reinvent the wheels, please - use struct completion
... and keep the sodding requests on stack - they are small enough. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 8fc37ec commit 3b8b487

File tree

3 files changed

+26
-65
lines changed

3 files changed

+26
-65
lines changed

fs/ecryptfs/ecryptfs_kernel.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -550,20 +550,6 @@ extern struct kmem_cache *ecryptfs_key_record_cache;
550550
extern struct kmem_cache *ecryptfs_key_sig_cache;
551551
extern struct kmem_cache *ecryptfs_global_auth_tok_cache;
552552
extern struct kmem_cache *ecryptfs_key_tfm_cache;
553-
extern struct kmem_cache *ecryptfs_open_req_cache;
554-
555-
struct ecryptfs_open_req {
556-
#define ECRYPTFS_REQ_PROCESSED 0x00000001
557-
#define ECRYPTFS_REQ_DROPPED 0x00000002
558-
#define ECRYPTFS_REQ_ZOMBIE 0x00000004
559-
u32 flags;
560-
struct file **lower_file;
561-
struct dentry *lower_dentry;
562-
struct vfsmount *lower_mnt;
563-
wait_queue_head_t wait;
564-
struct mutex mux;
565-
struct list_head kthread_ctl_list;
566-
};
567553

568554
struct inode *ecryptfs_get_inode(struct inode *lower_inode,
569555
struct super_block *sb);

fs/ecryptfs/kthread.c

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
#include <linux/mount.h>
2828
#include "ecryptfs_kernel.h"
2929

30-
struct kmem_cache *ecryptfs_open_req_cache;
30+
struct ecryptfs_open_req {
31+
struct file **lower_file;
32+
struct dentry *lower_dentry;
33+
struct vfsmount *lower_mnt;
34+
struct completion done;
35+
struct list_head kthread_ctl_list;
36+
};
3137

3238
static struct ecryptfs_kthread_ctl {
3339
#define ECRYPTFS_KTHREAD_ZOMBIE 0x00000001
@@ -67,18 +73,13 @@ static int ecryptfs_threadfn(void *ignored)
6773
req = list_first_entry(&ecryptfs_kthread_ctl.req_list,
6874
struct ecryptfs_open_req,
6975
kthread_ctl_list);
70-
mutex_lock(&req->mux);
7176
list_del(&req->kthread_ctl_list);
72-
if (!(req->flags & ECRYPTFS_REQ_ZOMBIE)) {
73-
dget(req->lower_dentry);
74-
mntget(req->lower_mnt);
75-
(*req->lower_file) = dentry_open(
76-
req->lower_dentry, req->lower_mnt,
77-
(O_RDWR | O_LARGEFILE), current_cred());
78-
req->flags |= ECRYPTFS_REQ_PROCESSED;
79-
}
80-
wake_up(&req->wait);
81-
mutex_unlock(&req->mux);
77+
dget(req->lower_dentry);
78+
mntget(req->lower_mnt);
79+
(*req->lower_file) = dentry_open(
80+
req->lower_dentry, req->lower_mnt,
81+
(O_RDWR | O_LARGEFILE), current_cred());
82+
complete(&req->done);
8283
}
8384
mutex_unlock(&ecryptfs_kthread_ctl.mux);
8485
}
@@ -111,10 +112,9 @@ void ecryptfs_destroy_kthread(void)
111112
ecryptfs_kthread_ctl.flags |= ECRYPTFS_KTHREAD_ZOMBIE;
112113
list_for_each_entry(req, &ecryptfs_kthread_ctl.req_list,
113114
kthread_ctl_list) {
114-
mutex_lock(&req->mux);
115-
req->flags |= ECRYPTFS_REQ_ZOMBIE;
116-
wake_up(&req->wait);
117-
mutex_unlock(&req->mux);
115+
list_del(&req->kthread_ctl_list);
116+
*req->lower_file = ERR_PTR(-EIO);
117+
complete(&req->done);
118118
}
119119
mutex_unlock(&ecryptfs_kthread_ctl.mux);
120120
kthread_stop(ecryptfs_kthread);
@@ -136,7 +136,7 @@ int ecryptfs_privileged_open(struct file **lower_file,
136136
struct vfsmount *lower_mnt,
137137
const struct cred *cred)
138138
{
139-
struct ecryptfs_open_req *req;
139+
struct ecryptfs_open_req req;
140140
int flags = O_LARGEFILE;
141141
int rc = 0;
142142

@@ -153,45 +153,25 @@ int ecryptfs_privileged_open(struct file **lower_file,
153153
rc = PTR_ERR((*lower_file));
154154
goto out;
155155
}
156-
req = kmem_cache_alloc(ecryptfs_open_req_cache, GFP_KERNEL);
157-
if (!req) {
158-
rc = -ENOMEM;
159-
goto out;
160-
}
161-
mutex_init(&req->mux);
162-
req->lower_file = lower_file;
163-
req->lower_dentry = lower_dentry;
164-
req->lower_mnt = lower_mnt;
165-
init_waitqueue_head(&req->wait);
166-
req->flags = 0;
156+
init_completion(&req.done);
157+
req.lower_file = lower_file;
158+
req.lower_dentry = lower_dentry;
159+
req.lower_mnt = lower_mnt;
167160
mutex_lock(&ecryptfs_kthread_ctl.mux);
168161
if (ecryptfs_kthread_ctl.flags & ECRYPTFS_KTHREAD_ZOMBIE) {
169162
rc = -EIO;
170163
mutex_unlock(&ecryptfs_kthread_ctl.mux);
171164
printk(KERN_ERR "%s: We are in the middle of shutting down; "
172165
"aborting privileged request to open lower file\n",
173166
__func__);
174-
goto out_free;
167+
goto out;
175168
}
176-
list_add_tail(&req->kthread_ctl_list, &ecryptfs_kthread_ctl.req_list);
169+
list_add_tail(&req.kthread_ctl_list, &ecryptfs_kthread_ctl.req_list);
177170
mutex_unlock(&ecryptfs_kthread_ctl.mux);
178171
wake_up(&ecryptfs_kthread_ctl.wait);
179-
wait_event(req->wait, (req->flags != 0));
180-
mutex_lock(&req->mux);
181-
BUG_ON(req->flags == 0);
182-
if (req->flags & ECRYPTFS_REQ_DROPPED
183-
|| req->flags & ECRYPTFS_REQ_ZOMBIE) {
184-
rc = -EIO;
185-
printk(KERN_WARNING "%s: Privileged open request dropped\n",
186-
__func__);
187-
goto out_unlock;
188-
}
189-
if (IS_ERR(*req->lower_file))
190-
rc = PTR_ERR(*req->lower_file);
191-
out_unlock:
192-
mutex_unlock(&req->mux);
193-
out_free:
194-
kmem_cache_free(ecryptfs_open_req_cache, req);
172+
wait_for_completion(&req.done);
173+
if (IS_ERR(*lower_file))
174+
rc = PTR_ERR(*lower_file);
195175
out:
196176
return rc;
197177
}

fs/ecryptfs/main.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,6 @@ static struct ecryptfs_cache_info {
681681
.name = "ecryptfs_key_tfm_cache",
682682
.size = sizeof(struct ecryptfs_key_tfm),
683683
},
684-
{
685-
.cache = &ecryptfs_open_req_cache,
686-
.name = "ecryptfs_open_req_cache",
687-
.size = sizeof(struct ecryptfs_open_req),
688-
},
689684
};
690685

691686
static void ecryptfs_free_kmem_caches(void)

0 commit comments

Comments
 (0)