Whamcloud - gitweb
LU-6215 llite: handle removal of ki_nbytes in struct kiocb
[fs/lustre-release.git] / lustre / llite / file.c
index fbc255c..8b54068 100644 (file)
@@ -99,7 +99,6 @@ void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
        op_data->op_attr_flags = ll_inode_to_ext_flags(inode->i_flags);
         if (fh)
                 op_data->op_handle = *fh;
-        op_data->op_capa1 = ll_mdscapa_get(inode);
 
        if (LLIF_DATA_MODIFIED & ll_i2info(inode)->lli_flags)
                op_data->op_bias |= MDS_DATA_MODIFIED;
@@ -273,10 +272,16 @@ int ll_md_real_close(struct inode *inode, fmode_t fmode)
 static int ll_md_close(struct obd_export *md_exp, struct inode *inode,
                       struct file *file)
 {
-        struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
-        struct ll_inode_info *lli = ll_i2info(inode);
-        int rc = 0;
-        ENTRY;
+       ldlm_policy_data_t policy = {
+               .l_inodebits    = { MDS_INODELOCK_OPEN },
+       };
+       __u64 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_TEST_LOCK;
+       struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct lustre_handle lockh;
+       int lockmode;
+       int rc = 0;
+       ENTRY;
 
        /* clear group lock, if present */
        if (unlikely(fd->fd_flags & LL_FILE_GROUP_LOCKED))
@@ -303,45 +308,29 @@ static int ll_md_close(struct obd_export *md_exp, struct inode *inode,
 
         /* Let's see if we have good enough OPEN lock on the file and if
            we can skip talking to MDS */
-        if (file->f_dentry->d_inode) { /* Can this ever be false? */
-                int lockmode;
-               __u64 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_TEST_LOCK;
-                struct lustre_handle lockh;
-                struct inode *inode = file->f_dentry->d_inode;
-                ldlm_policy_data_t policy = {.l_inodebits={MDS_INODELOCK_OPEN}};
-
-               mutex_lock(&lli->lli_och_mutex);
-                if (fd->fd_omode & FMODE_WRITE) {
-                        lockmode = LCK_CW;
-                        LASSERT(lli->lli_open_fd_write_count);
-                        lli->lli_open_fd_write_count--;
-                } else if (fd->fd_omode & FMODE_EXEC) {
-                        lockmode = LCK_PR;
-                        LASSERT(lli->lli_open_fd_exec_count);
-                        lli->lli_open_fd_exec_count--;
-                } else {
-                        lockmode = LCK_CR;
-                        LASSERT(lli->lli_open_fd_read_count);
-                        lli->lli_open_fd_read_count--;
-                }
-               mutex_unlock(&lli->lli_och_mutex);
-
-                if (!md_lock_match(md_exp, flags, ll_inode2fid(inode),
-                                   LDLM_IBITS, &policy, lockmode,
-                                   &lockh)) {
-                        rc = ll_md_real_close(file->f_dentry->d_inode,
-                                              fd->fd_omode);
-                }
+       mutex_lock(&lli->lli_och_mutex);
+       if (fd->fd_omode & FMODE_WRITE) {
+               lockmode = LCK_CW;
+               LASSERT(lli->lli_open_fd_write_count);
+               lli->lli_open_fd_write_count--;
+       } else if (fd->fd_omode & FMODE_EXEC) {
+               lockmode = LCK_PR;
+               LASSERT(lli->lli_open_fd_exec_count);
+               lli->lli_open_fd_exec_count--;
        } else {
-               CERROR("released file has negative dentry: file = %p, "
-                      "dentry = %p, name = %s\n",
-                      file, file->f_dentry, file->f_dentry->d_name.name);
+               lockmode = LCK_CR;
+               LASSERT(lli->lli_open_fd_read_count);
+               lli->lli_open_fd_read_count--;
        }
+       mutex_unlock(&lli->lli_och_mutex);
+
+       if (!md_lock_match(md_exp, flags, ll_inode2fid(inode),
+                          LDLM_IBITS, &policy, lockmode, &lockh))
+               rc = ll_md_real_close(inode, fd->fd_omode);
 
 out:
        LUSTRE_FPRIVATE(file) = NULL;
        ll_file_data_put(fd);
-       ll_capa_close(inode);
 
        RETURN(rc);
 }
@@ -376,7 +365,7 @@ int ll_file_release(struct inode *inode, struct file *file)
        }
 #endif
 
-        if (inode->i_sb->s_root != file->f_dentry)
+       if (inode->i_sb->s_root != file->f_path.dentry)
                 ll_stats_ops_tally(sbi, LPROC_LL_RELEASE, 1);
         fd = LUSTRE_FPRIVATE(file);
         LASSERT(fd != NULL);
@@ -386,7 +375,7 @@ int ll_file_release(struct inode *inode, struct file *file)
        if (S_ISDIR(inode->i_mode) && lli->lli_opendir_key == fd)
                ll_deauthorize_statahead(inode, fd);
 
-        if (inode->i_sb->s_root == file->f_dentry) {
+       if (inode->i_sb->s_root == file->f_path.dentry) {
                 LUSTRE_FPRIVATE(file) = NULL;
                 ll_file_data_put(fd);
                 RETURN(0);
@@ -409,7 +398,7 @@ int ll_file_release(struct inode *inode, struct file *file)
 static int ll_intent_file_open(struct file *file, void *lmm, int lmmsize,
                                struct lookup_intent *itp)
 {
-       struct dentry *de = file->f_dentry;
+       struct dentry *de = file->f_path.dentry;
        struct ll_sb_info *sbi = ll_i2sbi(de->d_inode);
        struct dentry *parent = de->d_parent;
        const char *name = NULL;
@@ -490,7 +479,7 @@ static int ll_och_fill(struct obd_export *md_exp, struct lookup_intent *it,
 static int ll_local_open(struct file *file, struct lookup_intent *it,
                         struct ll_file_data *fd, struct obd_client_handle *och)
 {
-       struct inode *inode = file->f_dentry->d_inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
        ENTRY;
 
        LASSERT(!LUSTRE_FPRIVATE(file));
@@ -554,7 +543,7 @@ int ll_file_open(struct inode *inode, struct file *file)
        if (S_ISDIR(inode->i_mode))
                ll_authorize_statahead(inode, fd);
 
-        if (inode->i_sb->s_root == file->f_dentry) {
+       if (inode->i_sb->s_root == file->f_path.dentry) {
                 LUSTRE_FPRIVATE(file) = fd;
                 RETURN(0);
         }
@@ -612,7 +601,7 @@ restart:
                                 GOTO(out_openerr, rc);
                         }
 
-                        ll_release_openhandle(file->f_dentry, it);
+                       ll_release_openhandle(file->f_path.dentry, it);
                 }
                 (*och_usecount)++;
 
@@ -682,8 +671,6 @@ restart:
         if (!S_ISREG(inode->i_mode))
                 GOTO(out_och_free, rc);
 
-        ll_capa_open(inode);
-
        cl_lov_delay_create_clear(&file->f_flags);
        GOTO(out_och_free, rc);
 
@@ -1056,7 +1043,7 @@ static bool file_is_noatime(const struct file *file)
 
 static void ll_io_init(struct cl_io *io, const struct file *file, int write)
 {
-        struct inode *inode = file->f_dentry->d_inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
 
         io->u.ci_rw.crw_nonblock = file->f_flags & O_NONBLOCK;
        if (write) {
@@ -1083,7 +1070,7 @@ ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
                   loff_t *ppos, size_t count)
 {
        struct vvp_io           *vio = vvp_env_io(env);
-       struct inode            *inode = file->f_dentry->d_inode;
+       struct inode            *inode = file->f_path.dentry->d_inode;
        struct ll_inode_info    *lli = ll_i2info(inode);
        struct ll_file_data     *fd  = LUSTRE_FPRIVATE(file);
        struct cl_io            *io;
@@ -1094,7 +1081,7 @@ ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
        ENTRY;
 
        CDEBUG(D_VFSTRACE, "file: %s, type: %d ppos: "LPU64", count: %zu\n",
-               file->f_dentry->d_name.name, iot, *ppos, count);
+               file->f_path.dentry->d_name.name, iot, *ppos, count);
 
 restart:
        io = vvp_env_thread_io(env);
@@ -1173,7 +1160,7 @@ out:
        if ((rc == 0 || rc == -ENODATA) && count > 0 && io->ci_need_restart) {
                CDEBUG(D_VFSTRACE,
                       "%s: restart %s from %lld, count:%zu, result: %zd\n",
-                      file->f_dentry->d_name.name,
+                      file->f_path.dentry->d_name.name,
                       iot == CIT_READ ? "read" : "write",
                       *ppos, count, result);
                goto restart;
@@ -1181,11 +1168,11 @@ out:
 
        if (iot == CIT_READ) {
                if (result > 0)
-                       ll_stats_ops_tally(ll_i2sbi(file->f_dentry->d_inode),
+                       ll_stats_ops_tally(ll_i2sbi(inode),
                                           LPROC_LL_READ_BYTES, result);
        } else if (iot == CIT_WRITE) {
                if (result > 0) {
-                       ll_stats_ops_tally(ll_i2sbi(file->f_dentry->d_inode),
+                       ll_stats_ops_tally(ll_i2sbi(inode),
                                           LPROC_LL_WRITE_BYTES, result);
                        fd->fd_write_failed = false;
                } else if (rc != -ERESTARTSYS) {
@@ -1295,9 +1282,9 @@ static ssize_t ll_file_read(struct file *file, char __user *buf, size_t count,
         init_sync_kiocb(kiocb, file);
         kiocb->ki_pos = *ppos;
 #ifdef HAVE_KIOCB_KI_LEFT
-        kiocb->ki_left = count;
-#else
-        kiocb->ki_nbytes = count;
+       kiocb->ki_left = count;
+#elif defined(HAVE_KI_NBYTES)
+       kiocb->ki_nbytes = count;
 #endif
 
        result = ll_file_aio_read(kiocb, &iov, 1, kiocb->ki_pos);
@@ -1377,9 +1364,9 @@ static ssize_t ll_file_write(struct file *file, const char __user *buf,
         init_sync_kiocb(kiocb, file);
         kiocb->ki_pos = *ppos;
 #ifdef HAVE_KIOCB_KI_LEFT
-        kiocb->ki_left = count;
-#else
-        kiocb->ki_nbytes = count;
+       kiocb->ki_left = count;
+#elif defined(HAVE_KI_NBYTES)
+       kiocb->ki_nbytes = count;
 #endif
 
        result = ll_file_aio_write(kiocb, &iov, 1, kiocb->ki_pos);
@@ -1431,7 +1418,7 @@ int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
        if (rc < 0)
                GOTO(out_unlock, rc);
 
-       ll_release_openhandle(file->f_dentry, &oit);
+       ll_release_openhandle(file->f_path.dentry, &oit);
 
 out_unlock:
        ll_inode_size_unlock(inode);
@@ -1950,8 +1937,8 @@ static int ll_swap_layouts(struct file *file1, struct file *file2,
        if (llss == NULL)
                RETURN(-ENOMEM);
 
-       llss->inode1 = file1->f_dentry->d_inode;
-       llss->inode2 = file2->f_dentry->d_inode;
+       llss->inode1 = file1->f_path.dentry->d_inode;
+       llss->inode2 = file2->f_path.dentry->d_inode;
 
        rc = ll_check_swap_layouts_validity(llss->inode1, llss->inode2);
        if (rc < 0)
@@ -2120,7 +2107,7 @@ static int ll_hsm_import(struct inode *inode, struct file *file,
 
        mutex_lock(&inode->i_mutex);
 
-       rc = ll_setattr_raw(file->f_dentry, attr, true);
+       rc = ll_setattr_raw(file->f_path.dentry, attr, true);
        if (rc == -ENODATA)
                rc = 0;
 
@@ -2145,7 +2132,7 @@ static inline long ll_lease_type_from_fmode(fmode_t fmode)
 static long
 ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
-       struct inode            *inode = file->f_dentry->d_inode;
+       struct inode            *inode = file->f_path.dentry->d_inode;
        struct ll_file_data     *fd = LUSTRE_FPRIVATE(file);
        int                      flags, rc;
        ENTRY;
@@ -2224,7 +2211,7 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        mutex_unlock(&lli->lli_och_mutex);
                        if (och == NULL)
                                GOTO(out, rc = -ENOLCK);
-                       inode2 = file2->f_dentry->d_inode;
+                       inode2 = file2->f_path.dentry->d_inode;
                        rc = ll_swap_layouts_close(och, inode, inode2);
                } else {
                        rc = ll_swap_layouts(file, file2, &lsl);
@@ -2507,7 +2494,7 @@ static loff_t
 generic_file_llseek_size(struct file *file, loff_t offset, int origin,
                 loff_t maxsize, loff_t eof)
 {
-       struct inode *inode = file->f_dentry->d_inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
 
        switch (origin) {
        case SEEK_END:
@@ -2556,7 +2543,7 @@ generic_file_llseek_size(struct file *file, loff_t offset, int origin,
 
 static loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
 {
-       struct inode *inode = file->f_dentry->d_inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
        loff_t retval, eof = 0;
 
        ENTRY;
@@ -2581,7 +2568,7 @@ static loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
 
 static int ll_flush(struct file *file, fl_owner_t id)
 {
-       struct inode *inode = file->f_dentry->d_inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
        struct ll_inode_info *lli = ll_i2info(inode);
        struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
        int rc, err;
@@ -2617,7 +2604,6 @@ int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
        struct cl_env_nest nest;
        struct lu_env *env;
        struct cl_io *io;
-       struct obd_capa *capa = NULL;
        struct cl_fsync_io *fio;
        int result;
        ENTRY;
@@ -2630,15 +2616,12 @@ int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
        if (IS_ERR(env))
                RETURN(PTR_ERR(env));
 
-       capa = ll_osscapa_get(inode, CAPA_OPC_OSS_WRITE);
-
        io = vvp_env_thread_io(env);
        io->ci_obj = ll_i2info(inode)->lli_clob;
        io->ci_ignore_layout = ignore_layout;
 
        /* initialize parameters for sync */
        fio = &io->u.ci_fsync;
-       fio->fi_capa = capa;
        fio->fi_start = start;
        fio->fi_end = end;
        fio->fi_fid = ll_inode2fid(inode);
@@ -2654,25 +2637,23 @@ int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
        cl_io_fini(env, io);
        cl_env_nested_put(&nest, env);
 
-       capa_put(capa);
-
        RETURN(result);
 }
 
 /*
- * When dentry is provided (the 'else' case), *file->f_dentry may be
+ * When dentry is provided (the 'else' case), *file->f_path.dentry may be
  * null and dentry must be used directly rather than pulled from
- * *file->f_dentry as is done otherwise.
+ * *file->f_path.dentry as is done otherwise.
  */
 
 #ifdef HAVE_FILE_FSYNC_4ARGS
 int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 {
-       struct dentry *dentry = file->f_dentry;
+       struct dentry *dentry = file->f_path.dentry;
 #elif defined(HAVE_FILE_FSYNC_2ARGS)
 int ll_fsync(struct file *file, int datasync)
 {
-       struct dentry *dentry = file->f_dentry;
+       struct dentry *dentry = file->f_path.dentry;
        loff_t start = 0;
        loff_t end = LLONG_MAX;
 #else
@@ -2684,7 +2665,6 @@ int ll_fsync(struct file *file, struct dentry *dentry, int datasync)
        struct inode *inode = dentry->d_inode;
        struct ll_inode_info *lli = ll_i2info(inode);
        struct ptlrpc_request *req;
-       struct obd_capa *oc;
        int rc, err;
        ENTRY;
 
@@ -2713,10 +2693,7 @@ int ll_fsync(struct file *file, struct dentry *dentry, int datasync)
                        rc = err;
        }
 
-       oc = ll_mdscapa_get(inode);
-       err = md_fsync(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode), oc,
-                      &req);
-       capa_put(oc);
+       err = md_fsync(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode), &req);
        if (!rc)
                rc = err;
        if (!err)
@@ -2743,7 +2720,7 @@ int ll_fsync(struct file *file, struct dentry *dentry, int datasync)
 static int
 ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
 {
-       struct inode *inode = file->f_dentry->d_inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
        struct ll_sb_info *sbi = ll_i2sbi(inode);
        struct ldlm_enqueue_info einfo = {
                .ei_type        = LDLM_FLOCK,
@@ -2930,7 +2907,7 @@ int ll_migrate(struct inode *parent, struct file *file, int mdtidx,
        qstr.hash = full_name_hash(name, namelen);
        qstr.name = name;
        qstr.len = namelen;
-       dchild = d_lookup(file->f_dentry, &qstr);
+       dchild = d_lookup(file->f_path.dentry, &qstr);
        if (dchild != NULL) {
                if (dchild->d_inode != NULL) {
                        child_inode = igrab(dchild->d_inode);
@@ -3158,9 +3135,6 @@ static int __ll_inode_revalidate(struct dentry *dentry, __u64 ibits)
                         RETURN(PTR_ERR(op_data));
 
                 op_data->op_valid = valid;
-                /* Once OBD_CONNECT_ATTRFID is not supported, we can't find one
-                 * capa for this inode. Because we only keep capas of dirs
-                 * fresh. */
                 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
                 ll_finish_md_op_data(op_data);
                 if (rc) {
@@ -3660,7 +3634,6 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
 
 {
        struct ll_sb_info *sbi = ll_i2sbi(inode);
-       struct obd_capa *oc;
        struct ptlrpc_request *req;
        struct mdt_body *body;
        void *lvbdata;
@@ -3673,7 +3646,7 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
               PFID(ll_inode2fid(inode)), ldlm_is_lvb_ready(lock),
               lock->l_lvb_data, lock->l_lvb_len);
 
-       if ((lock->l_lvb_data != NULL) && ldlm_is_lvb_ready(lock))
+       if (lock->l_lvb_data != NULL)
                RETURN(0);
 
        /* if layout lock was granted right away, the layout is returned
@@ -3681,13 +3654,11 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
         * blocked and then granted via completion ast, we have to fetch
         * layout here. Please note that we can't use the LVB buffer in
         * completion AST because it doesn't have a large enough buffer */
-       oc = ll_mdscapa_get(inode);
        rc = ll_get_default_mdsize(sbi, &lmmsize);
        if (rc == 0)
-               rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
+               rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode),
                                OBD_MD_FLXATTR, XATTR_NAME_LOV, NULL, 0,
                                lmmsize, 0, &req);
-       capa_put(oc);
        if (rc < 0)
                RETURN(rc);
 
@@ -3709,13 +3680,17 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
 
        memcpy(lvbdata, lmm, lmmsize);
        lock_res_and_lock(lock);
-       if (lock->l_lvb_data != NULL)
-               OBD_FREE_LARGE(lock->l_lvb_data, lock->l_lvb_len);
-
-       lock->l_lvb_data = lvbdata;
-       lock->l_lvb_len = lmmsize;
+       if (unlikely(lock->l_lvb_data == NULL)) {
+               lock->l_lvb_type = LVB_T_LAYOUT;
+               lock->l_lvb_data = lvbdata;
+               lock->l_lvb_len = lmmsize;
+               lvbdata = NULL;
+       }
        unlock_res_and_lock(lock);
 
+       if (lvbdata != NULL)
+               OBD_FREE_LARGE(lvbdata, lmmsize);
+
        EXIT;
 
 out:
@@ -3733,7 +3708,6 @@ static int ll_layout_lock_set(struct lustre_handle *lockh, ldlm_mode_t mode,
        struct ll_inode_info *lli = ll_i2info(inode);
        struct ll_sb_info    *sbi = ll_i2sbi(inode);
        struct ldlm_lock *lock;
-       struct lustre_md md = { NULL };
        struct cl_object_conf conf;
        int rc = 0;
        bool lvb_ready;
@@ -3765,38 +3739,20 @@ static int ll_layout_lock_set(struct lustre_handle *lockh, ldlm_mode_t mode,
        if (rc < 0)
                GOTO(out, rc);
 
-       /* for layout lock, lmm is returned in lock's lvb.
+       /* for layout lock, lmm is stored in lock's lvb.
         * lvb_data is immutable if the lock is held so it's safe to access it
-        * without res lock. See the description in ldlm_lock_decref_internal()
-        * for the condition to free lvb_data of layout lock */
-       if (lock->l_lvb_data != NULL) {
-               rc = obd_unpackmd(sbi->ll_dt_exp, &md.lsm,
-                                 lock->l_lvb_data, lock->l_lvb_len);
-               if (rc < 0) {
-                       CERROR("%s: file "DFID" unpackmd error: %d\n",
-                               ll_get_fsname(inode->i_sb, NULL, 0),
-                               PFID(&lli->lli_fid), rc);
-                       GOTO(out, rc);
-               }
-
-               LASSERTF(md.lsm != NULL, "lvb_data = %p, lvb_len = %u\n",
-                        lock->l_lvb_data, lock->l_lvb_len);
-
-               rc = 0;
-       }
-
-       /* set layout to file. Unlikely this will fail as old layout was
+        * without res lock.
+        *
+        * set layout to file. Unlikely this will fail as old layout was
         * surely eliminated */
        memset(&conf, 0, sizeof conf);
        conf.coc_opc = OBJECT_CONF_SET;
        conf.coc_inode = inode;
        conf.coc_lock = lock;
-       conf.u.coc_md = &md;
+       conf.u.coc_layout.lb_buf = lock->l_lvb_data;
+       conf.u.coc_layout.lb_len = lock->l_lvb_len;
        rc = ll_layout_conf(inode, &conf);
 
-       if (md.lsm != NULL)
-               obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
-
        /* refresh layout failed, need to wait */
        wait_layout = rc == -EBUSY;
        EXIT;