Whamcloud - gitweb
LU-1337 llite: kernel 3.1 renames lock-manager ops
[fs/lustre-release.git] / lustre / llite / file.c
index 4d4d201..d03ec76 100644 (file)
 
 struct ll_file_data *ll_file_data_get(void)
 {
-        struct ll_file_data *fd;
+       struct ll_file_data *fd;
 
-        OBD_SLAB_ALLOC_PTR_GFP(fd, ll_file_data_slab, CFS_ALLOC_IO);
-        return fd;
+       OBD_SLAB_ALLOC_PTR_GFP(fd, ll_file_data_slab, CFS_ALLOC_IO);
+       fd->fd_write_failed = false;
+       return fd;
 }
 
 static void ll_file_data_put(struct ll_file_data *fd)
@@ -372,6 +373,7 @@ static int ll_intent_file_open(struct file *file, void *lmm,
         if (IS_ERR(op_data))
                 RETURN(PTR_ERR(op_data));
 
+       itp->it_flags |= MDS_OPEN_BY_FID;
         rc = md_intent_lock(sbi->ll_md_exp, op_data, lmm, lmmsize, itp,
                             0 /*unused */, &req, ll_md_blocking_ast, 0);
         ll_finish_md_op_data(op_data);
@@ -824,11 +826,13 @@ void ll_io_init(struct cl_io *io, const struct file *file, int write)
         }
 }
 
-static ssize_t ll_file_io_generic(const struct lu_env *env,
-                struct vvp_io_args *args, struct file *file,
-                enum cl_io_type iot, loff_t *ppos, size_t count)
+static ssize_t
+ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
+                  struct file *file, enum cl_io_type iot,
+                  loff_t *ppos, size_t count)
 {
-        struct ll_inode_info *lli = ll_i2info(file->f_dentry->d_inode);
+       struct ll_inode_info *lli = ll_i2info(file->f_dentry->d_inode);
+       struct ll_file_data  *fd  = LUSTRE_FPRIVATE(file);
         struct cl_io         *io;
         ssize_t               result;
         ENTRY;
@@ -900,13 +904,13 @@ out:
                 if (result >= 0) {
                         ll_stats_ops_tally(ll_i2sbi(file->f_dentry->d_inode),
                                            LPROC_LL_WRITE_BYTES, result);
-                        lli->lli_write_rc = 0;
-                } else {
-                        lli->lli_write_rc = result;
-                }
-        }
+                       fd->fd_write_failed = false;
+               } else {
+                       fd->fd_write_failed = true;
+               }
+       }
 
-        return result;
+       return result;
 }
 
 
@@ -1674,12 +1678,17 @@ out:
        RETURN(rc);
 }
 
-int ll_fid2path(struct obd_export *exp, void *arg)
+int ll_fid2path(struct inode *inode, void *arg)
 {
+       struct obd_export *exp = ll_i2mdexp(inode);
         struct getinfo_fid2path *gfout, *gfin;
         int outsize, rc;
         ENTRY;
 
+       if (!cfs_capable(CFS_CAP_DAC_READ_SEARCH) &&
+           !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
+               RETURN(-EPERM);
+
         /* Need to get the buflen */
         OBD_ALLOC_PTR(gfin);
         if (gfin == NULL)
@@ -1891,7 +1900,7 @@ long ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                 RETURN(0);
         }
         case OBD_IOC_FID2PATH:
-                RETURN(ll_fid2path(ll_i2mdexp(inode), (void *)arg));
+               RETURN(ll_fid2path(inode, (void *)arg));
         case LL_IOC_DATA_VERSION: {
                 struct ioc_data_version idv;
                 int rc;
@@ -1974,24 +1983,25 @@ loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
 
 int ll_flush(struct file *file, fl_owner_t id)
 {
-        struct inode *inode = file->f_dentry->d_inode;
-        struct ll_inode_info *lli = ll_i2info(inode);
-        int rc, err;
-
-        LASSERT(!S_ISDIR(inode->i_mode));
+       struct inode *inode = file->f_dentry->d_inode;
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
+       int rc, err;
 
-        /* the application should know write failure already. */
-        if (lli->lli_write_rc)
-                return 0;
+       LASSERT(!S_ISDIR(inode->i_mode));
 
-        /* catch async errors that were recorded back when async writeback
-         * failed for pages in this mapping. */
-        rc = lli->lli_async_rc;
-        lli->lli_async_rc = 0;
+       /* catch async errors that were recorded back when async writeback
+        * failed for pages in this mapping. */
+       rc = lli->lli_async_rc;
+       lli->lli_async_rc = 0;
        err = lov_read_and_clear_async_rc(lli->lli_clob);
        if (rc == 0)
                rc = err;
 
+       /* The application has been told write failure already.
+        * Do not report failure again. */
+       if (fd->fd_write_failed)
+               return 0;
        return rc ? -EIO : 0;
 }
 
@@ -2095,11 +2105,16 @@ int ll_fsync(struct file *file, struct dentry *dentry, int data)
 
        lsm = ccc_inode_lsm_get(inode);
        if (data && lsm) {
+               struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
+
                err = cl_sync_file_range(inode, 0, OBD_OBJECT_EOF,
                                CL_FSYNC_ALL);
                if (rc == 0 && err < 0)
                        rc = err;
-               lli->lli_write_rc = rc < 0 ? rc : 0;
+               if (rc < 0)
+                       fd->fd_write_failed = true;
+               else
+                       fd->fd_write_failed = false;
        }
        ccc_inode_lsm_put(inode, lsm);
 
@@ -2140,15 +2155,15 @@ int ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
         }
         flock.l_flock.pid = file_lock->fl_pid;
 
-        /* Somewhat ugly workaround for svc lockd.
-         * lockd installs custom fl_lmops->fl_compare_owner that checks
-         * for the fl_owner to be the same (which it always is on local node
-         * I guess between lockd processes) and then compares pid.
-         * As such we assign pid to the owner field to make it all work,
-         * conflict with normal locks is unlikely since pid space and
-         * pointer space for current->files are not intersecting */
-        if (file_lock->fl_lmops && file_lock->fl_lmops->fl_compare_owner)
-                flock.l_flock.owner = (unsigned long)file_lock->fl_pid;
+       /* Somewhat ugly workaround for svc lockd.
+        * lockd installs custom fl_lmops->lm_compare_owner that checks
+        * for the fl_owner to be the same (which it always is on local node
+        * I guess between lockd processes) and then compares pid.
+        * As such we assign pid to the owner field to make it all work,
+        * conflict with normal locks is unlikely since pid space and
+        * pointer space for current->files are not intersecting */
+       if (file_lock->fl_lmops && file_lock->fl_lmops->lm_compare_owner)
+               flock.l_flock.owner = (unsigned long)file_lock->fl_pid;
 
         switch (file_lock->fl_type) {
         case F_RDLCK:
@@ -2477,11 +2492,7 @@ int ll_getattr_it(struct vfsmount *mnt, struct dentry *de,
         stat->atime = inode->i_atime;
         stat->mtime = inode->i_mtime;
         stat->ctime = inode->i_ctime;
-#ifdef HAVE_INODE_BLKSIZE
-        stat->blksize = inode->i_blksize;
-#else
-        stat->blksize = 1 << inode->i_blkbits;
-#endif
+       stat->blksize = 1 << inode->i_blkbits;
 
         stat->size = i_size_read(inode);
         stat->blocks = inode->i_blocks;
@@ -2530,39 +2541,40 @@ int ll_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 }
 #endif
 
-
+#ifndef HAVE_GENERIC_PERMISSION_2ARGS
 static int
-#ifdef HAVE_GENERIC_PERMISSION_4ARGS
+# ifdef HAVE_GENERIC_PERMISSION_4ARGS
 lustre_check_acl(struct inode *inode, int mask, unsigned int flags)
-#else
+# else
 lustre_check_acl(struct inode *inode, int mask)
-#endif
+# endif
 {
-#ifdef CONFIG_FS_POSIX_ACL
-        struct ll_inode_info *lli = ll_i2info(inode);
-        struct posix_acl *acl;
-        int rc;
-        ENTRY;
+# ifdef CONFIG_FS_POSIX_ACL
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct posix_acl *acl;
+       int rc;
+       ENTRY;
 
-#ifdef HAVE_GENERIC_PERMISSION_4ARGS
-        if (flags & IPERM_FLAG_RCU)
-                return -ECHILD;
-#endif
-        cfs_spin_lock(&lli->lli_lock);
-        acl = posix_acl_dup(lli->lli_posix_acl);
-        cfs_spin_unlock(&lli->lli_lock);
+#  ifdef HAVE_GENERIC_PERMISSION_4ARGS
+       if (flags & IPERM_FLAG_RCU)
+               return -ECHILD;
+#  endif
+       cfs_spin_lock(&lli->lli_lock);
+       acl = posix_acl_dup(lli->lli_posix_acl);
+       cfs_spin_unlock(&lli->lli_lock);
 
-        if (!acl)
-                RETURN(-EAGAIN);
+       if (!acl)
+               RETURN(-EAGAIN);
 
-        rc = posix_acl_permission(inode, acl, mask);
-        posix_acl_release(acl);
+       rc = posix_acl_permission(inode, acl, mask);
+       posix_acl_release(acl);
 
-        RETURN(rc);
-#else
-        return -EAGAIN;
-#endif
+       RETURN(rc);
+# else /* !CONFIG_FS_POSIX_ACL */
+       return -EAGAIN;
+# endif /* CONFIG_FS_POSIX_ACL */
 }
+#endif /* HAVE_GENERIC_PERMISSION_2ARGS */
 
 #ifdef HAVE_GENERIC_PERMISSION_4ARGS
 int ll_inode_permission(struct inode *inode, int mask, unsigned int flags)