Whamcloud - gitweb
LU-1305 osd: xattr support for osd-zfs
[fs/lustre-release.git] / lustre / llite / lloop.c
index bbbb0ea..15e4314 100644 (file)
@@ -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.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -141,7 +141,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;
 
@@ -170,7 +170,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)
@@ -240,7 +240,7 @@ static int do_bio_lustrebacked(struct lloop_device *lo, struct bio *head)
 
         ll_stats_ops_tally(ll_i2sbi(inode),
                         (rw == WRITE) ? LPROC_LL_BRW_WRITE : LPROC_LL_BRW_READ,
-                        page_count << PAGE_CACHE_SHIFT);
+                        page_count);
 
         pvec->ldp_size = page_count << PAGE_CACHE_SHIFT;
         pvec->ldp_nr = page_count;
@@ -376,6 +376,7 @@ err:
         return 0;
 }
 
+#ifdef HAVE_REQUEST_QUEUE_UNPLUG_FN
 /*
  * kick off io on the underlying address space
  */
@@ -386,6 +387,7 @@ static void loop_unplug(struct request_queue *q)
         clear_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags);
         blk_run_address_space(lo->lo_backing_file->f_mapping);
 }
+#endif
 
 static inline void loop_handle_bio(struct lloop_device *lo, struct bio *bio)
 {
@@ -538,21 +540,24 @@ static int loop_set_fd(struct lloop_device *lo, struct file *unused,
          */
         blk_queue_make_request(lo->lo_queue, loop_make_request);
         lo->lo_queue->queuedata = lo;
+#ifdef HAVE_REQUEST_QUEUE_UNPLUG_FN
         lo->lo_queue->unplug_fn = loop_unplug;
+#endif
 
         /* queue parameters */
-        blk_queue_hardsect_size(lo->lo_queue, CFS_PAGE_SIZE);
-        blk_queue_max_sectors(lo->lo_queue,
-                              LLOOP_MAX_SEGMENTS << (CFS_PAGE_SHIFT - 9));
-        blk_queue_max_phys_segments(lo->lo_queue, LLOOP_MAX_SEGMENTS);
-        blk_queue_max_hw_segments(lo->lo_queue, LLOOP_MAX_SEGMENTS);
+        CLASSERT(CFS_PAGE_SIZE < (1 << (sizeof(unsigned short) * 8)));
+        blk_queue_logical_block_size(lo->lo_queue,
+                                     (unsigned short)CFS_PAGE_SIZE);
+        blk_queue_max_hw_sectors(lo->lo_queue,
+                                 LLOOP_MAX_SEGMENTS << (CFS_PAGE_SHIFT - 9));
+        blk_queue_max_segments(lo->lo_queue, LLOOP_MAX_SEGMENTS);
 
         set_capacity(disks[lo->lo_number], size);
         bd_set_size(bdev, size << 9);
 
         set_blocksize(bdev, lo->lo_blocksize);
 
-        cfs_kernel_thread(loop_thread, lo, CLONE_KERNEL);
+        cfs_create_thread(loop_thread, lo, CLONE_KERNEL);
         cfs_down(&lo->lo_sem);
         return 0;
 
@@ -600,52 +605,78 @@ static int loop_clr_fd(struct lloop_device *lo, struct block_device *bdev,
         return 0;
 }
 
+#ifdef HAVE_BLKDEV_PUT_2ARGS
+static int lo_open(struct block_device *bdev, fmode_t mode)
+{
+        struct lloop_device *lo = bdev->bd_disk->private_data;
+#else
 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;
 }
 
+#ifdef HAVE_BLKDEV_PUT_2ARGS
+static int lo_release(struct gendisk *disk, fmode_t mode)
+{
+        struct lloop_device *lo = disk->private_data;
+#else
 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;
 }
 
 /* lloop device node's ioctl function. */
+#ifdef HAVE_BLKDEV_PUT_2ARGS
+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 = 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;
         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);
                 if (err == 0)
-                        blkdev_put(bdev); /* grabbed in LLOOP_ATTACH */
+                        ll_blkdev_put(bdev, 0); /* grabbed in LLOOP_ATTACH */
                 break;
         }
 
         case LL_IOC_LLOOP_INFO: {
-                __u64 ino = 0;
+                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)
-                        ino = lo->lo_backing_file->f_dentry->d_inode->i_ino;
+                        fid = ll_i2info(inode)->lli_fid;
+                else
+                        fid_zero(&fid);
 
-                if (put_user(ino, (__u64 *)arg))
+                if (copy_to_user((struct lu_fid *)arg, &fid, sizeof(fid)))
                         err = -EFAULT;
                 break;
         }
@@ -654,7 +685,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;
 }
@@ -690,7 +721,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;
@@ -717,7 +748,7 @@ static enum llioc_iter lloop_ioctl(struct inode *unused, struct file *file,
                 if (put_user((long)old_encode_dev(dev), (long*)arg))
                         GOTO(out, err = -EFAULT);
 
-                bdev = open_by_devnum(dev, file->f_mode);
+                bdev = blkdev_get_by_dev(dev, file->f_mode, NULL);
                 if (IS_ERR(bdev))
                         GOTO(out, err = PTR_ERR(bdev));
 
@@ -725,7 +756,7 @@ static enum llioc_iter lloop_ioctl(struct inode *unused, struct file *file,
                 err = loop_set_fd(lo, NULL, bdev, file);
                 if (err) {
                         fput(file);
-                        blkdev_put(bdev);
+                        ll_blkdev_put(bdev, 0);
                 }
 
                 break;
@@ -749,7 +780,7 @@ static enum llioc_iter lloop_ioctl(struct inode *unused, struct file *file,
                 bdev = lo->lo_device;
                 err = loop_clr_fd(lo, bdev, 1);
                 if (err == 0)
-                        blkdev_put(bdev); /* grabbed in LLOOP_ATTACH */
+                        ll_blkdev_put(bdev, 0); /* grabbed in LLOOP_ATTACH */
 
                 break;
         }
@@ -760,7 +791,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;
@@ -806,7 +837,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];
@@ -816,8 +847,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);