Whamcloud - gitweb
branch: HEAD
[fs/lustre-release.git] / lustre / lvfs / lvfs_linux.c
index 8dbf9e1..1b4ab82 100644 (file)
@@ -116,17 +116,6 @@ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
         ASSERT_CTXT_MAGIC(new_ctx->magic);
         OBD_SET_CTXT_MAGIC(save);
 
-        /*
-        CDEBUG(D_INFO,
-               "= push %p->%p = cur fs %p pwd %p:d%d:i%d (%.*s), pwdmnt %p:%d\n",
-               save, current, current->fs, current->fs->pwd,
-               atomic_read(&current->fs->pwd->d_count),
-               atomic_read(&current->fs->pwd->d_inode->i_count),
-               current->fs->pwd->d_name.len, current->fs->pwd->d_name.name,
-               current->fs->pwdmnt,
-               atomic_read(&current->fs->pwdmnt->mnt_count));
-        */
-
         save->fs = get_fs();
         LASSERT(atomic_read(&current->fs->pwd->d_count));
         LASSERT(atomic_read(&new_ctx->pwd->d_count));
@@ -161,39 +150,15 @@ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
         current->fs->umask = 0; /* umask already applied on client */
         set_fs(new_ctx->fs);
         ll_set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd);
-
-        /*
-        CDEBUG(D_INFO,
-               "= push %p->%p = cur fs %p pwd %p:d%d:i%d (%.*s), pwdmnt %p:%d\n",
-               new_ctx, current, current->fs, current->fs->pwd,
-               atomic_read(&current->fs->pwd->d_count),
-               atomic_read(&current->fs->pwd->d_inode->i_count),
-               current->fs->pwd->d_name.len, current->fs->pwd->d_name.name,
-               current->fs->pwdmnt,
-               atomic_read(&current->fs->pwdmnt->mnt_count));
-        */
 }
 EXPORT_SYMBOL(push_ctxt);
 
 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,
               struct lvfs_ucred *uc)
 {
-        //printk("pc0");
         ASSERT_CTXT_MAGIC(saved->magic);
-        //printk("pc1");
         ASSERT_KERNEL_CTXT("popping non-kernel context!\n");
 
-        /*
-        CDEBUG(D_INFO,
-               " = pop  %p==%p = cur %p pwd %p:d%d:i%d (%.*s), pwdmnt %p:%d\n",
-               new_ctx, current, current->fs, current->fs->pwd,
-               atomic_read(&current->fs->pwd->d_count),
-               atomic_read(&current->fs->pwd->d_inode->i_count),
-               current->fs->pwd->d_name.len, current->fs->pwd->d_name.name,
-               current->fs->pwdmnt,
-               atomic_read(&current->fs->pwdmnt->mnt_count));
-        */
-
         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",
@@ -216,17 +181,6 @@ void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,
                                uc->luc_identity ? uc->luc_identity->mi_ginfo :
                                                   NULL);
         }
-
-        /*
-        CDEBUG(D_INFO,
-               "= pop  %p->%p = cur fs %p pwd %p:d%d:i%d (%.*s), pwdmnt %p:%d\n",
-               saved, current, current->fs, current->fs->pwd,
-               atomic_read(&current->fs->pwd->d_count),
-               atomic_read(&current->fs->pwd->d_inode->i_count),
-               current->fs->pwd->d_name.len, current->fs->pwd->d_name.name,
-               current->fs->pwdmnt,
-               atomic_read(&current->fs->pwdmnt->mnt_count));
-        */
 }
 EXPORT_SYMBOL(pop_ctxt);
 
@@ -277,7 +231,7 @@ EXPORT_SYMBOL(simple_mknod);
 
 /* utility to make a directory */
 struct dentry *simple_mkdir(struct dentry *dir, struct vfsmount *mnt, 
-                            char *name, int mode, int fix)
+                            const char *name, int mode, int fix)
 {
         struct dentry *dchild;
         int err = 0;
@@ -300,7 +254,7 @@ struct dentry *simple_mkdir(struct dentry *dir, struct vfsmount *mnt,
 
                 /* Fixup directory permissions if necessary */
                 if (fix && (old_mode & S_IALLUGO) != (mode & S_IALLUGO)) {
-                        CDEBUG(D_CONFIG, 
+                        CDEBUG(D_CONFIG,
                                "fixing permissions on %s from %o to %o\n",
                                name, old_mode, mode);
                         dchild->d_inode->i_mode = (mode & S_IALLUGO) |
@@ -325,7 +279,7 @@ out_up:
 EXPORT_SYMBOL(simple_mkdir);
 
 /* utility to rename a file */
-int lustre_rename(struct dentry *dir, struct vfsmount *mnt, 
+int lustre_rename(struct dentry *dir, struct vfsmount *mnt,
                   char *oldname, char *newname)
 {
         struct dentry *dchild_old, *dchild_new;
@@ -333,21 +287,21 @@ int lustre_rename(struct dentry *dir, struct vfsmount *mnt,
         ENTRY;
 
         ASSERT_KERNEL_CTXT("kernel doing rename outside kernel context\n");
-        CDEBUG(D_INODE, "renaming file %.*s to %.*s\n", 
+        CDEBUG(D_INODE, "renaming file %.*s to %.*s\n",
                (int)strlen(oldname), oldname, (int)strlen(newname), newname);
 
         dchild_old = ll_lookup_one_len(oldname, dir, strlen(oldname));
         if (IS_ERR(dchild_old))
                 RETURN(PTR_ERR(dchild_old));
 
-        if (!dchild_old->d_inode) 
+        if (!dchild_old->d_inode)
                 GOTO(put_old, err = -ENOENT);
 
         dchild_new = ll_lookup_one_len(newname, dir, strlen(newname));
         if (IS_ERR(dchild_new))
                 GOTO(put_old, err = PTR_ERR(dchild_new));
 
-        err = ll_vfs_rename(dir->d_inode, dchild_old, mnt, 
+        err = ll_vfs_rename(dir->d_inode, dchild_old, mnt,
                             dir->d_inode, dchild_new, mnt);
 
         dput(dchild_new);
@@ -408,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)
 {
@@ -467,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]
@@ -476,7 +483,6 @@ int dev_check_rdonly(lvfs_sbdev_type dev);
 
 void __lvfs_set_rdonly(lvfs_sbdev_type dev, lvfs_sbdev_type jdev)
 {
-        lvfs_sbdev_sync(dev);
         if (jdev && (jdev != dev)) {
                 CDEBUG(D_IOCTL | D_HA, "set journal dev %lx rdonly\n",
                        (long)jdev);
@@ -528,7 +534,7 @@ void obd_update_maxusage()
         if (max2 > obd_max_alloc)
                 obd_max_alloc = max2;
         spin_unlock(&obd_updatemax_lock);
-        
+
 }
 
 __u64 obd_memory_max(void)
@@ -575,7 +581,7 @@ __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
                                 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;