Whamcloud - gitweb
LU-812 ldiskfs: super_operations->dirty_inode now takes a flag
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_handler.c
index d6c82a4..e1bc36f 100644 (file)
@@ -53,8 +53,6 @@
 #include <linux/fs.h>
 /* XATTR_{REPLACE,CREATE} */
 #include <linux/xattr.h>
-/* simple_mkdir() */
-#include <lvfs.h>
 
 /*
  * struct OBD_{ALLOC,FREE}*()
@@ -1075,14 +1073,31 @@ static int osd_commit_async(const struct lu_env *env,
 
 static int osd_ro(const struct lu_env *env, struct dt_device *d)
 {
-        struct super_block *sb = osd_sb(osd_dt_dev(d));
-        int rc;
-        ENTRY;
+       struct super_block *sb = osd_sb(osd_dt_dev(d));
+       struct block_device *dev = sb->s_bdev;
+#ifdef HAVE_DEV_SET_RDONLY
+       struct block_device *jdev = LDISKFS_SB(sb)->journal_bdev;
+       int rc = 0;
+#else
+       int rc = -EOPNOTSUPP;
+#endif
+       ENTRY;
 
+#ifdef HAVE_DEV_SET_RDONLY
        CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
 
-        rc = __lvfs_set_rdonly(sb->s_bdev, LDISKFS_SB(sb)->journal_bdev);
-        RETURN(rc);
+       if (jdev && (jdev != dev)) {
+               CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n",
+                      (long)jdev);
+               dev_set_rdonly(jdev);
+       }
+       CDEBUG(D_IOCTL | D_HA, "set dev %lx rdonly\n", (long)dev);
+       dev_set_rdonly(dev);
+#else
+       CERROR("%s: %lx CANNOT BE SET READONLY: rc = %d\n",
+              osd_dt_dev(d)->od_svname, (long)dev, rc);
+#endif
+       RETURN(rc);
 }
 
 /*
@@ -1662,7 +1677,7 @@ static int osd_attr_set(const struct lu_env *env,
        spin_unlock(&obj->oo_guard);
 
         if (!rc)
-                inode->i_sb->s_op->dirty_inode(inode);
+               ll_dirty_inode(inode, I_DIRTY_DATASYNC);
         return rc;
 }
 
@@ -1914,7 +1929,7 @@ static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
                  * enabled on ldiskfs (lquota takes care of it).
                  */
                 LASSERTF(result == 0, "%d", result);
-                inode->i_sb->s_op->dirty_inode(inode);
+               ll_dirty_inode(inode, I_DIRTY_DATASYNC);
         }
 
         attr->la_valid = valid;
@@ -1932,6 +1947,11 @@ static int __osd_object_create(struct osd_thread_info *info,
                                struct thandle *th)
 {
        int     result;
+       __u32   umask;
+
+       /* we drop umask so that permissions we pass are not affected */
+       umask = current->fs->umask;
+       current->fs->umask = 0;
 
        result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
                                                  th);
@@ -1943,7 +1963,10 @@ static int __osd_object_create(struct osd_thread_info *info,
                        unlock_new_inode(obj->oo_inode);
         }
 
-        return result;
+       /* restore previous umask value */
+       current->fs->umask = umask;
+
+       return result;
 }
 
 /**
@@ -2166,7 +2189,7 @@ static int osd_object_destroy(const struct lu_env *env,
                spin_lock(&obj->oo_guard);
                clear_nlink(inode);
                spin_unlock(&obj->oo_guard);
-               inode->i_sb->s_op->dirty_inode(inode);
+               ll_dirty_inode(inode, I_DIRTY_DATASYNC);
        }
 
        osd_trans_exec_op(env, th, OSD_OT_DESTROY);
@@ -2467,7 +2490,7 @@ static int osd_object_ref_add(const struct lu_env *env,
        }
        LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
        spin_unlock(&obj->oo_guard);
-       inode->i_sb->s_op->dirty_inode(inode);
+       ll_dirty_inode(inode, I_DIRTY_DATASYNC);
        LINVRNT(osd_invariant(obj));
 
        return 0;
@@ -2516,7 +2539,7 @@ static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
        if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
                set_nlink(inode, 1);
        spin_unlock(&obj->oo_guard);
-       inode->i_sb->s_op->dirty_inode(inode);
+       ll_dirty_inode(inode, I_DIRTY_DATASYNC);
        LINVRNT(osd_invariant(obj));
 
        return 0;
@@ -2602,7 +2625,7 @@ static void osd_object_version_set(const struct lu_env *env,
         LDISKFS_I(inode)->i_fs_version = *new_version;
         /** Version is set after all inode operations are finished,
          *  so we should mark it dirty here */
-        inode->i_sb->s_op->dirty_inode(inode);
+       ll_dirty_inode(inode, I_DIRTY_DATASYNC);
 }
 
 /*
@@ -2616,6 +2639,7 @@ static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
        struct inode           *inode    = obj->oo_inode;
        struct osd_thread_info *info     = osd_oti_get(env);
        int                     fs_flags = 0;
+       ENTRY;
 
         LASSERT(handle != NULL);
 
@@ -2812,9 +2836,13 @@ static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
        file->f_dentry = dentry;
        file->f_mapping = inode->i_mapping;
        file->f_op = inode->i_fop;
+#ifndef HAVE_FILE_FSYNC_4ARGS
        mutex_lock(&inode->i_mutex);
-       rc = file->f_op->fsync(file, dentry, 0);
+#endif
+       rc = do_fsync(file, 0);
+#ifndef HAVE_FILE_FSYNC_4ARGS
        mutex_unlock(&inode->i_mutex);
+#endif
        RETURN(rc);
 }
 
@@ -4082,12 +4110,12 @@ osd_it_append_attrs(struct lu_dirent *ent, int len, __u16 type)
 {
        /* check if file type is required */
        if (ent->lde_attrs & LUDA_TYPE) {
-               int align = sizeof(struct luda_type) - 1;
                struct luda_type *lt;
+               int align = sizeof(*lt) - 1;
 
                len = (len + align) & ~align;
                lt = (struct luda_type *)(ent->lde_name + len);
-               lt->lt_type = cpu_to_le16(CFS_DTTOIF(type));
+               lt->lt_type = cpu_to_le16(DTTOIF(type));
        }
 
        ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
@@ -5010,12 +5038,14 @@ static void *osd_key_init(const struct lu_context *ctx,
 static void osd_key_fini(const struct lu_context *ctx,
                          struct lu_context_key *key, void* data)
 {
-        struct osd_thread_info *info = data;
+       struct osd_thread_info *info = data;
 
-        if (info->oti_hlock != NULL)
-                ldiskfs_htree_lock_free(info->oti_hlock);
-        OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
-        OBD_FREE_PTR(info);
+       if (info->oti_hlock != NULL)
+               ldiskfs_htree_lock_free(info->oti_hlock);
+       OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
+       lu_buf_free(&info->oti_iobuf.dr_pg_buf);
+       lu_buf_free(&info->oti_iobuf.dr_bl_buf);
+       OBD_FREE_PTR(info);
 }
 
 static void osd_key_exit(const struct lu_context *ctx,
@@ -5136,13 +5166,15 @@ static int osd_mount(const struct lu_env *env,
                GOTO(out, rc);
        }
 
-       if (lvfs_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
+#ifdef HAVE_DEV_SET_RDONLY
+       if (dev_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
                CERROR("%s: underlying device %s is marked as read-only. "
                       "Setup failed\n", name, dev);
                mntput(o->od_mnt);
                o->od_mnt = NULL;
                GOTO(out, rc = -EROFS);
        }
+#endif
 
        if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
            LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {