Whamcloud - gitweb
LU-5569 ptlrpc: change reverse import life cycle
[fs/lustre-release.git] / lustre / llite / lloop.c
index 55e3e6b..0e68b51 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -82,6 +82,7 @@
 #include <linux/module.h>
 
 #include <linux/sched.h>
+#include <linux/kthread.h>
 #include <linux/fs.h>
 #include <linux/file.h>
 #include <linux/stat.h>
 #include <asm/uaccess.h>
 
 #include <lustre_lib.h>
-#include <lustre_lite.h>
 #include "llite_internal.h"
 
 #define LLOOP_MAX_SEGMENTS        LNET_MAX_IOV
@@ -127,7 +127,7 @@ struct lloop_device {
        struct block_device *lo_device;
        unsigned             lo_blocksize;
 
-       int                  old_gfp_mask;
+       gfp_t                   old_gfp_mask;
 
        spinlock_t              lo_lock;
        struct bio              *lo_bio;
@@ -188,14 +188,20 @@ static int do_bio_lustrebacked(struct lloop_device *lo, struct bio *head)
 {
         const struct lu_env  *env   = lo->lo_env;
         struct cl_io         *io    = &lo->lo_io;
-        struct inode         *inode = lo->lo_backing_file->f_dentry->d_inode;
+       struct dentry        *de    = lo->lo_backing_file->f_path.dentry;
+       struct inode         *inode = de->d_inode;
         struct cl_object     *obj = ll_i2info(inode)->lli_clob;
         pgoff_t               offset;
         int                   ret;
-        int                   i;
+#ifdef HAVE_BVEC_ITER
+       struct bvec_iter      iter;
+       struct bio_vec        bvec;
+#else
+       int                   iter;
+       struct bio_vec       *bvec;
+#endif
         int                   rw;
-        obd_count             page_count = 0;
-        struct bio_vec       *bvec;
+       size_t                page_count = 0;
         struct bio           *bio;
         ssize_t               bytes;
 
@@ -218,18 +224,30 @@ static int do_bio_lustrebacked(struct lloop_device *lo, struct bio *head)
         for (bio = head; bio != NULL; bio = bio->bi_next) {
                 LASSERT(rw == bio->bi_rw);
 
-                offset = (pgoff_t)(bio->bi_sector << 9) + lo->lo_offset;
-                bio_for_each_segment(bvec, bio, i) {
-                        BUG_ON(bvec->bv_offset != 0);
+#ifdef HAVE_BVEC_ITER
+               offset = (pgoff_t)(bio->bi_iter.bi_sector << 9) + lo->lo_offset;
+               bio_for_each_segment(bvec, bio, iter) {
+                       BUG_ON(bvec.bv_offset != 0);
+                       BUG_ON(bvec.bv_len != PAGE_CACHE_SIZE);
+
+                       pages[page_count] = bvec.bv_page;
+                       offsets[page_count] = offset;
+                       page_count++;
+                       offset += bvec.bv_len;
+#else
+               offset = (pgoff_t)(bio->bi_sector << 9) + lo->lo_offset;
+               bio_for_each_segment(bvec, bio, iter) {
+                       BUG_ON(bvec->bv_offset != 0);
                        BUG_ON(bvec->bv_len != PAGE_CACHE_SIZE);
 
-                        pages[page_count] = bvec->bv_page;
-                        offsets[page_count] = offset;
-                        page_count++;
-                        offset += bvec->bv_len;
-                }
-                LASSERT(page_count <= LLOOP_MAX_SEGMENTS);
-        }
+                       pages[page_count] = bvec->bv_page;
+                       offsets[page_count] = offset;
+                       page_count++;
+                       offset += bvec->bv_len;
+#endif
+               }
+               LASSERT(page_count <= LLOOP_MAX_SEGMENTS);
+       }
 
         ll_stats_ops_tally(ll_i2sbi(inode),
                         (rw == WRITE) ? LPROC_LL_BRW_WRITE : LPROC_LL_BRW_READ,
@@ -310,12 +328,17 @@ static unsigned int loop_get_bio(struct lloop_device *lo, struct bio **req)
         rw = first->bi_rw;
         bio = &lo->lo_bio;
         while (*bio && (*bio)->bi_rw == rw) {
-                CDEBUG(D_INFO, "bio sector %llu size %u count %u vcnt%u \n",
-                       (unsigned long long)(*bio)->bi_sector, (*bio)->bi_size,
-                       page_count, (*bio)->bi_vcnt);
-                if (page_count + (*bio)->bi_vcnt > LLOOP_MAX_SEGMENTS)
-                        break;
-
+#ifdef HAVE_BVEC_ITER
+               CDEBUG(D_INFO, "bio sector %llu size %u count %u vcnt%u \n",
+                      (unsigned long long)(*bio)->bi_iter.bi_sector,
+                      (*bio)->bi_iter.bi_size, page_count, (*bio)->bi_vcnt);
+#else
+               CDEBUG(D_INFO, "bio sector %llu size %u count %u vcnt%u \n",
+                      (unsigned long long)(*bio)->bi_sector, (*bio)->bi_size,
+                      page_count, (*bio)->bi_vcnt);
+#endif
+               if (page_count + (*bio)->bi_vcnt > LLOOP_MAX_SEGMENTS)
+                       break;
 
                 page_count += (*bio)->bi_vcnt;
                 count++;
@@ -345,8 +368,14 @@ loop_make_request(struct request_queue *q, struct bio *old_bio)
         if (!lo)
                 goto err;
 
-        CDEBUG(D_INFO, "submit bio sector %llu size %u\n",
-               (unsigned long long)old_bio->bi_sector, old_bio->bi_size);
+#ifdef HAVE_BVEC_ITER
+       CDEBUG(D_INFO, "submit bio sector %llu size %u\n",
+              (unsigned long long)old_bio->bi_iter.bi_sector,
+              old_bio->bi_iter.bi_size);
+#else
+       CDEBUG(D_INFO, "submit bio sector %llu size %u\n",
+              (unsigned long long)old_bio->bi_sector, old_bio->bi_size);
+#endif
 
        spin_lock_irq(&lo->lo_lock);
        inactive = (lo->lo_state != LLOOP_BOUND);
@@ -559,7 +588,7 @@ static int loop_clr_fd(struct lloop_device *lo, struct block_device *bdev,
                        int count)
 {
         struct file *filp = lo->lo_backing_file;
-        int gfp = lo->old_gfp_mask;
+       gfp_t gfp = lo->old_gfp_mask;
 
         if (lo->lo_state != LLOOP_BOUND)
                 return -ENXIO;
@@ -624,9 +653,8 @@ lo_release(struct gendisk *disk, fmode_t mode)
 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;
+       struct lloop_device *lo = bdev->bd_disk->private_data;
+       int err = 0;
 
        mutex_lock(&lloop_mutex);
         switch (cmd) {
@@ -637,23 +665,24 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
                 break;
         }
 
-        case LL_IOC_LLOOP_INFO: {
-                struct lu_fid fid;
+       case LL_IOC_LLOOP_INFO: {
+               struct inode *inode;
+               struct lu_fid fid;
 
                if (lo->lo_backing_file == NULL) {
                        err = -ENOENT;
                        break;
                }
-                if (inode == NULL)
-                        inode = lo->lo_backing_file->f_dentry->d_inode;
-                if (lo->lo_state == LLOOP_BOUND)
+               inode = lo->lo_backing_file->f_path.dentry->d_inode;
+               if (inode != NULL && lo->lo_state == LLOOP_BOUND)
                         fid = ll_i2info(inode)->lli_fid;
                 else
                         fid_zero(&fid);
 
-                if (copy_to_user((struct lu_fid *)arg, &fid, sizeof(fid)))
-                        err = -EFAULT;
-                break;
+               if (copy_to_user((struct lu_fid __user *)arg,
+                                &fid, sizeof(fid)))
+                       err = -EFAULT;
+               break;
         }
 
         default:
@@ -697,10 +726,11 @@ static enum llioc_iter lloop_ioctl(struct inode *unused, struct file *file,
         CWARN("Enter llop_ioctl\n");
 
        mutex_lock(&lloop_mutex);
-        switch (cmd) {
-        case LL_IOC_LLOOP_ATTACH: {
-                struct lloop_device *lo_free = NULL;
-                int i;
+       switch (cmd) {
+       case LL_IOC_LLOOP_ATTACH: {
+               struct inode *inode = file->f_path.dentry->d_inode;
+               struct lloop_device *lo_free = NULL;
+               int i;
 
                 for (i = 0; i < max_loop; i++, lo = NULL) {
                         lo = &loop_dev[i];
@@ -709,19 +739,19 @@ static enum llioc_iter lloop_ioctl(struct inode *unused, struct file *file,
                                         lo_free = lo;
                                 continue;
                         }
-                        if (lo->lo_backing_file->f_dentry->d_inode ==
-                            file->f_dentry->d_inode)
-                                break;
-                }
-                if (lo || !lo_free)
-                        GOTO(out, err = -EBUSY);
+                       if (lo->lo_backing_file->f_path.dentry->d_inode ==
+                           inode)
+                               break;
+               }
+               if (lo || !lo_free)
+                       GOTO(out, err = -EBUSY);
 
                 lo = lo_free;
                 dev = MKDEV(lloop_major, lo->lo_number);
 
                 /* quit if the used pointer is writable */
-                if (put_user((long)old_encode_dev(dev), (long*)arg))
-                        GOTO(out, err = -EFAULT);
+               if (put_user((long)old_encode_dev(dev), (long __user *)arg))
+                       GOTO(out, err = -EFAULT);
 
                 bdev = blkdev_get_by_dev(dev, file->f_mode, NULL);
                 if (IS_ERR(bdev))