X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fllite%2Flloop.c;h=5f4dec3f3f5db880783ba53f09767d44e5d9214d;hp=df95d712b6b93d6cfa4a28b78e3c5df688bb854a;hb=539d4218b8c6d025bb2ebffec313a38b53e08cd1;hpb=65701b4a30efdb695776bcf690a2b3cabc928da1 diff --git a/lustre/llite/lloop.c b/lustre/llite/lloop.c index df95d71..5f4dec3 100644 --- a/lustre/llite/lloop.c +++ b/lustre/llite/lloop.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -81,9 +79,6 @@ * */ -#ifndef AUTOCONF_INCLUDED -#include -#endif #include #include @@ -96,7 +91,6 @@ #include #include #include -#include #include #include #include @@ -143,7 +137,7 @@ struct lloop_device { struct bio *lo_biotail; int lo_state; cfs_semaphore_t lo_sem; - cfs_semaphore_t lo_ctl_mutex; + cfs_mutex_t lo_ctl_mutex; cfs_atomic_t lo_pending; cfs_waitq_t lo_bh_wait; @@ -172,7 +166,7 @@ static int lloop_major; static int max_loop = MAX_LOOP_DEFAULT; static struct lloop_device *loop_dev; static struct gendisk **disks; -static cfs_semaphore_t lloop_mutex; +static cfs_mutex_t lloop_mutex; static void *ll_iocontrol_magic = NULL; static loff_t get_loop_size(struct lloop_device *lo, struct file *file) @@ -247,32 +241,32 @@ static int do_bio_lustrebacked(struct lloop_device *lo, struct bio *head) pvec->ldp_size = page_count << PAGE_CACHE_SHIFT; pvec->ldp_nr = page_count; - /* FIXME: in ll_direct_rw_pages, it has to allocate many cl_page{}s to - * write those pages into OST. Even worse case is that more pages - * would be asked to write out to swap space, and then finally get here - * again. - * Unfortunately this is NOT easy to fix. - * Thoughts on solution: - * 0. Define a reserved pool for cl_pages, which could be a list of - * pre-allocated cl_pages from cl_page_kmem; - * 1. Define a new operation in cl_object_operations{}, says clo_depth, - * which measures how many layers for this lustre object. Generally - * speaking, the depth would be 2, one for llite, and one for lovsub. - * However, for SNS, there will be more since we need additional page - * to store parity; - * 2. Reserve the # of (page_count * depth) cl_pages from the reserved - * pool. Afterwards, the clio would allocate the pages from reserved - * pool, this guarantees we neeedn't allocate the cl_pages from - * generic cl_page slab cache. - * Of course, if there is NOT enough pages in the pool, we might - * be asked to write less pages once, this purely depends on - * implementation. Anyway, we should be careful to avoid deadlocking. - */ - LOCK_INODE_MUTEX(inode); - bytes = ll_direct_rw_pages(env, io, rw, inode, pvec); - UNLOCK_INODE_MUTEX(inode); - cl_io_fini(env, io); - return (bytes == pvec->ldp_size) ? 0 : (int)bytes; + /* FIXME: in ll_direct_rw_pages, it has to allocate many cl_page{}s to + * write those pages into OST. Even worse case is that more pages + * would be asked to write out to swap space, and then finally get here + * again. + * Unfortunately this is NOT easy to fix. + * Thoughts on solution: + * 0. Define a reserved pool for cl_pages, which could be a list of + * pre-allocated cl_pages from cl_page_kmem; + * 1. Define a new operation in cl_object_operations{}, says clo_depth, + * which measures how many layers for this lustre object. Generally + * speaking, the depth would be 2, one for llite, and one for lovsub. + * However, for SNS, there will be more since we need additional page + * to store parity; + * 2. Reserve the # of (page_count * depth) cl_pages from the reserved + * pool. Afterwards, the clio would allocate the pages from reserved + * pool, this guarantees we neeedn't allocate the cl_pages from + * generic cl_page slab cache. + * Of course, if there is NOT enough pages in the pool, we might + * be asked to write less pages once, this purely depends on + * implementation. Anyway, we should be careful to avoid deadlocking. + */ + mutex_lock(&inode->i_mutex); + bytes = ll_direct_rw_pages(env, io, rw, inode, pvec); + mutex_unlock(&inode->i_mutex); + cl_io_fini(env, io); + return (bytes == pvec->ldp_size) ? 0 : (int)bytes; } /* @@ -617,9 +611,9 @@ static int lo_open(struct inode *inode, struct file *file) struct lloop_device *lo = inode->i_bdev->bd_disk->private_data; #endif - cfs_down(&lo->lo_ctl_mutex); + cfs_mutex_lock(&lo->lo_ctl_mutex); lo->lo_refcnt++; - cfs_up(&lo->lo_ctl_mutex); + cfs_mutex_unlock(&lo->lo_ctl_mutex); return 0; } @@ -634,9 +628,9 @@ static int lo_release(struct inode *inode, struct file *file) struct lloop_device *lo = inode->i_bdev->bd_disk->private_data; #endif - cfs_down(&lo->lo_ctl_mutex); + cfs_mutex_lock(&lo->lo_ctl_mutex); --lo->lo_refcnt; - cfs_up(&lo->lo_ctl_mutex); + cfs_mutex_unlock(&lo->lo_ctl_mutex); return 0; } @@ -647,17 +641,18 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { struct lloop_device *lo = bdev->bd_disk->private_data; - struct inode *inode = lo->lo_backing_file->f_dentry->d_inode; + struct inode *inode = NULL; + int err = 0; #else static int lo_ioctl(struct inode *inode, struct file *unused, unsigned int cmd, unsigned long arg) { struct lloop_device *lo = inode->i_bdev->bd_disk->private_data; struct block_device *bdev = inode->i_bdev; -#endif int err = 0; +#endif - cfs_down(&lloop_mutex); + cfs_mutex_lock(&lloop_mutex); switch (cmd) { case LL_IOC_LLOOP_DETACH: { err = loop_clr_fd(lo, bdev, 2); @@ -669,6 +664,9 @@ static int lo_ioctl(struct inode *inode, struct file *unused, case LL_IOC_LLOOP_INFO: { struct lu_fid fid; + LASSERT(lo->lo_backing_file != NULL); + if (inode == NULL) + inode = lo->lo_backing_file->f_dentry->d_inode; if (lo->lo_state == LLOOP_BOUND) fid = ll_i2info(inode)->lli_fid; else @@ -683,7 +681,7 @@ static int lo_ioctl(struct inode *inode, struct file *unused, err = -EINVAL; break; } - cfs_up(&lloop_mutex); + cfs_mutex_unlock(&lloop_mutex); return err; } @@ -719,7 +717,7 @@ static enum llioc_iter lloop_ioctl(struct inode *unused, struct file *file, CWARN("Enter llop_ioctl\n"); - cfs_down(&lloop_mutex); + cfs_mutex_lock(&lloop_mutex); switch (cmd) { case LL_IOC_LLOOP_ATTACH: { struct lloop_device *lo_free = NULL; @@ -789,7 +787,7 @@ static enum llioc_iter lloop_ioctl(struct inode *unused, struct file *file, } out: - cfs_up(&lloop_mutex); + cfs_mutex_unlock(&lloop_mutex); out1: if (rcp) *rcp = err; @@ -835,7 +833,7 @@ static int __init lloop_init(void) goto out_mem3; } - cfs_init_mutex(&lloop_mutex); + cfs_mutex_init(&lloop_mutex); for (i = 0; i < max_loop; i++) { struct lloop_device *lo = &loop_dev[i]; @@ -845,8 +843,8 @@ static int __init lloop_init(void) if (!lo->lo_queue) goto out_mem4; - cfs_init_mutex(&lo->lo_ctl_mutex); - cfs_init_mutex_locked(&lo->lo_sem); + cfs_mutex_init(&lo->lo_ctl_mutex); + cfs_sema_init(&lo->lo_sem, 0); cfs_waitq_init(&lo->lo_bh_wait); lo->lo_number = i; cfs_spin_lock_init(&lo->lo_lock);