Whamcloud - gitweb
LU-1337 llite: ll_inode_permission should check RCU walk
[fs/lustre-release.git] / lustre / llite / file.c
index 4f7385c..e43dfb5 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)
@@ -825,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;
@@ -901,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;
 }
 
 
@@ -1675,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)
@@ -1892,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;
@@ -1975,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;
 }
 
@@ -2069,9 +2078,14 @@ int ll_fsync(struct file *file, struct dentry *dentry, int data)
                inode->i_generation, inode);
         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_FSYNC, 1);
 
+#ifdef HAVE_FILE_FSYNC_4ARGS
+       rc = filemap_write_and_wait_range(inode->i_mapping, start, end);
+       mutex_lock(&inode->i_mutex);
+#else
         /* fsync's caller has already called _fdata{sync,write}, we want
          * that IO to finish before calling the osc and mdc sync methods */
         rc = filemap_fdatawait(inode->i_mapping);
+#endif
 
         /* catch async errors that were recorded back when async writeback
          * failed for pages in this mapping. */
@@ -2096,14 +2110,22 @@ 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);
 
+#ifdef HAVE_FILE_FSYNC_4ARGS
+       mutex_unlock(&inode->i_mutex);
+#endif
        RETURN(rc);
 }
 
@@ -2141,15 +2163,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:
@@ -2474,7 +2496,7 @@ int ll_getattr_it(struct vfsmount *mnt, struct dentry *de,
         stat->nlink = inode->i_nlink;
         stat->uid = inode->i_uid;
         stat->gid = inode->i_gid;
-        stat->rdev = kdev_t_to_nr(inode->i_rdev);
+       stat->rdev = inode->i_rdev;
         stat->atime = inode->i_atime;
         stat->mtime = inode->i_mtime;
         stat->ctime = inode->i_ctime;
@@ -2575,7 +2597,10 @@ int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd)
         int rc = 0;
         ENTRY;
 
-#ifdef HAVE_GENERIC_PERMISSION_4ARGS
+#ifdef MAY_NOT_BLOCK
+       if (mask & MAY_NOT_BLOCK)
+               return -ECHILD;
+#elif defined(HAVE_GENERIC_PERMISSION_4ARGS)
        if (flags & IPERM_FLAG_RCU)
                return -ECHILD;
 #endif