Whamcloud - gitweb
LU-2275 mdt: Avoid setting positive dispositions too early
[fs/lustre-release.git] / lustre / lvfs / lvfs_linux.c
index 5d4608b..eef01f4 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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  * Author: Andreas Dilger <adilger@clusterfs.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
-
 #define DEBUG_SUBSYSTEM S_FILTER
 
 #include <linux/version.h>
 
 #include <obd.h>
 #include <lustre_lib.h>
-#include <lustre_quota.h>
 
 __u64 obd_max_pages = 0;
 __u64 obd_max_alloc = 0;
 struct lprocfs_stats *obd_memory = NULL;
-spinlock_t obd_updatemax_lock = SPIN_LOCK_UNLOCKED;
+EXPORT_SYMBOL(obd_memory);
+DEFINE_SPINLOCK(obd_updatemax_lock);
 /* refine later and change to seqlock or simlar from libcfs */
 
 /* Debugging check only needed during development */
@@ -120,16 +116,20 @@ static void pop_group_info(struct lvfs_run_ctxt *save,
 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
                struct lvfs_ucred *uc)
 {
+       /* if there is underlaying dt_device then push_ctxt is not needed */
+       if (new_ctx->dt != NULL)
+               return;
+
         //ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n");
         ASSERT_CTXT_MAGIC(new_ctx->magic);
         OBD_SET_CTXT_MAGIC(save);
 
         save->fs = get_fs();
-        LASSERT(atomic_read(&cfs_fs_pwd(current->fs)->d_count));
-        LASSERT(atomic_read(&new_ctx->pwd->d_count));
+       LASSERT(d_refcount(cfs_fs_pwd(current->fs)));
+       LASSERT(d_refcount(new_ctx->pwd));
         save->pwd = dget(cfs_fs_pwd(current->fs));
         save->pwdmnt = mntget(cfs_fs_mnt(current->fs));
-        save->luc.luc_umask = current->fs->umask;
+        save->luc.luc_umask = cfs_curproc_umask();
         save->ngroups = current_cred()->group_info->ngroups;
 
         LASSERT(save->pwd);
@@ -168,6 +168,10 @@ EXPORT_SYMBOL(push_ctxt);
 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,
               struct lvfs_ucred *uc)
 {
+       /* if there is underlaying dt_device then pop_ctxt is not needed */
+       if (new_ctx->dt != NULL)
+               return;
+
         ASSERT_CTXT_MAGIC(saved->magic);
         ASSERT_KERNEL_CTXT("popping non-kernel context!\n");
 
@@ -231,10 +235,10 @@ struct dentry *simple_mknod(struct dentry *dir, char *name, int mode, int fix)
                 GOTO(out_up, dchild);
         }
 
-        err = ll_vfs_create(dir->d_inode, dchild, (mode & ~S_IFMT) | S_IFREG,
-                            NULL);
-        if (err)
-                GOTO(out_err, err);
+       err = vfs_create(dir->d_inode, dchild, (mode & ~S_IFMT) | S_IFREG,
+                           NULL);
+       if (err)
+               GOTO(out_err, err);
 
         RETURN(dchild);
 
@@ -375,7 +379,7 @@ int lustre_fsync(struct file *file)
         if (!file || !file->f_op || !file->f_op->fsync)
                 RETURN(-ENOSYS);
 
-        RETURN(file->f_op->fsync(file, file->f_dentry, 0));
+        RETURN(cfs_do_fsync(file, 0));
 }
 EXPORT_SYMBOL(lustre_fsync);
 
@@ -388,13 +392,8 @@ struct l_file *l_dentry_open(struct lvfs_run_ctxt *ctxt, struct l_dentry *de,
 }
 EXPORT_SYMBOL(l_dentry_open);
 
-#ifdef HAVE_VFS_READDIR_U64_INO
 static int l_filldir(void *__buf, const char *name, int namlen, loff_t offset,
                      u64 ino, unsigned int d_type)
-#else
-static int l_filldir(void *__buf, const char *name, int namlen, loff_t offset,
-                     ino_t ino, unsigned int d_type)
-#endif
 {
         struct l_linux_dirent *dirent;
         struct l_readdir_callback *buf = (struct l_readdir_callback *)__buf;
@@ -408,7 +407,7 @@ static int l_filldir(void *__buf, const char *name, int namlen, loff_t offset,
         if (!dirent)
                 return -ENOMEM;
 
-        list_add_tail(&dirent->lld_list, buf->lrc_list);
+        cfs_list_add_tail(&dirent->lld_list, buf->lrc_list);
 
         buf->lrc_dirent = dirent;
         dirent->lld_ino = ino;
@@ -418,7 +417,7 @@ static int l_filldir(void *__buf, const char *name, int namlen, loff_t offset,
         return 0;
 }
 
-long l_readdir(struct file *file, struct list_head *dentry_list)
+long l_readdir(struct file *file, cfs_list_t *dentry_list)
 {
         struct l_linux_dirent *lastdirent;
         struct l_readdir_callback buf;
@@ -440,18 +439,18 @@ long l_readdir(struct file *file, struct list_head *dentry_list)
 EXPORT_SYMBOL(l_readdir);
 
 int l_notify_change(struct vfsmount *mnt, struct dentry *dchild,
-                 struct iattr *newattrs)
+                   struct iattr *newattrs)
 {
-        int rc;
+       int rc;
 
-        LOCK_INODE_MUTEX(dchild->d_inode);
+       mutex_lock(&dchild->d_inode->i_mutex);
 #ifdef HAVE_SECURITY_PLUG
-        rc = notify_change(dchild, mnt, newattrs);
+       rc = notify_change(dchild, mnt, newattrs);
 #else
-        rc = notify_change(dchild, newattrs);
+       rc = notify_change(dchild, newattrs);
 #endif
-        UNLOCK_INODE_MUTEX(dchild->d_inode);
-        return rc;
+       mutex_unlock(&dchild->d_inode->i_mutex);
+       return rc;
 }
 EXPORT_SYMBOL(l_notify_change);
 
@@ -491,15 +490,9 @@ out:
 }
 EXPORT_SYMBOL(simple_truncate);
 
-#ifdef LUSTRE_KERNEL_VERSION
-#ifndef HAVE_CLEAR_RDONLY_ON_PUT
-#error rdonly patchset must be updated [cfs bz11248]
-#endif
-void dev_set_rdonly(lvfs_sbdev_type dev);
-int dev_check_rdonly(lvfs_sbdev_type dev);
-
-void __lvfs_set_rdonly(lvfs_sbdev_type dev, lvfs_sbdev_type jdev)
+int __lvfs_set_rdonly(lvfs_sbdev_type dev, lvfs_sbdev_type jdev)
 {
+#ifdef HAVE_DEV_SET_RDONLY
         if (jdev && (jdev != dev)) {
                 CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n",
                        (long)jdev);
@@ -507,14 +500,24 @@ void __lvfs_set_rdonly(lvfs_sbdev_type dev, lvfs_sbdev_type jdev)
         }
         CDEBUG(D_IOCTL | D_HA, "set dev %lx rdonly\n", (long)dev);
         dev_set_rdonly(dev);
+
+        return 0;
+#else
+        CERROR("DEV %lx CANNOT BE SET READONLY\n", (long)dev);
+
+        return -EOPNOTSUPP;
+#endif
 }
+EXPORT_SYMBOL(__lvfs_set_rdonly);
 
 int lvfs_check_rdonly(lvfs_sbdev_type dev)
 {
+#ifdef HAVE_DEV_SET_RDONLY
         return dev_check_rdonly(dev);
+#else
+        return 0;
+#endif
 }
-
-EXPORT_SYMBOL(__lvfs_set_rdonly);
 EXPORT_SYMBOL(lvfs_check_rdonly);
 
 int lvfs_check_io_health(struct obd_device *obd, struct file *file)
@@ -536,92 +539,84 @@ int lvfs_check_io_health(struct obd_device *obd, struct file *file)
         RETURN(rc);
 }
 EXPORT_SYMBOL(lvfs_check_io_health);
-#endif /* LUSTRE_KERNEL_VERSION */
 
 void obd_update_maxusage()
 {
-        __u64 max1, max2;
+       __u64 max1, max2;
 
-        max1 = obd_pages_sum();
-        max2 = obd_memory_sum();
+       max1 = obd_pages_sum();
+       max2 = obd_memory_sum();
 
-        spin_lock(&obd_updatemax_lock);
-        if (max1 > obd_max_pages)
-                obd_max_pages = max1;
-        if (max2 > obd_max_alloc)
-                obd_max_alloc = max2;
-        spin_unlock(&obd_updatemax_lock);
+       spin_lock(&obd_updatemax_lock);
+       if (max1 > obd_max_pages)
+               obd_max_pages = max1;
+       if (max2 > obd_max_alloc)
+               obd_max_alloc = max2;
+       spin_unlock(&obd_updatemax_lock);
 
 }
+EXPORT_SYMBOL(obd_update_maxusage);
 
 __u64 obd_memory_max(void)
 {
-        __u64 ret;
+       __u64 ret;
 
-        spin_lock(&obd_updatemax_lock);
-        ret = obd_max_alloc;
-        spin_unlock(&obd_updatemax_lock);
+       spin_lock(&obd_updatemax_lock);
+       ret = obd_max_alloc;
+       spin_unlock(&obd_updatemax_lock);
 
-        return ret;
+       return ret;
 }
+EXPORT_SYMBOL(obd_memory_max);
 
 __u64 obd_pages_max(void)
 {
-        __u64 ret;
+       __u64 ret;
 
-        spin_lock(&obd_updatemax_lock);
-        ret = obd_max_pages;
-        spin_unlock(&obd_updatemax_lock);
+       spin_lock(&obd_updatemax_lock);
+       ret = obd_max_pages;
+       spin_unlock(&obd_updatemax_lock);
 
-        return ret;
+       return ret;
 }
-
-EXPORT_SYMBOL(obd_update_maxusage);
 EXPORT_SYMBOL(obd_pages_max);
-EXPORT_SYMBOL(obd_memory_max);
-EXPORT_SYMBOL(obd_memory);
 
 #ifdef LPROCFS
 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
                           enum lprocfs_fields_flags field)
 {
-        __s64 ret = 0;
-        int centry;
-
-        if (!lc)
-                RETURN(0);
-        do {
-                centry = atomic_read(&lc->lc_cntl.la_entry);
-
-                switch (field) {
-                        case LPROCFS_FIELDS_FLAGS_CONFIG:
-                                ret = lc->lc_config;
-                                break;
-                        case LPROCFS_FIELDS_FLAGS_SUM:
-                                ret = lc->lc_sum + lc->lc_sum_irq;
-                                break;
-                        case LPROCFS_FIELDS_FLAGS_MIN:
-                                ret = lc->lc_min;
-                                break;
-                        case LPROCFS_FIELDS_FLAGS_MAX:
-                                ret = lc->lc_max;
-                                break;
-                        case LPROCFS_FIELDS_FLAGS_AVG:
-                                ret = (lc->lc_max - lc->lc_min)/2;
-                                break;
-                        case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
-                                ret = lc->lc_sumsquare;
-                                break;
-                        case LPROCFS_FIELDS_FLAGS_COUNT:
-                                ret = lc->lc_count;
-                                break;
-                        default:
-                                break;
-                };
-        } while (centry != atomic_read(&lc->lc_cntl.la_entry) &&
-                 centry != atomic_read(&lc->lc_cntl.la_exit));
-
-        RETURN(ret);
+       __s64 ret = 0;
+
+       if (lc == NULL)
+               RETURN(0);
+
+       switch (field) {
+               case LPROCFS_FIELDS_FLAGS_CONFIG:
+                       ret = lc->lc_config;
+                       break;
+               case LPROCFS_FIELDS_FLAGS_SUM:
+                       ret = lc->lc_sum + lc->lc_sum_irq;
+                       break;
+               case LPROCFS_FIELDS_FLAGS_MIN:
+                       ret = lc->lc_min;
+                       break;
+               case LPROCFS_FIELDS_FLAGS_MAX:
+                       ret = lc->lc_max;
+                       break;
+               case LPROCFS_FIELDS_FLAGS_AVG:
+                       ret = (lc->lc_max - lc->lc_min) / 2;
+                       break;
+               case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
+                       ret = lc->lc_sumsquare;
+                       break;
+               case LPROCFS_FIELDS_FLAGS_COUNT:
+                       ret = lc->lc_count;
+                       break;
+               default:
+                       break;
+       };
+
+       RETURN(ret);
 }
 EXPORT_SYMBOL(lprocfs_read_helper);
 #endif /* LPROCFS */