Whamcloud - gitweb
LU-2642 osd-ldiskfs: Use __REQ_WRITE instead of BIO_RW.
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_io.c
index 5626f5f..dac9d00 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -137,6 +137,10 @@ void osd_fini_iobuf(struct osd_device *d, struct osd_iobuf *iobuf)
         }
 }
 
+#ifndef __REQ_WRITE /* pre-2.6.35 */
+#define __REQ_WRITE BIO_RW
+#endif
+
 #ifdef HAVE_BIO_ENDIO_2ARG
 #define DIO_RETURN(a)
 static void dio_complete_routine(struct bio *bio, int error)
@@ -171,7 +175,7 @@ static int dio_complete_routine(struct bio *bio, unsigned int done, int error)
         }
 
         /* the check is outside of the cycle for performance reason -bzzz */
-        if (!cfs_test_bit(BIO_RW, &bio->bi_rw)) {
+       if (!test_bit(__REQ_WRITE, &bio->bi_rw)) {
                 bio_for_each_segment(bvl, bio, i) {
                         if (likely(error == 0))
                                 SetPageUptodate(bvl->bv_page);
@@ -352,10 +356,10 @@ static int osd_do_bio(struct osd_device *osd, struct inode *inode,
                                 osd_submit_bio(iobuf->dr_rw, bio);
                         }
 
-                        /* allocate new bio, limited by max BIO size, b=9945 */
-                        bio = bio_alloc(GFP_NOIO, max(BIO_MAX_PAGES,
-                                                      (npages - page_idx) *
-                                                      blocks_per_page));
+                       /* allocate new bio */
+                       bio = bio_alloc(GFP_NOIO, min(BIO_MAX_PAGES,
+                                                     (npages - page_idx) *
+                                                     blocks_per_page));
                         if (bio == NULL) {
                                 CERROR("Can't allocate bio %u*%u = %u pages\n",
                                        (npages - page_idx), blocks_per_page,
@@ -448,7 +452,6 @@ struct page *osd_get_page(struct dt_object *dt, loff_t offset, int rw)
 /*
  * there are following "locks":
  * journal_start
- * i_alloc_sem
  * i_mutex
  * page lock
 
@@ -923,10 +926,10 @@ int osd_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs)
         int err;
 
         /* prevent reading after eof */
-        cfs_spin_lock(&inode->i_lock);
-        if (i_size_read(inode) < *offs + size) {
+       spin_lock(&inode->i_lock);
+       if (i_size_read(inode) < *offs + size) {
                loff_t diff = i_size_read(inode) - *offs;
-               cfs_spin_unlock(&inode->i_lock);
+               spin_unlock(&inode->i_lock);
                if (diff < 0) {
                        CDEBUG(D_EXT2, "size %llu is too short to read @%llu\n",
                               i_size_read(inode), *offs);
@@ -936,9 +939,9 @@ int osd_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs)
                } else {
                        size = diff;
                }
-        } else {
-                cfs_spin_unlock(&inode->i_lock);
-        }
+       } else {
+               spin_unlock(&inode->i_lock);
+       }
 
         blocksize = 1 << inode->i_blkbits;
         osize = size;
@@ -978,7 +981,7 @@ static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
          * on-disk symlinks for ldiskfs.
          */
         if (S_ISLNK(dt->do_lu.lo_header->loh_attr) &&
-            (buf->lb_len <= sizeof(LDISKFS_I(inode)->i_data)))
+            (buf->lb_len < sizeof(LDISKFS_I(inode)->i_data)))
                 rc = osd_ldiskfs_readlink(inode, buf->lb_buf, buf->lb_len);
         else
                 rc = osd_ldiskfs_read(inode, buf->lb_buf, buf->lb_len, pos);
@@ -1013,8 +1016,7 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt,
         else
                 credits = osd_dto_credits_noquota[DTO_WRITE_BLOCK];
 
-        OSD_DECLARE_OP(oh, write);
-        oh->ot_credits += credits;
+       osd_trans_declare_op(env, oh, OSD_OT_WRITE, credits);
 
        inode = osd_dt_obj(dt)->oo_inode;
 
@@ -1032,6 +1034,8 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt,
 
 static int osd_ldiskfs_writelink(struct inode *inode, char *buffer, int buflen)
 {
+       /* LU-2634: clear the extent format for fast symlink */
+       ldiskfs_clear_inode_flag(inode, LDISKFS_INODE_EXTENTS);
 
         memcpy((char *)&LDISKFS_I(inode)->i_data, (char *)buffer, buflen);
         LDISKFS_I(inode)->i_disksize = buflen;
@@ -1105,14 +1109,14 @@ int osd_ldiskfs_write_record(struct inode *inode, void *buf, int bufsize,
                --new_size;
         /* correct in-core and on-disk sizes */
         if (new_size > i_size_read(inode)) {
-                cfs_spin_lock(&inode->i_lock);
-                if (new_size > i_size_read(inode))
-                        i_size_write(inode, new_size);
-                if (i_size_read(inode) > LDISKFS_I(inode)->i_disksize) {
-                        LDISKFS_I(inode)->i_disksize = i_size_read(inode);
-                        dirty_inode = 1;
-                }
-                cfs_spin_unlock(&inode->i_lock);
+               spin_lock(&inode->i_lock);
+               if (new_size > i_size_read(inode))
+                       i_size_write(inode, new_size);
+               if (i_size_read(inode) > LDISKFS_I(inode)->i_disksize) {
+                       LDISKFS_I(inode)->i_disksize = i_size_read(inode);
+                       dirty_inode = 1;
+               }
+               spin_unlock(&inode->i_lock);
                 if (dirty_inode)
                         inode->i_sb->s_op->dirty_inode(inode);
         }
@@ -1142,7 +1146,7 @@ static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
        ll_vfs_dq_init(inode);
 
         /* XXX: don't check: one declared chunk can be used many times */
-        /* OSD_EXEC_OP(handle, write); */
+       /* osd_trans_exec_op(env, handle, OSD_OT_WRITE); */
 
         oh = container_of(handle, struct osd_thandle, ot_super);
         LASSERT(oh->ot_handle->h_transaction != NULL);
@@ -1174,8 +1178,6 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt,
         LASSERT(th);
         oh = container_of(th, struct osd_thandle, ot_super);
 
-        OSD_DECLARE_OP(oh, punch);
-
         /*
          * we don't need to reserve credits for whole truncate
          * it's not possible as truncate may need to free too many
@@ -1184,8 +1186,8 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt,
          * orphan list. if needed truncate will extend or restart
          * transaction
          */
-        oh->ot_credits += osd_dto_credits_noquota[DTO_ATTR_SET_BASE];
-        oh->ot_credits += 3;
+       osd_trans_declare_op(env, oh, OSD_OT_PUNCH,
+                            osd_dto_credits_noquota[DTO_ATTR_SET_BASE] + 3);
 
        inode = osd_dt_obj(dt)->oo_inode;
        LASSERT(inode);
@@ -1217,7 +1219,7 @@ static int osd_punch(const struct lu_env *env, struct dt_object *dt,
         oh = container_of(th, struct osd_thandle, ot_super);
         LASSERT(oh->ot_handle->h_transaction != NULL);
 
-        OSD_EXEC_OP(th, punch);
+       osd_trans_exec_op(env, th, OSD_OT_PUNCH);
 
         tid = oh->ot_handle->h_transaction->t_tid;