Whamcloud - gitweb
LU-2850 kernel: 3.8 upstream removes vmtruncate()
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_io.c
index 61d7da7..c9eb4eb 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, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 /* prerequisite for linux/xattr.h */
 #include <linux/fs.h>
 
-/* ext_depth() */
-#include <ldiskfs/ldiskfs.h>
-#include <ldiskfs/ldiskfs_jbd2.h>
-#include <ldiskfs/ldiskfs_extents.h>
-
 /*
  * struct OBD_{ALLOC,FREE}*()
  * OBD_FAIL_CHECK
@@ -62,6 +57,9 @@
 
 #include "osd_internal.h"
 
+/* ext_depth() */
+#include <ldiskfs/ldiskfs_extents.h>
+
 #ifndef HAVE_PAGE_CONSTANT
 #define mapping_cap_page_constant_write(mapping) 0
 #define SetPageConstant(page) do {} while (0)
@@ -711,10 +709,15 @@ static int osd_declare_write_commit(const struct lu_env *env,
                /* ignore quota for the whole request if any page is from
                 * client cache or written by root.
                 *
+                * XXX once we drop the 1.8 client support, the checking
+                * for whether page is from cache can be simplified as:
+                * !(lnb[i].flags & OBD_BRW_SYNC)
+                *
                 * XXX we could handle this on per-lnb basis as done by
                 * grant. */
                if ((lnb[i].flags & OBD_BRW_NOQUOTA) ||
-                   !(lnb[i].flags & OBD_BRW_SYNC))
+                   (lnb[i].flags & (OBD_BRW_FROM_GRANT | OBD_BRW_SYNC)) ==
+                   OBD_BRW_FROM_GRANT)
                        ignore_quota = true;
        }
 
@@ -1045,17 +1048,7 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt,
         oh = container_of0(handle, struct osd_thandle, ot_super);
         LASSERT(oh->ot_handle == NULL);
 
-        /* XXX: size == 0 or INT_MAX indicating a catalog header update or
-         *      llog write, see comment in mdd_declare_llog_record().
-         *
-         *      This hack will be removed with llog over OSD landing
-         */
-        if (size == DECLARE_LLOG_REWRITE)
-                credits = 2;
-        else if (size == DECLARE_LLOG_WRITE)
-                credits = 6;
-        else
-                credits = osd_dto_credits_noquota[DTO_WRITE_BLOCK];
+       credits = osd_dto_credits_noquota[DTO_WRITE_BLOCK];
 
        osd_trans_declare_op(env, oh, OSD_OT_WRITE, credits);
 
@@ -1247,7 +1240,8 @@ static int osd_punch(const struct lu_env *env, struct dt_object *dt,
         struct inode       *inode = obj->oo_inode;
         handle_t           *h;
         tid_t               tid;
-        int                 rc, rc2 = 0;
+       loff_t             oldsize;
+       int                rc = 0, rc2 = 0;
         ENTRY;
 
         LASSERT(end == OBD_OBJECT_EOF);
@@ -1264,13 +1258,17 @@ static int osd_punch(const struct lu_env *env, struct dt_object *dt,
 
         tid = oh->ot_handle->h_transaction->t_tid;
 
-        rc = vmtruncate(inode, start);
+       oldsize=inode->i_size;
+       i_size_write(inode, start);
+       truncate_pagecache(inode, oldsize, start);
+       if (inode->i_op->truncate)
+               inode->i_op->truncate(inode);
 
         /*
          * For a partial-page truncate, flush the page to disk immediately to
          * avoid data corruption during direct disk write.  b=17397
          */
-        if (rc == 0 && (start & ~CFS_PAGE_MASK) != 0)
+       if ((start & ~CFS_PAGE_MASK) != 0)
                 rc = filemap_fdatawrite_range(inode->i_mapping, start, start+1);
 
         h = journal_current_handle();
@@ -1304,6 +1302,7 @@ static int osd_fiemap_get(const struct lu_env *env, struct dt_object *dt,
 
         LASSERT(inode);
         dentry->d_inode = inode;
+       dentry->d_sb = inode->i_sb;
         file->f_dentry = dentry;
         file->f_mapping = inode->i_mapping;
         file->f_op = inode->i_fop;
@@ -1338,8 +1337,8 @@ const struct dt_body_operations osd_body_ops = {
         .dbo_declare_write_commit = osd_declare_write_commit,
         .dbo_write_commit         = osd_write_commit,
         .dbo_read_prep            = osd_read_prep,
-        .do_declare_punch         = osd_declare_punch,
-        .do_punch                 = osd_punch,
+        .dbo_declare_punch         = osd_declare_punch,
+        .dbo_punch                 = osd_punch,
         .dbo_fiemap_get           = osd_fiemap_get,
 };