Whamcloud - gitweb
LU-13335 ldiskfs: add projid to debug logs
[fs/lustre-release.git] / lustre / llite / file.c
index 0c08757..73c256c 100644 (file)
@@ -46,7 +46,6 @@
 #include <linux/ktime.h>
 
 #include <uapi/linux/lustre/lustre_ioctl.h>
-#include <uapi/linux/llcrypt.h>
 #include <lustre_swab.h>
 
 #include "cl_object.h"
@@ -105,7 +104,16 @@ static void ll_prepare_close(struct inode *inode, struct md_op_data *op_data,
        op_data->op_attr.ia_atime = inode->i_atime;
        op_data->op_attr.ia_mtime = inode->i_mtime;
        op_data->op_attr.ia_ctime = inode->i_ctime;
-       op_data->op_attr.ia_size = i_size_read(inode);
+       /* In case of encrypted file without the key, visible size was rounded
+        * up to next LUSTRE_ENCRYPTION_UNIT_SIZE, and clear text size was
+        * stored into lli_lazysize in ll_merge_attr(), so set proper file size
+        * now that we are closing.
+        */
+       if (llcrypt_require_key(inode) == -ENOKEY &&
+           ll_i2info(inode)->lli_attr_valid & OBD_MD_FLLAZYSIZE)
+               op_data->op_attr.ia_size = ll_i2info(inode)->lli_lazysize;
+       else
+               op_data->op_attr.ia_size = i_size_read(inode);
        op_data->op_attr.ia_valid |= (ATTR_MODE | ATTR_ATIME | ATTR_ATIME_SET |
                                      ATTR_MTIME | ATTR_MTIME_SET |
                                      ATTR_CTIME);
@@ -163,7 +171,7 @@ static int ll_close_inode_openhandle(struct inode *inode,
                op_data->op_attr_blocks += ((struct inode *)data)->i_blocks;
                op_data->op_attr.ia_valid |= ATTR_SIZE;
                op_data->op_xvalid |= OP_XVALID_BLOCKS;
-               /* fallthrough */
+               fallthrough;
        case MDS_CLOSE_LAYOUT_SPLIT:
        case MDS_CLOSE_LAYOUT_SWAP: {
                struct split_param *sp = data;
@@ -318,28 +326,39 @@ static int ll_md_close(struct inode *inode, struct file *file)
        if (unlikely(fd->fd_flags & LL_FILE_GROUP_LOCKED))
                ll_put_grouplock(inode, file, fd->fd_grouplock.lg_gid);
 
+       mutex_lock(&lli->lli_och_mutex);
        if (fd->fd_lease_och != NULL) {
                bool lease_broken;
+               struct obd_client_handle *lease_och;
+
+               lease_och = fd->fd_lease_och;
+               fd->fd_lease_och = NULL;
+               mutex_unlock(&lli->lli_och_mutex);
 
                /* Usually the lease is not released when the
                 * application crashed, we need to release here. */
-               rc = ll_lease_close(fd->fd_lease_och, inode, &lease_broken);
+               rc = ll_lease_close(lease_och, inode, &lease_broken);
+
+               mutex_lock(&lli->lli_och_mutex);
+
                CDEBUG_LIMIT(rc ? D_ERROR : D_INODE,
                             "Clean up lease "DFID" %d/%d\n",
                             PFID(&lli->lli_fid), rc, lease_broken);
-
-               fd->fd_lease_och = NULL;
        }
 
        if (fd->fd_och != NULL) {
-               rc = ll_close_inode_openhandle(inode, fd->fd_och, 0, NULL);
+               struct obd_client_handle *och;
+
+               och = fd->fd_och;
                fd->fd_och = NULL;
+               mutex_unlock(&lli->lli_och_mutex);
+
+               rc = ll_close_inode_openhandle(inode, och, 0, NULL);
                GOTO(out, rc);
        }
 
         /* Let's see if we have good enough OPEN lock on the file and if
            we can skip talking to MDS */
-       mutex_lock(&lli->lli_och_mutex);
        if (fd->fd_omode & FMODE_WRITE) {
                lockmode = LCK_CW;
                LASSERT(lli->lli_open_fd_write_count);
@@ -424,11 +443,15 @@ out:
 
 static inline int ll_dom_readpage(void *data, struct page *page)
 {
+       /* since ll_dom_readpage is a page cache helper, it is safe to assume
+        * mapping and host pointers are set here
+        */
+       struct inode *inode;
        struct niobuf_local *lnb = data;
        void *kaddr;
        int rc = 0;
 
-       struct inode *inode = page2inode(page);
+       inode = page2inode(page);
 
        kaddr = kmap_atomic(page);
        memcpy(kaddr, lnb->lnb_data, lnb->lnb_len);
@@ -571,7 +594,7 @@ void ll_dom_finish_open(struct inode *inode, struct ptlrpc_request *req)
                        put_page(vmpage);
                        break;
                }
-               cl_page_export(env, page, 1);
+               SetPageUptodate(vmpage);
                cl_page_put(env, page);
                unlock_page(vmpage);
                put_page(vmpage);
@@ -628,7 +651,7 @@ retry:
        }
 
        op_data = ll_prep_md_op_data(NULL, parent->d_inode, de->d_inode,
-                                    name, len, 0, LUSTRE_OPC_ANY, NULL);
+                                    name, len, 0, LUSTRE_OPC_OPEN, NULL);
        if (IS_ERR(op_data)) {
                kfree(name);
                RETURN(PTR_ERR(op_data));
@@ -744,12 +767,6 @@ static int ll_local_open(struct file *file, struct lookup_intent *it,
        file->private_data = fd;
        ll_readahead_init(inode, &fd->fd_ras);
        fd->fd_omode = it->it_flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
-       /* turn off the kernel's read-ahead */
-       file->f_ra.ra_pages = 0;
-
-       /* ll_cl_context initialize */
-       rwlock_init(&fd->fd_lock);
-       INIT_LIST_HEAD(&fd->fd_lccs);
 
        RETURN(0);
 }
@@ -809,9 +826,12 @@ int ll_file_open(struct inode *inode, struct file *file)
        file->private_data = NULL; /* prevent ll_local_open assertion */
 
        if (S_ISREG(inode->i_mode)) {
-               rc = llcrypt_file_open(inode, file);
-               if (rc)
+               rc = ll_file_open_encrypt(inode, file);
+               if (rc) {
+                       if (it && it->it_disposition)
+                               ll_release_openhandle(file_dentry(file), it);
                        GOTO(out_nofiledata, rc);
+               }
        }
 
        fd = ll_file_data_get();
@@ -1267,8 +1287,8 @@ static int ll_check_swap_layouts_validity(struct inode *inode1,
        if (!S_ISREG(inode1->i_mode) || !S_ISREG(inode2->i_mode))
                return -EINVAL;
 
-       if (inode_permission(inode1, MAY_WRITE) ||
-           inode_permission(inode2, MAY_WRITE))
+       if (inode_permission(&init_user_ns, inode1, MAY_WRITE) ||
+           inode_permission(&init_user_ns, inode2, MAY_WRITE))
                return -EPERM;
 
        if (inode1->i_sb != inode2->i_sb)
@@ -1460,6 +1480,16 @@ int ll_merge_attr(const struct lu_env *env, struct inode *inode)
        CDEBUG(D_VFSTRACE, DFID" updating i_size %llu\n",
               PFID(&lli->lli_fid), attr->cat_size);
 
+       if (llcrypt_require_key(inode) == -ENOKEY) {
+               /* Without the key, round up encrypted file size to next
+                * LUSTRE_ENCRYPTION_UNIT_SIZE. Clear text size is put in
+                * lli_lazysize for proper file size setting at close time.
+                */
+               lli->lli_attr_valid |= OBD_MD_FLLAZYSIZE;
+               lli->lli_lazysize = attr->cat_size;
+               attr->cat_size = round_up(attr->cat_size,
+                                         LUSTRE_ENCRYPTION_UNIT_SIZE);
+       }
        i_size_write(inode, attr->cat_size);
        inode->i_blocks = attr->cat_blocks;
 
@@ -1547,6 +1577,12 @@ void ll_io_init(struct cl_io *io, struct file *file, enum cl_io_type iot,
 #endif
        }
 
+#ifdef IOCB_NOWAIT
+       io->ci_iocb_nowait = !!(args &&
+                               (args->u.normal.via_iocb->ki_flags &
+                                IOCB_NOWAIT));
+#endif
+
        io->ci_obj = ll_i2info(inode)->lli_clob;
        io->ci_lockreq = CILR_MAYBE;
        if (ll_file_nolock(file)) {
@@ -1633,6 +1669,8 @@ ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
 
        io = vvp_env_thread_io(env);
        if (file->f_flags & O_DIRECT) {
+               if (file->f_flags & O_APPEND)
+                       dio_lock = 1;
                if (!is_sync_kiocb(args->u.normal.via_iocb))
                        is_aio = true;
 
@@ -1647,7 +1685,7 @@ ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
                        is_parallel_dio = false;
 
                ci_aio = cl_aio_alloc(args->u.normal.via_iocb,
-                                     ll_i2info(inode)->lli_clob);
+                                     ll_i2info(inode)->lli_clob, NULL);
                if (!ci_aio)
                        GOTO(out, rc = -ENOMEM);
        }
@@ -1695,9 +1733,9 @@ restart:
                        range_locked = true;
                }
 
-               ll_cl_add(file, env, io, LCC_RW);
+               ll_cl_add(inode, env, io, LCC_RW);
                rc = cl_io_loop(env, io);
-               ll_cl_remove(file, env);
+               ll_cl_remove(inode, env);
 
                if (range_locked && !is_parallel_dio) {
                        CDEBUG(D_VFSTRACE, "Range unlock "RL_FMT"\n",
@@ -1913,8 +1951,15 @@ static ssize_t ll_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
        ktime_t kstart = ktime_get();
        bool cached;
 
+       ENTRY;
+
+       CDEBUG(D_VFSTRACE|D_IOTRACE, "file %s:"DFID", ppos: %lld, count: %zu\n",
+              file_dentry(file)->d_name.name,
+              PFID(ll_inode2fid(file_inode(file))), iocb->ki_pos,
+              iov_iter_count(to));
+
        if (!iov_iter_count(to))
-               return 0;
+               RETURN(0);
 
        /**
         * Currently when PCC read failed, we do not fall back to the
@@ -1939,7 +1984,7 @@ static ssize_t ll_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
 
        env = cl_env_get(&refcheck);
        if (IS_ERR(env))
-               return PTR_ERR(env);
+               RETURN(PTR_ERR(env));
 
        args = ll_env_args(env);
        args->u.normal.via_iter = to;
@@ -1962,7 +2007,13 @@ out:
                                   ktime_us_delta(ktime_get(), kstart));
        }
 
-       return result;
+       CDEBUG(D_IOTRACE,
+              "COMPLETED: file %s:"DFID", ppos: %lld, count: %zu\n",
+              file_dentry(file)->d_name.name,
+              PFID(ll_inode2fid(file_inode(file))), iocb->ki_pos,
+              iov_iter_count(to));
+
+       RETURN(result);
 }
 
 /**
@@ -2014,8 +2065,6 @@ static ssize_t ll_do_tiny_write(struct kiocb *iocb, struct iov_iter *iter)
 
        if (result > 0) {
                ll_heat_add(inode, CIT_WRITE, result);
-               ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_WRITE_BYTES,
-                                  result);
                set_bit(LLIF_DATA_MODIFIED, &ll_i2info(inode)->lli_flags);
        }
 
@@ -2040,6 +2089,11 @@ static ssize_t ll_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
 
        ENTRY;
 
+       CDEBUG(D_VFSTRACE|D_IOTRACE, "file %s:"DFID", ppos: %lld, count: %zu\n",
+              file_dentry(file)->d_name.name,
+              PFID(ll_inode2fid(file_inode(file))), iocb->ki_pos,
+              iov_iter_count(from));
+
        if (!iov_iter_count(from))
                GOTO(out, rc_normal = 0);
 
@@ -2074,7 +2128,7 @@ static ssize_t ll_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
 
        env = cl_env_get(&refcheck);
        if (IS_ERR(env))
-               return PTR_ERR(env);
+               RETURN(PTR_ERR(env));
 
        args = ll_env_args(env);
        args->u.normal.via_iter = from;
@@ -2102,6 +2156,12 @@ out:
                                   ktime_us_delta(ktime_get(), kstart));
        }
 
+       CDEBUG(D_IOTRACE,
+              "COMPLETED: file %s:"DFID", ppos: %lld, count: %zu\n",
+              file_dentry(file)->d_name.name,
+              PFID(ll_inode2fid(file_inode(file))), iocb->ki_pos,
+              iov_iter_count(from));
+
        RETURN(rc_normal);
 }
 
@@ -2283,7 +2343,7 @@ int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
                              struct ptlrpc_request **request)
 {
        struct ll_sb_info *sbi = ll_i2sbi(inode);
-       struct mdt_body *body;
+       struct mdt_body  *body;
        struct lov_mds_md *lmm = NULL;
        struct ptlrpc_request *req = NULL;
        struct md_op_data *op_data;
@@ -2305,8 +2365,8 @@ int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
        rc = md_getattr_name(sbi->ll_md_exp, op_data, &req);
        ll_finish_md_op_data(op_data);
        if (rc < 0) {
-               CDEBUG(D_INFO, "md_getattr_name failed "
-                      "on %s: rc %d\n", filename, rc);
+               CDEBUG(D_INFO, "md_getattr_name failed on %s: rc %d\n",
+                      filename, rc);
                GOTO(out, rc);
        }
 
@@ -2714,7 +2774,7 @@ static int ll_do_fiemap(struct inode *inode, struct fiemap *fiemap,
                        GOTO(out, rc);
        }
 
-       fmkey.lfik_oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
+       fmkey.lfik_oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLPROJID;
        obdo_from_inode(&fmkey.lfik_oa, inode, OBD_MD_FLSIZE);
        obdo_set_parent_fid(&fmkey.lfik_oa, &ll_i2info(inode)->lli_fid);
 
@@ -2745,7 +2805,7 @@ int ll_fid2path(struct inode *inode, void __user *arg)
        ENTRY;
 
        if (!capable(CAP_DAC_READ_SEARCH) &&
-           !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
+           !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
                RETURN(-EPERM);
 
        /* Only need to get the buflen */
@@ -2858,8 +2918,9 @@ int ll_hsm_release(struct inode *inode)
        struct lu_env *env;
        struct obd_client_handle *och = NULL;
        __u64 data_version = 0;
-       int rc;
        __u16 refcheck;
+       int rc;
+
        ENTRY;
 
        CDEBUG(D_INODE, "%s: Releasing file "DFID".\n",
@@ -2871,7 +2932,8 @@ int ll_hsm_release(struct inode *inode)
                GOTO(out, rc = PTR_ERR(och));
 
        /* Grab latest data_version and [am]time values */
-       rc = ll_data_version(inode, &data_version, LL_DV_WR_FLUSH);
+       rc = ll_data_version(inode, &data_version,
+                            LL_DV_WR_FLUSH | LL_DV_SZ_UPDATE);
        if (rc != 0)
                GOTO(out, rc);
 
@@ -3309,7 +3371,7 @@ static int ll_ladvise_sanity(struct inode *inode,
                               ladvise_names[advice], rc);
                        GOTO(out, rc);
                }
-               /* fallthrough */
+               fallthrough;
        case LU_LADVISE_WILLREAD:
        case LU_LADVISE_DONTNEED:
        default:
@@ -3453,12 +3515,14 @@ int ll_ioctl_check_project(struct inode *inode, __u32 xflags,
 
 static int ll_set_project(struct inode *inode, __u32 xflags, __u32 projid)
 {
-       struct md_op_data *op_data;
        struct ptlrpc_request *req = NULL;
+       struct md_op_data *op_data;
        struct cl_object *obj;
        unsigned int inode_flags;
        int rc = 0;
 
+       CDEBUG(D_QUOTA, DFID" xflags=%x projid=%u\n",
+              PFID(ll_inode2fid(inode)), xflags, projid);
        rc = ll_ioctl_check_project(inode, xflags, projid);
        if (rc)
                RETURN(rc);
@@ -3472,7 +3536,10 @@ static int ll_set_project(struct inode *inode, __u32 xflags, __u32 projid)
        op_data->op_attr_flags = ll_inode_to_ext_flags(inode_flags);
        if (xflags & FS_XFLAG_PROJINHERIT)
                op_data->op_attr_flags |= LUSTRE_PROJINHERIT_FL;
+
+       /* pass projid to md_op_data */
        op_data->op_projid = projid;
+
        op_data->op_xvalid |= OP_XVALID_PROJID | OP_XVALID_FLAGS;
        rc = md_setattr(ll_i2sbi(inode)->ll_md_exp, op_data, NULL, 0, &req);
        ptlrpc_req_finished(req);
@@ -3675,6 +3742,9 @@ static long ll_file_unlock_lease(struct file *file, struct ll_ioc_lease *ioc,
                if (ioc->lil_count != 1)
                        RETURN(-EINVAL);
 
+               if (IS_ENCRYPTED(inode))
+                       RETURN(-EOPNOTSUPP);
+
                arg += sizeof(*ioc);
                if (copy_from_user(&param.pa_archive_id, (void __user *)arg,
                                   sizeof(__u32)))
@@ -3997,9 +4067,7 @@ out:
                 RETURN(0);
         }
        case OBD_IOC_GETNAME_OLD:
-               /* fall through */
        case OBD_IOC_GETDTNAME:
-               /* fall through */
        case OBD_IOC_GETMDNAME:
                RETURN(ll_get_obd_name(inode, cmd, arg));
        case LL_IOC_HSM_STATE_GET: {
@@ -4047,9 +4115,10 @@ out:
                RETURN(rc);
        }
        case LL_IOC_HSM_ACTION: {
-               struct md_op_data               *op_data;
-               struct hsm_current_action       *hca;
-               int                              rc;
+               struct md_op_data *op_data;
+               struct hsm_current_action *hca;
+               const char *action;
+               int rc;
 
                OBD_ALLOC_PTR(hca);
                if (hca == NULL)
@@ -4064,10 +4133,26 @@ out:
 
                rc = obd_iocontrol(cmd, ll_i2mdexp(inode), sizeof(*op_data),
                                   op_data, NULL);
+               if (rc < 0)
+                       GOTO(skip_copy, rc);
+
+               /* The hsm_current_action retreived from the server could
+                * contain corrupt information. If it is incorrect data collect
+                * debug information. We still send the data even if incorrect
+                * to user land to handle.
+                */
+               action = hsm_user_action2name(hca->hca_action);
+               if (strcmp(action, "UNKNOWN") == 0 ||
+                   hca->hca_state > HPS_DONE) {
+                       CDEBUG(D_HSM,
+                              "HSM current state %s action %s, offset = %llu, length %llu\n",
+                              hsm_progress_state2name(hca->hca_state), action,
+                              hca->hca_location.offset, hca->hca_location.length);
+               }
 
                if (copy_to_user((char __user *)arg, hca, sizeof(*hca)))
                        rc = -EFAULT;
-
+skip_copy:
                ll_finish_md_op_data(op_data);
                OBD_FREE_PTR(hca);
                RETURN(rc);
@@ -4276,7 +4361,7 @@ out_ladvise:
                if (!S_ISREG(inode->i_mode))
                        GOTO(out_detach_free, rc = -EINVAL);
 
-               if (!inode_owner_or_capable(inode))
+               if (!inode_owner_or_capable(&init_user_ns, inode))
                        GOTO(out_detach_free, rc = -EPERM);
 
                rc = pcc_ioctl_detach(inode, detach->pccd_opt);
@@ -4395,6 +4480,12 @@ loff_t ll_lseek(struct file *file, loff_t offset, int whence)
 
        cl_env_put(env, &refcheck);
 
+       /* Without the key, SEEK_HOLE return value has to be
+        * rounded up to next LUSTRE_ENCRYPTION_UNIT_SIZE.
+        */
+       if (llcrypt_require_key(inode) == -ENOKEY && whence == SEEK_HOLE)
+               retval = round_up(retval, LUSTRE_ENCRYPTION_UNIT_SIZE);
+
        RETURN(retval);
 }
 
@@ -4537,7 +4628,6 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
        /* 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_write_and_wait_range(inode->i_mapping, start, end);
-       inode_lock(inode);
 
        /* catch async errors that were recorded back when async writeback
         * failed for pages in this mapping. */
@@ -4578,8 +4668,6 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
                        fd->fd_write_failed = false;
        }
 
-       inode_unlock(inode);
-
        if (!rc)
                ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_FSYNC,
                                   ktime_us_delta(ktime_get(), kstart));
@@ -4737,10 +4825,10 @@ int ll_get_fid_by_name(struct inode *parent, const char *name,
                       int namelen, struct lu_fid *fid,
                       struct inode **inode)
 {
-       struct md_op_data       *op_data = NULL;
-       struct mdt_body         *body;
-       struct ptlrpc_request   *req;
-       int                     rc;
+       struct md_op_data *op_data = NULL;
+       struct mdt_body *body;
+       struct ptlrpc_request *req;
+       int rc;
        ENTRY;
 
        op_data = ll_prep_md_op_data(NULL, parent, NULL, name, namelen, 0,
@@ -4768,7 +4856,7 @@ out_req:
 }
 
 int ll_migrate(struct inode *parent, struct file *file, struct lmv_user_md *lum,
-              const char *name)
+              const char *name, __u32 flags)
 {
        struct dentry *dchild = NULL;
        struct inode *child_inode = NULL;
@@ -4830,23 +4918,6 @@ int ll_migrate(struct inode *parent, struct file *file, struct lmv_user_md *lum,
        if (is_root_inode(child_inode))
                GOTO(out_iput, rc = -EINVAL);
 
-       if (IS_ENCRYPTED(child_inode)) {
-               rc = llcrypt_get_encryption_info(child_inode);
-               if (rc)
-                       GOTO(out_iput, rc);
-               if (!llcrypt_has_encryption_key(child_inode)) {
-                       CDEBUG(D_SEC, "no enc key for "DFID"\n",
-                              PFID(ll_inode2fid(child_inode)));
-                       GOTO(out_iput, rc = -ENOKEY);
-               }
-               if (unlikely(!llcrypt_policy_has_filename_enc(child_inode))) {
-                       CDEBUG(D_SEC,
-                              "cannot migrate old format encrypted "DFID", please move to new enc dir first\n",
-                              PFID(ll_inode2fid(child_inode)));
-                       GOTO(out_iput, rc = -EUCLEAN);
-               }
-       }
-
        op_data = ll_prep_md_op_data(NULL, parent, NULL, name, namelen,
                                     child_inode->i_mode, LUSTRE_OPC_ANY, NULL);
        if (IS_ERR(op_data))
@@ -4865,6 +4936,11 @@ int ll_migrate(struct inode *parent, struct file *file, struct lmv_user_md *lum,
        op_data->op_data = lum;
        op_data->op_data_size = lumlen;
 
+       /* migrate dirent only for subdirs if MDS_MIGRATE_NSONLY set */
+       if (S_ISDIR(child_inode->i_mode) && (flags & MDS_MIGRATE_NSONLY) &&
+           lmv_dir_layout_changing(ll_i2info(parent)->lli_lsm_md))
+               op_data->op_bias |= MDS_MIGRATE_NSONLY;
+
 again:
        if (S_ISREG(child_inode->i_mode)) {
                och = ll_lease_open(child_inode, NULL, FMODE_WRITE, 0);
@@ -4889,8 +4965,9 @@ again:
                spin_unlock(&och->och_mod->mod_open_req->rq_lock);
        }
 
-       rc = md_rename(ll_i2sbi(parent)->ll_md_exp, op_data, name, namelen,
-                      name, namelen, &request);
+       rc = md_rename(ll_i2sbi(parent)->ll_md_exp, op_data,
+                      op_data->op_name, op_data->op_namelen,
+                      op_data->op_name, op_data->op_namelen, &request);
        if (rc == 0) {
                LASSERT(request != NULL);
                ll_update_times(request, parent);
@@ -4947,7 +5024,7 @@ ll_file_noflock(struct file *file, int cmd, struct file_lock *file_lock)
         */
        if (!(fd->fd_flags & LL_FILE_FLOCK_WARNING)) {
                fd->fd_flags |= LL_FILE_FLOCK_WARNING;
-               CDEBUG_LIMIT(D_TTY | D_CONSOLE,
+               CDEBUG_LIMIT(D_CONSOLE,
                             "flock disabled, mount with '-o [local]flock' to enable\r\n");
        }
        RETURN(-ENOSYS);
@@ -5115,19 +5192,24 @@ static int ll_merge_md_attr(struct inode *inode)
        struct cl_attr attr = { 0 };
        int rc;
 
-       LASSERT(lli->lli_lsm_md != NULL);
-
-       if (!lmv_dir_striped(lli->lli_lsm_md))
+       if (!lli->lli_lsm_md)
                RETURN(0);
 
        down_read(&lli->lli_lsm_sem);
+       if (!lmv_dir_striped(lli->lli_lsm_md)) {
+               up_read(&lli->lli_lsm_sem);
+               RETURN(0);
+       }
        rc = md_merge_attr(ll_i2mdexp(inode), ll_i2info(inode)->lli_lsm_md,
                           &attr, ll_md_blocking_ast);
        up_read(&lli->lli_lsm_sem);
        if (rc != 0)
                RETURN(rc);
 
+       spin_lock(&inode->i_lock);
        set_nlink(inode, attr.cat_nlink);
+       spin_unlock(&inode->i_lock);
+
        inode->i_blocks = attr.cat_blocks;
        i_size_write(inode, attr.cat_size);
 
@@ -5267,7 +5349,7 @@ fill_attr:
        stat->size = i_size_read(inode);
        stat->blocks = inode->i_blocks;
 
-#ifdef HAVE_INODEOPS_ENHANCED_GETATTR
+#if defined(HAVE_USER_NAMESPACE_ARG) || defined(HAVE_INODEOPS_ENHANCED_GETATTR)
        if (flags & AT_STATX_DONT_SYNC) {
                if (stat->size == 0 &&
                    lli->lli_attr_valid & OBD_MD_FLLAZYSIZE)
@@ -5293,9 +5375,9 @@ fill_attr:
        return 0;
 }
 
-#ifdef HAVE_INODEOPS_ENHANCED_GETATTR
-int ll_getattr(const struct path *path, struct kstat *stat,
-              u32 request_mask, unsigned int flags)
+#if defined(HAVE_USER_NAMESPACE_ARG) || defined(HAVE_INODEOPS_ENHANCED_GETATTR)
+int ll_getattr(struct user_namespace *mnt_userns, const struct path *path,
+              struct kstat *stat, u32 request_mask, unsigned int flags)
 {
        return ll_getattr_dentry(path->dentry, stat, request_mask, flags,
                                 false);
@@ -5308,13 +5390,14 @@ int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat)
 }
 #endif
 
-int cl_falloc(struct inode *inode, int mode, loff_t offset, loff_t len)
+int cl_falloc(struct file *file, struct inode *inode, int mode, loff_t offset,
+             loff_t len)
 {
+       loff_t size = i_size_read(inode);
        struct lu_env *env;
        struct cl_io *io;
        __u16 refcheck;
        int rc;
-       loff_t size = i_size_read(inode);
 
        ENTRY;
 
@@ -5324,12 +5407,24 @@ int cl_falloc(struct inode *inode, int mode, loff_t offset, loff_t len)
 
        io = vvp_env_thread_io(env);
        io->ci_obj = ll_i2info(inode)->lli_clob;
+       ll_io_set_mirror(io, file);
+
        io->ci_verify_layout = 1;
        io->u.ci_setattr.sa_parent_fid = lu_object_fid(&io->ci_obj->co_lu);
        io->u.ci_setattr.sa_falloc_mode = mode;
        io->u.ci_setattr.sa_falloc_offset = offset;
        io->u.ci_setattr.sa_falloc_end = offset + len;
        io->u.ci_setattr.sa_subtype = CL_SETATTR_FALLOCATE;
+
+       CDEBUG(D_INODE, "UID %u GID %u PRJID %u\n",
+              from_kuid(&init_user_ns, inode->i_uid),
+              from_kgid(&init_user_ns, inode->i_gid),
+              ll_i2info(inode)->lli_projid);
+
+       io->u.ci_setattr.sa_falloc_uid = from_kuid(&init_user_ns, inode->i_uid);
+       io->u.ci_setattr.sa_falloc_gid = from_kgid(&init_user_ns, inode->i_gid);
+       io->u.ci_setattr.sa_falloc_projid = ll_i2info(inode)->lli_projid;
+
        if (io->u.ci_setattr.sa_falloc_end > size) {
                loff_t newsize = io->u.ci_setattr.sa_falloc_end;
 
@@ -5362,7 +5457,7 @@ out:
 
 long ll_fallocate(struct file *filp, int mode, loff_t offset, loff_t len)
 {
-       struct inode *inode = filp->f_path.dentry->d_inode;
+       struct inode *inode = file_inode(filp);
        int rc;
 
        if (offset < 0 || len <= 0)
@@ -5387,7 +5482,7 @@ long ll_fallocate(struct file *filp, int mode, loff_t offset, loff_t len)
 
        ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_FALLOCATE, 1);
 
-       rc = cl_falloc(inode, mode, offset, len);
+       rc = cl_falloc(filp, inode, mode, offset, len);
        /*
         * ENOTSUPP (524) is an NFSv3 specific error code erroneously
         * used by Lustre in several places. Retuning it here would
@@ -5447,7 +5542,8 @@ out:
        return rc;
 }
 
-int ll_inode_permission(struct inode *inode, int mask)
+int ll_inode_permission(struct user_namespace *mnt_userns, struct inode *inode,
+                       int mask)
 {
        int rc = 0;
        struct ll_sb_info *sbi;
@@ -5481,7 +5577,7 @@ int ll_inode_permission(struct inode *inode, int mask)
        squash = &sbi->ll_squash;
        if (unlikely(squash->rsi_uid != 0 &&
                     uid_eq(current_fsuid(), GLOBAL_ROOT_UID) &&
-                    !(sbi->ll_flags & LL_SBI_NOROOTSQUASH))) {
+                    !test_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags))) {
                        squash_id = true;
        }
        if (squash_id) {
@@ -5503,7 +5599,7 @@ int ll_inode_permission(struct inode *inode, int mask)
                old_cred = override_creds(cred);
        }
 
-       rc = generic_permission(inode, mask);
+       rc = generic_permission(mnt_userns, inode, mask);
        /* restore current process's credentials and FS capability */
        if (squash_id) {
                revert_creds(old_cred);
@@ -5631,9 +5727,9 @@ const struct file_operations *ll_select_file_operations(struct ll_sb_info *sbi)
 {
        const struct file_operations *fops = &ll_file_operations_noflock;
 
-       if (sbi->ll_flags & LL_SBI_FLOCK)
+       if (test_bit(LL_SBI_FLOCK, sbi->ll_flags))
                fops = &ll_file_operations_flock;
-       else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
+       else if (test_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags))
                fops = &ll_file_operations;
 
        return fops;
@@ -5921,7 +6017,8 @@ int ll_layout_refresh(struct inode *inode, __u32 *gen)
        ENTRY;
 
        *gen = ll_layout_version_get(lli);
-       if (!(sbi->ll_flags & LL_SBI_LAYOUT_LOCK) || *gen != CL_LAYOUT_GEN_NONE)
+       if (!test_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags) ||
+           *gen != CL_LAYOUT_GEN_NONE)
                RETURN(0);
 
        /* sanity checks */