Whamcloud - gitweb
b=19387 integrate LST into acc-sm
[fs/lustre-release.git] / lustre / lvfs / lvfs_linux.c
index 5d07875..7e01051 100644 (file)
@@ -67,7 +67,7 @@
 __u64 obd_max_pages = 0;
 __u64 obd_max_alloc = 0;
 struct lprocfs_stats *obd_memory = NULL;
-spinlock_t obd_updatemax_lock = SPIN_LOCK_UNLOCKED;
+cfs_spinlock_t obd_updatemax_lock = CFS_SPIN_LOCK_UNLOCKED;
 /* refine later and change to seqlock or simlar from libcfs */
 
 /* Debugging check only needed during development */
@@ -117,10 +117,10 @@ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
         OBD_SET_CTXT_MAGIC(save);
 
         save->fs = get_fs();
-        LASSERT(atomic_read(&current->fs->pwd->d_count));
-        LASSERT(atomic_read(&new_ctx->pwd->d_count));
-        save->pwd = dget(current->fs->pwd);
-        save->pwdmnt = mntget(current->fs->pwdmnt);
+        LASSERT(cfs_atomic_read(&cfs_fs_pwd(current->fs)->d_count));
+        LASSERT(cfs_atomic_read(&new_ctx->pwd->d_count));
+        save->pwd = dget(cfs_fs_pwd(current->fs));
+        save->pwdmnt = mntget(cfs_fs_mnt(current->fs));
         save->luc.luc_umask = current->fs->umask;
         save->ngroups = current->group_info->ngroups;
 
@@ -159,10 +159,10 @@ void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,
         ASSERT_CTXT_MAGIC(saved->magic);
         ASSERT_KERNEL_CTXT("popping non-kernel context!\n");
 
-        LASSERTF(current->fs->pwd == new_ctx->pwd, "%p != %p\n",
-                 current->fs->pwd, new_ctx->pwd);
-        LASSERTF(current->fs->pwdmnt == new_ctx->pwdmnt, "%p != %p\n",
-                 current->fs->pwdmnt, new_ctx->pwdmnt);
+        LASSERTF(cfs_fs_pwd(current->fs) == new_ctx->pwd, "%p != %p\n",
+                 cfs_fs_pwd(current->fs), new_ctx->pwd);
+        LASSERTF(cfs_fs_mnt(current->fs) == new_ctx->pwdmnt, "%p != %p\n",
+                 cfs_fs_mnt(current->fs), new_ctx->pwdmnt);
 
         set_fs(saved->fs);
         ll_set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
@@ -362,6 +362,7 @@ int lustre_fsync(struct file *file)
 }
 EXPORT_SYMBOL(lustre_fsync);
 
+/* Note: dput(dchild) will be called if there is an error */
 struct l_file *l_dentry_open(struct lvfs_run_ctxt *ctxt, struct l_dentry *de,
                              int flags)
 {
@@ -390,7 +391,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;
@@ -400,7 +401,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;
@@ -421,6 +422,58 @@ 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)
+{
+        int rc;
+
+        LOCK_INODE_MUTEX(dchild->d_inode);
+#ifdef HAVE_SECURITY_PLUG
+        rc = notify_change(dchild, mnt, newattrs);
+#else
+        rc = notify_change(dchild, newattrs);
+#endif
+        UNLOCK_INODE_MUTEX(dchild->d_inode);
+        return rc;
+}
+EXPORT_SYMBOL(l_notify_change);
+
+/* utility to truncate a file */
+int simple_truncate(struct dentry *dir, struct vfsmount *mnt, 
+                 char *name, loff_t length)
+{
+        struct dentry *dchild;
+        struct iattr newattrs;
+        int err = 0;
+        ENTRY;
+
+        CDEBUG(D_INODE, "truncating file %.*s to %lld\n", (int)strlen(name),
+               name, (long long)length);
+        dchild = ll_lookup_one_len(name, dir, strlen(name));
+        if (IS_ERR(dchild))
+                GOTO(out, err = PTR_ERR(dchild));
+
+        if (dchild->d_inode) {
+                int old_mode = dchild->d_inode->i_mode;
+                if (S_ISDIR(old_mode)) {
+                        CERROR("found %s (%lu/%u) is mode %o\n", name,
+                               dchild->d_inode->i_ino,
+                               dchild->d_inode->i_generation, old_mode);
+                        GOTO(out_dput, err = -EISDIR);
+                }
+
+                newattrs.ia_size = length;
+                newattrs.ia_valid = ATTR_SIZE;
+                err = l_notify_change(mnt, dchild, &newattrs);
+        }
+        EXIT;
+out_dput:
+        dput(dchild);
+out:
+        return err;
+}
+EXPORT_SYMBOL(simple_truncate);
+
 #ifdef LUSTRE_KERNEL_VERSION
 #ifndef HAVE_CLEAR_RDONLY_ON_PUT
 #error rdonly patchset must be updated [cfs bz11248]
@@ -475,12 +528,12 @@ void obd_update_maxusage()
         max1 = obd_pages_sum();
         max2 = obd_memory_sum();
 
-        spin_lock(&obd_updatemax_lock);
+        cfs_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);
+        cfs_spin_unlock(&obd_updatemax_lock);
 
 }
 
@@ -488,9 +541,9 @@ __u64 obd_memory_max(void)
 {
         __u64 ret;
 
-        spin_lock(&obd_updatemax_lock);
+        cfs_spin_lock(&obd_updatemax_lock);
         ret = obd_max_alloc;
-        spin_unlock(&obd_updatemax_lock);
+        cfs_spin_unlock(&obd_updatemax_lock);
 
         return ret;
 }
@@ -499,9 +552,9 @@ __u64 obd_pages_max(void)
 {
         __u64 ret;
 
-        spin_lock(&obd_updatemax_lock);
+        cfs_spin_lock(&obd_updatemax_lock);
         ret = obd_max_pages;
-        spin_unlock(&obd_updatemax_lock);
+        cfs_spin_unlock(&obd_updatemax_lock);
 
         return ret;
 }
@@ -521,14 +574,14 @@ __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
         if (!lc)
                 RETURN(0);
         do {
-                centry = atomic_read(&lc->lc_cntl.la_entry);
+                centry = cfs_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;
+                                ret = lc->lc_sum + lc->lc_sum_irq;
                                 break;
                         case LPROCFS_FIELDS_FLAGS_MIN:
                                 ret = lc->lc_min;
@@ -548,8 +601,8 @@ __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
                         default:
                                 break;
                 };
-        } while (centry != atomic_read(&lc->lc_cntl.la_entry) &&
-                 centry != atomic_read(&lc->lc_cntl.la_exit));
+        } while (centry != cfs_atomic_read(&lc->lc_cntl.la_entry) &&
+                 centry != cfs_atomic_read(&lc->lc_cntl.la_exit));
 
         RETURN(ret);
 }