Skip to content

Commit da47c19

Browse files
Yoshihisa Abetorvalds
authored andcommitted
Coda: replace BKL with mutex
Replace the BKL with a mutex to protect the venus_comm structure which binds the mountpoint with the character device and holds the upcall queues. Signed-off-by: Yoshihisa Abe <yoshiabe@cs.cmu.edu> Signed-off-by: Jan Harkes <jaharkes@cs.cmu.edu> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f7cc02b commit da47c19

4 files changed

Lines changed: 70 additions & 50 deletions

File tree

‎fs/coda/inode.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <linux/stat.h>
1616
#include <linux/errno.h>
1717
#include <linux/unistd.h>
18-
#include <linux/smp_lock.h>
18+
#include <linux/mutex.h>
1919
#include <linux/spinlock.h>
2020
#include <linux/file.h>
2121
#include <linux/vfs.h>
@@ -145,7 +145,7 @@ static int get_device_index(struct coda_mount_data *data)
145145
static int coda_fill_super(struct super_block *sb, void *data, int silent)
146146
{
147147
struct inode *root = NULL;
148-
struct venus_comm *vc = NULL;
148+
struct venus_comm *vc;
149149
struct CodaFid fid;
150150
int error;
151151
int idx;
@@ -159,7 +159,7 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
159159
printk(KERN_INFO "coda_read_super: device index: %i\n", idx);
160160

161161
vc = &coda_comms[idx];
162-
lock_kernel();
162+
mutex_lock(&vc->vc_mutex);
163163

164164
if (!vc->vc_inuse) {
165165
printk("coda_read_super: No pseudo device\n");
@@ -178,7 +178,7 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
178178
goto unlock_out;
179179

180180
vc->vc_sb = sb;
181-
unlock_kernel();
181+
mutex_unlock(&vc->vc_mutex);
182182

183183
sb->s_fs_info = vc;
184184
sb->s_flags |= MS_NOATIME;
@@ -217,20 +217,23 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
217217
if (root)
218218
iput(root);
219219

220-
lock_kernel();
220+
mutex_lock(&vc->vc_mutex);
221221
bdi_destroy(&vc->bdi);
222222
vc->vc_sb = NULL;
223223
sb->s_fs_info = NULL;
224224
unlock_out:
225-
unlock_kernel();
225+
mutex_unlock(&vc->vc_mutex);
226226
return error;
227227
}
228228

229229
static void coda_put_super(struct super_block *sb)
230230
{
231-
bdi_destroy(&coda_vcp(sb)->bdi);
232-
coda_vcp(sb)->vc_sb = NULL;
231+
struct venus_comm *vcp = coda_vcp(sb);
232+
mutex_lock(&vcp->vc_mutex);
233+
bdi_destroy(&vcp->bdi);
234+
vcp->vc_sb = NULL;
233235
sb->s_fs_info = NULL;
236+
mutex_unlock(&vcp->vc_mutex);
234237

235238
printk("Coda: Bye bye.\n");
236239
}

‎fs/coda/psdev.c‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <linux/poll.h>
3636
#include <linux/init.h>
3737
#include <linux/list.h>
38-
#include <linux/smp_lock.h>
38+
#include <linux/mutex.h>
3939
#include <linux/device.h>
4040
#include <asm/io.h>
4141
#include <asm/system.h>
@@ -67,8 +67,10 @@ static unsigned int coda_psdev_poll(struct file *file, poll_table * wait)
6767
unsigned int mask = POLLOUT | POLLWRNORM;
6868

6969
poll_wait(file, &vcp->vc_waitq, wait);
70+
mutex_lock(&vcp->vc_mutex);
7071
if (!list_empty(&vcp->vc_pending))
7172
mask |= POLLIN | POLLRDNORM;
73+
mutex_unlock(&vcp->vc_mutex);
7274

7375
return mask;
7476
}
@@ -143,7 +145,7 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
143145
}
144146

145147
/* Look for the message on the processing queue. */
146-
lock_kernel();
148+
mutex_lock(&vcp->vc_mutex);
147149
list_for_each(lh, &vcp->vc_processing) {
148150
tmp = list_entry(lh, struct upc_req , uc_chain);
149151
if (tmp->uc_unique == hdr.unique) {
@@ -152,7 +154,7 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
152154
break;
153155
}
154156
}
155-
unlock_kernel();
157+
mutex_unlock(&vcp->vc_mutex);
156158

157159
if (!req) {
158160
printk("psdev_write: msg (%d, %d) not found\n",
@@ -207,7 +209,7 @@ static ssize_t coda_psdev_read(struct file * file, char __user * buf,
207209
if (nbytes == 0)
208210
return 0;
209211

210-
lock_kernel();
212+
mutex_lock(&vcp->vc_mutex);
211213

212214
add_wait_queue(&vcp->vc_waitq, &wait);
213215
set_current_state(TASK_INTERRUPTIBLE);
@@ -221,7 +223,9 @@ static ssize_t coda_psdev_read(struct file * file, char __user * buf,
221223
retval = -ERESTARTSYS;
222224
break;
223225
}
226+
mutex_unlock(&vcp->vc_mutex);
224227
schedule();
228+
mutex_lock(&vcp->vc_mutex);
225229
}
226230

227231
set_current_state(TASK_RUNNING);
@@ -254,7 +258,7 @@ static ssize_t coda_psdev_read(struct file * file, char __user * buf,
254258
CODA_FREE(req->uc_data, sizeof(struct coda_in_hdr));
255259
kfree(req);
256260
out:
257-
unlock_kernel();
261+
mutex_unlock(&vcp->vc_mutex);
258262
return (count ? count : retval);
259263
}
260264

@@ -267,10 +271,10 @@ static int coda_psdev_open(struct inode * inode, struct file * file)
267271
if (idx < 0 || idx >= MAX_CODADEVS)
268272
return -ENODEV;
269273

270-
lock_kernel();
271-
272274
err = -EBUSY;
273275
vcp = &coda_comms[idx];
276+
mutex_lock(&vcp->vc_mutex);
277+
274278
if (!vcp->vc_inuse) {
275279
vcp->vc_inuse++;
276280

@@ -284,7 +288,7 @@ static int coda_psdev_open(struct inode * inode, struct file * file)
284288
err = 0;
285289
}
286290

287-
unlock_kernel();
291+
mutex_unlock(&vcp->vc_mutex);
288292
return err;
289293
}
290294

@@ -299,7 +303,7 @@ static int coda_psdev_release(struct inode * inode, struct file * file)
299303
return -1;
300304
}
301305

302-
lock_kernel();
306+
mutex_lock(&vcp->vc_mutex);
303307

304308
/* Wakeup clients so they can return. */
305309
list_for_each_entry_safe(req, tmp, &vcp->vc_pending, uc_chain) {
@@ -324,7 +328,7 @@ static int coda_psdev_release(struct inode * inode, struct file * file)
324328

325329
file->private_data = NULL;
326330
vcp->vc_inuse--;
327-
unlock_kernel();
331+
mutex_unlock(&vcp->vc_mutex);
328332
return 0;
329333
}
330334

@@ -353,9 +357,11 @@ static int init_coda_psdev(void)
353357
err = PTR_ERR(coda_psdev_class);
354358
goto out_chrdev;
355359
}
356-
for (i = 0; i < MAX_CODADEVS; i++)
360+
for (i = 0; i < MAX_CODADEVS; i++) {
361+
mutex_init(&(&coda_comms[i])->vc_mutex);
357362
device_create(coda_psdev_class, NULL,
358363
MKDEV(CODA_PSDEV_MAJOR, i), NULL, "cfs%d", i);
364+
}
359365
coda_sysctl_init();
360366
goto out;
361367

‎fs/coda/upcall.c‎

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <linux/errno.h>
2828
#include <linux/string.h>
2929
#include <linux/slab.h>
30-
#include <linux/smp_lock.h>
30+
#include <linux/mutex.h>
3131
#include <asm/uaccess.h>
3232
#include <linux/vmalloc.h>
3333
#include <linux/vfs.h>
@@ -607,7 +607,8 @@ static void coda_unblock_signals(sigset_t *old)
607607
(r)->uc_opcode != CODA_RELEASE) || \
608608
(r)->uc_flags & CODA_REQ_READ))
609609

610-
static inline void coda_waitfor_upcall(struct upc_req *req)
610+
static inline void coda_waitfor_upcall(struct venus_comm *vcp,
611+
struct upc_req *req)
611612
{
612613
DECLARE_WAITQUEUE(wait, current);
613614
unsigned long timeout = jiffies + coda_timeout * HZ;
@@ -640,10 +641,12 @@ static inline void coda_waitfor_upcall(struct upc_req *req)
640641
break;
641642
}
642643

644+
mutex_unlock(&vcp->vc_mutex);
643645
if (blocked)
644646
schedule_timeout(HZ);
645647
else
646648
schedule();
649+
mutex_lock(&vcp->vc_mutex);
647650
}
648651
if (blocked)
649652
coda_unblock_signals(&old);
@@ -671,7 +674,7 @@ static int coda_upcall(struct venus_comm *vcp,
671674
struct upc_req *req = NULL, *sig_req;
672675
int error;
673676

674-
lock_kernel();
677+
mutex_lock(&vcp->vc_mutex);
675678

676679
if (!vcp->vc_inuse) {
677680
printk(KERN_NOTICE "coda: Venus dead, not sending upcall\n");
@@ -711,7 +714,7 @@ static int coda_upcall(struct venus_comm *vcp,
711714
* ENODEV. */
712715

713716
/* Go to sleep. Wake up on signals only after the timeout. */
714-
coda_waitfor_upcall(req);
717+
coda_waitfor_upcall(vcp, req);
715718

716719
/* Op went through, interrupt or not... */
717720
if (req->uc_flags & CODA_REQ_WRITE) {
@@ -765,7 +768,7 @@ static int coda_upcall(struct venus_comm *vcp,
765768

766769
exit:
767770
kfree(req);
768-
unlock_kernel();
771+
mutex_unlock(&vcp->vc_mutex);
769772
return error;
770773
}
771774

@@ -806,11 +809,11 @@ static int coda_upcall(struct venus_comm *vcp,
806809
int coda_downcall(struct venus_comm *vcp, int opcode, union outputArgs *out)
807810
{
808811
struct inode *inode = NULL;
809-
struct CodaFid *fid, *newfid;
812+
struct CodaFid *fid = NULL, *newfid;
810813
struct super_block *sb;
811814

812815
/* Handle invalidation requests. */
813-
lock_kernel();
816+
mutex_lock(&vcp->vc_mutex);
814817
sb = vcp->vc_sb;
815818
if (!sb || !sb->s_root)
816819
goto unlock_out;
@@ -829,47 +832,53 @@ int coda_downcall(struct venus_comm *vcp, int opcode, union outputArgs *out)
829832

830833
case CODA_ZAPDIR:
831834
fid = &out->coda_zapdir.CodaFid;
832-
inode = coda_fid_to_inode(fid, sb);
833-
if (inode) {
834-
coda_flag_inode_children(inode, C_PURGE);
835-
coda_flag_inode(inode, C_VATTR);
836-
}
837835
break;
838836

839837
case CODA_ZAPFILE:
840838
fid = &out->coda_zapfile.CodaFid;
841-
inode = coda_fid_to_inode(fid, sb);
842-
if (inode)
843-
coda_flag_inode(inode, C_VATTR);
844839
break;
845840

846841
case CODA_PURGEFID:
847842
fid = &out->coda_purgefid.CodaFid;
848-
inode = coda_fid_to_inode(fid, sb);
849-
if (inode) {
850-
coda_flag_inode_children(inode, C_PURGE);
851-
852-
/* catch the dentries later if some are still busy */
853-
coda_flag_inode(inode, C_PURGE);
854-
d_prune_aliases(inode);
855-
856-
}
857843
break;
858844

859845
case CODA_REPLACE:
860846
fid = &out->coda_replace.OldFid;
861-
newfid = &out->coda_replace.NewFid;
862-
inode = coda_fid_to_inode(fid, sb);
863-
if (inode)
864-
coda_replace_fid(inode, fid, newfid);
865847
break;
866848
}
849+
if (fid)
850+
inode = coda_fid_to_inode(fid, sb);
867851

868852
unlock_out:
869-
unlock_kernel();
853+
mutex_unlock(&vcp->vc_mutex);
854+
855+
if (!inode)
856+
return 0;
857+
858+
switch (opcode) {
859+
case CODA_ZAPDIR:
860+
coda_flag_inode_children(inode, C_PURGE);
861+
coda_flag_inode(inode, C_VATTR);
862+
break;
863+
864+
case CODA_ZAPFILE:
865+
coda_flag_inode(inode, C_VATTR);
866+
break;
867+
868+
case CODA_PURGEFID:
869+
coda_flag_inode_children(inode, C_PURGE);
870870

871-
if (inode)
872-
iput(inode);
871+
/* catch the dentries later if some are still busy */
872+
coda_flag_inode(inode, C_PURGE);
873+
d_prune_aliases(inode);
874+
break;
875+
876+
case CODA_REPLACE:
877+
newfid = &out->coda_replace.NewFid;
878+
coda_replace_fid(inode, fid, newfid);
879+
break;
880+
}
881+
iput(inode);
873882
return 0;
874883
}
875884

‎include/linux/coda_psdev.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#ifdef __KERNEL__
1010
#include <linux/backing-dev.h>
11+
#include <linux/mutex.h>
1112

1213
struct kstatfs;
1314

@@ -20,6 +21,7 @@ struct venus_comm {
2021
int vc_inuse;
2122
struct super_block *vc_sb;
2223
struct backing_dev_info bdi;
24+
struct mutex vc_mutex;
2325
};
2426

2527

0 commit comments

Comments
 (0)