These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / lustre / lustre / llite / file.c
index 4b44c63..02f2759 100644 (file)
@@ -64,7 +64,7 @@ static struct ll_file_data *ll_file_data_get(void)
 {
        struct ll_file_data *fd;
 
-       OBD_SLAB_ALLOC_PTR_GFP(fd, ll_file_data_slab, GFP_NOFS);
+       fd = kmem_cache_alloc(ll_file_data_slab, GFP_NOFS | __GFP_ZERO);
        if (fd == NULL)
                return NULL;
        fd->fd_write_failed = false;
@@ -74,7 +74,7 @@ static struct ll_file_data *ll_file_data_get(void)
 static void ll_file_data_put(struct ll_file_data *fd)
 {
        if (fd != NULL)
-               OBD_SLAB_FREE_PTR(fd, ll_file_data_slab);
+               kmem_cache_free(ll_file_data_slab, fd);
 }
 
 void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
@@ -92,9 +92,8 @@ void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
        op_data->op_ioepoch = ll_i2info(inode)->lli_ioepoch;
        if (fh)
                op_data->op_handle = *fh;
-       op_data->op_capa1 = ll_mdscapa_get(inode);
 
-       if (LLIF_DATA_MODIFIED & ll_i2info(inode)->lli_flags)
+       if (ll_i2info(inode)->lli_flags & LLIF_DATA_MODIFIED)
                op_data->op_bias |= MDS_DATA_MODIFIED;
 }
 
@@ -213,7 +212,7 @@ out:
                md_clear_open_replay_data(md_exp, och);
                /* Free @och if it is not waiting for DONE_WRITING. */
                och->och_fh.cookie = DEAD_HANDLE_MAGIC;
-               OBD_FREE_PTR(och);
+               kfree(och);
        }
        if (req) /* This is close request */
                ptlrpc_req_finished(req);
@@ -270,7 +269,7 @@ static int ll_md_close(struct obd_export *md_exp, struct inode *inode,
        int lockmode;
        __u64 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_TEST_LOCK;
        struct lustre_handle lockh;
-       ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_OPEN}};
+       ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_OPEN} };
        int rc = 0;
 
        /* clear group lock, if present */
@@ -321,7 +320,6 @@ static int ll_md_close(struct obd_export *md_exp, struct inode *inode,
 out:
        LUSTRE_FPRIVATE(file) = NULL;
        ll_file_data_put(fd);
-       ll_capa_close(inode);
 
        return rc;
 }
@@ -679,8 +677,6 @@ restart:
        if (!S_ISREG(inode->i_mode))
                goto out_och_free;
 
-       ll_capa_open(inode);
-
        if (!lli->lli_has_smd &&
            (cl_is_lov_delay_create(file->f_flags) ||
             (file->f_mode & FMODE_WRITE) == 0)) {
@@ -693,8 +689,8 @@ restart:
 out_och_free:
        if (rc) {
                if (och_p && *och_p) {
-                       OBD_FREE(*och_p, sizeof(struct obd_client_handle));
-                       *och_p = NULL; /* OBD_FREE writes some magic there */
+                       kfree(*och_p);
+                       *och_p = NULL;
                        (*och_usecount)--;
                }
                mutex_unlock(&lli->lli_och_mutex);
@@ -702,8 +698,7 @@ out_och_free:
 out_openerr:
                if (opendir_set != 0)
                        ll_stop_statahead(inode, lli->lli_opendir_key);
-               if (fd != NULL)
-                       ll_file_data_put(fd);
+               ll_file_data_put(fd);
        } else {
                ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_OPEN, 1);
        }
@@ -875,7 +870,7 @@ out_close:
 out_release_it:
        ll_intent_release(&it);
 out:
-       OBD_FREE_PTR(och);
+       kfree(och);
        return ERR_PTR(rc);
 }
 
@@ -913,11 +908,10 @@ static int ll_lease_close(struct obd_client_handle *och, struct inode *inode,
 
 /* Fills the obdo with the attributes for the lsm */
 static int ll_lsm_getattr(struct lov_stripe_md *lsm, struct obd_export *exp,
-                         struct obd_capa *capa, struct obdo *obdo,
-                         __u64 ioepoch, int sync)
+                         struct obdo *obdo, __u64 ioepoch, int sync)
 {
        struct ptlrpc_request_set *set;
-       struct obd_info     oinfo = { { { 0 } } };
+       struct obd_info     oinfo = { };
        int                     rc;
 
        LASSERT(lsm != NULL);
@@ -933,7 +927,6 @@ static int ll_lsm_getattr(struct lov_stripe_md *lsm, struct obd_export *exp,
                               OBD_MD_FLMTIME | OBD_MD_FLCTIME |
                               OBD_MD_FLGROUP | OBD_MD_FLEPOCH |
                               OBD_MD_FLDATAVERSION;
-       oinfo.oi_capa = capa;
        if (sync) {
                oinfo.oi_oa->o_valid |= OBD_MD_FLFLAGS;
                oinfo.oi_oa->o_flags |= OBD_FL_SRVLOCK;
@@ -964,14 +957,12 @@ static int ll_lsm_getattr(struct lov_stripe_md *lsm, struct obd_export *exp,
 int ll_inode_getattr(struct inode *inode, struct obdo *obdo,
                     __u64 ioepoch, int sync)
 {
-       struct obd_capa      *capa = ll_mdscapa_get(inode);
        struct lov_stripe_md *lsm;
        int rc;
 
        lsm = ccc_inode_lsm_get(inode);
        rc = ll_lsm_getattr(lsm, ll_i2dtexp(inode),
-                           capa, obdo, ioepoch, sync);
-       capa_put(capa);
+                           obdo, ioepoch, sync);
        if (rc == 0) {
                struct ost_id *oi = lsm ? &lsm->lsm_oi : &obdo->o_oi;
 
@@ -1039,7 +1030,7 @@ int ll_glimpse_ioctl(struct ll_sb_info *sbi, struct lov_stripe_md *lsm,
        struct obdo obdo = { 0 };
        int rc;
 
-       rc = ll_lsm_getattr(lsm, sbi->ll_dt_exp, NULL, &obdo, 0, 0);
+       rc = ll_lsm_getattr(lsm, sbi->ll_dt_exp, &obdo, 0, 0);
        if (rc == 0) {
                st->st_size   = obdo.o_size;
                st->st_blocks = obdo.o_blocks;
@@ -1269,7 +1260,7 @@ static int ll_lov_recreate(struct inode *inode, struct ost_id *oi, u32 ost_idx)
        int rc = 0;
        struct lov_stripe_md *lsm = NULL, *lsm2;
 
-       OBDO_ALLOC(oa);
+       oa = kmem_cache_alloc(obdo_cachep, GFP_NOFS | __GFP_ZERO);
        if (oa == NULL)
                return -ENOMEM;
 
@@ -1282,7 +1273,7 @@ static int ll_lov_recreate(struct inode *inode, struct ost_id *oi, u32 ost_idx)
        lsm_size = sizeof(*lsm) + (sizeof(struct lov_oinfo) *
                   (lsm->lsm_stripe_count));
 
-       OBD_ALLOC_LARGE(lsm2, lsm_size);
+       lsm2 = libcfs_kvzalloc(lsm_size, GFP_NOFS);
        if (lsm2 == NULL) {
                rc = -ENOMEM;
                goto out;
@@ -1300,11 +1291,11 @@ static int ll_lov_recreate(struct inode *inode, struct ost_id *oi, u32 ost_idx)
        rc = obd_create(NULL, exp, oa, &lsm2, &oti);
        ll_inode_size_unlock(inode);
 
-       OBD_FREE_LARGE(lsm2, lsm_size);
+       kvfree(lsm2);
        goto out;
 out:
        ccc_inode_lsm_put(inode, lsm);
-       OBDO_FREE(oa);
+       kmem_cache_free(obdo_cachep, oa);
        return rc;
 }
 
@@ -1434,7 +1425,7 @@ int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
         * little endian.  We convert it to host endian before
         * passing it to userspace.
         */
-       if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC)) {
+       if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) {
                int stripe_count;
 
                stripe_count = le16_to_cpu(lmm->lmm_stripe_count);
@@ -1477,12 +1468,12 @@ static int ll_lov_setea(struct inode *inode, struct file *file,
        if (!capable(CFS_CAP_SYS_ADMIN))
                return -EPERM;
 
-       OBD_ALLOC_LARGE(lump, lum_size);
+       lump = libcfs_kvzalloc(lum_size, GFP_NOFS);
        if (lump == NULL)
                return -ENOMEM;
 
        if (copy_from_user(lump, (struct lov_user_md *)arg, lum_size)) {
-               OBD_FREE_LARGE(lump, lum_size);
+               kvfree(lump);
                return -EFAULT;
        }
 
@@ -1490,7 +1481,7 @@ static int ll_lov_setea(struct inode *inode, struct file *file,
                                     lum_size);
        cl_lov_delay_create_clear(&file->f_flags);
 
-       OBD_FREE_LARGE(lump, lum_size);
+       kvfree(lump);
        return rc;
 }
 
@@ -1779,7 +1770,7 @@ int ll_fid2path(struct inode *inode, void __user *arg)
                rc = -EFAULT;
 
 gf_free:
-       OBD_FREE(gfout, outsize);
+       kfree(gfout);
        return rc;
 }
 
@@ -1802,7 +1793,7 @@ static int ll_ioctl_fiemap(struct inode *inode, unsigned long arg)
        num_bytes = sizeof(*fiemap_s) + (extent_count *
                                         sizeof(struct ll_fiemap_extent));
 
-       OBD_ALLOC_LARGE(fiemap_s, num_bytes);
+       fiemap_s = libcfs_kvzalloc(num_bytes, GFP_NOFS);
        if (fiemap_s == NULL)
                return -ENOMEM;
 
@@ -1839,7 +1830,7 @@ static int ll_ioctl_fiemap(struct inode *inode, unsigned long arg)
                rc = -EFAULT;
 
 error:
-       OBD_FREE_LARGE(fiemap_s, num_bytes);
+       kvfree(fiemap_s);
        return rc;
 }
 
@@ -1875,7 +1866,7 @@ int ll_data_version(struct inode *inode, __u64 *data_version,
                goto out;
        }
 
-       rc = ll_lsm_getattr(lsm, sbi->ll_dt_exp, NULL, obdo, 0, extent_lock);
+       rc = ll_lsm_getattr(lsm, sbi->ll_dt_exp, obdo, 0, extent_lock);
        if (rc == 0) {
                if (!(obdo->o_valid & OBD_MD_FLDATAVERSION))
                        rc = -EOPNOTSUPP;
@@ -1883,7 +1874,7 @@ int ll_data_version(struct inode *inode, __u64 *data_version,
                        *data_version = obdo->o_data_version;
        }
 
-       OBD_FREE_PTR(obdo);
+       kfree(obdo);
 out:
        ccc_inode_lsm_put(inode, lsm);
        return rc;
@@ -1900,7 +1891,6 @@ int ll_hsm_release(struct inode *inode)
        __u64 data_version = 0;
        int rc;
 
-
        CDEBUG(D_INODE, "%s: Releasing file "DFID".\n",
               ll_get_fsname(inode->i_sb, NULL, 0),
               PFID(&ll_i2info(inode)->lli_fid));
@@ -1932,7 +1922,6 @@ int ll_hsm_release(struct inode *inode)
                                       &data_version);
        och = NULL;
 
-
 out:
        if (och != NULL && !IS_ERR(och)) /* close the file */
                ll_lease_close(och, inode, NULL);
@@ -2109,8 +2098,7 @@ putgl:
        }
 
 free:
-       if (llss != NULL)
-               OBD_FREE_PTR(llss);
+       kfree(llss);
 
        return rc;
 }
@@ -2120,12 +2108,21 @@ static int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss)
        struct md_op_data       *op_data;
        int                      rc;
 
+       /* Detect out-of range masks */
+       if ((hss->hss_setmask | hss->hss_clearmask) & ~HSM_FLAGS_MASK)
+               return -EINVAL;
+
        /* Non-root users are forbidden to set or clear flags which are
         * NOT defined in HSM_USER_MASK. */
        if (((hss->hss_setmask | hss->hss_clearmask) & ~HSM_USER_MASK) &&
            !capable(CFS_CAP_SYS_ADMIN))
                return -EPERM;
 
+       /* Detect out-of range archive id */
+       if ((hss->hss_valid & HSS_ARCHIVE_ID) &&
+           (hss->hss_archive_id > LL_HSM_MAX_ARCHIVE))
+               return -EINVAL;
+
        op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
                                     LUSTRE_OPC_ANY, hss);
        if (IS_ERR(op_data))
@@ -2146,28 +2143,25 @@ static int ll_hsm_import(struct inode *inode, struct file *file,
        struct iattr            *attr = NULL;
        int                      rc;
 
-
        if (!S_ISREG(inode->i_mode))
                return -EINVAL;
 
        /* set HSM flags */
        hss = kzalloc(sizeof(*hss), GFP_NOFS);
-       if (!hss) {
-               rc = -ENOMEM;
-               goto out;
-       }
+       if (!hss)
+               return -ENOMEM;
 
        hss->hss_valid = HSS_SETMASK | HSS_ARCHIVE_ID;
        hss->hss_archive_id = hui->hui_archive_id;
        hss->hss_setmask = HS_ARCHIVED | HS_EXISTS | HS_RELEASED;
        rc = ll_hsm_state_set(inode, hss);
        if (rc != 0)
-               goto out;
+               goto free_hss;
 
        attr = kzalloc(sizeof(*attr), GFP_NOFS);
        if (!attr) {
                rc = -ENOMEM;
-               goto out;
+               goto free_hss;
        }
 
        attr->ia_mode = hui->hui_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
@@ -2193,13 +2187,9 @@ static int ll_hsm_import(struct inode *inode, struct file *file,
 
        mutex_unlock(&inode->i_mutex);
 
-out:
-       if (hss != NULL)
-               OBD_FREE_PTR(hss);
-
-       if (attr != NULL)
-               OBD_FREE_PTR(attr);
-
+       kfree(attr);
+free_hss:
+       kfree(hss);
        return rc;
 }
 
@@ -2350,7 +2340,7 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
                                             LUSTRE_OPC_ANY, hus);
                if (IS_ERR(op_data)) {
-                       OBD_FREE_PTR(hus);
+                       kfree(hus);
                        return PTR_ERR(op_data);
                }
 
@@ -2361,25 +2351,20 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        rc = -EFAULT;
 
                ll_finish_md_op_data(op_data);
-               OBD_FREE_PTR(hus);
+               kfree(hus);
                return rc;
        }
        case LL_IOC_HSM_STATE_SET: {
                struct hsm_state_set    *hss;
                int                      rc;
 
-               hss = kzalloc(sizeof(*hss), GFP_NOFS);
-               if (!hss)
-                       return -ENOMEM;
-
-               if (copy_from_user(hss, (char *)arg, sizeof(*hss))) {
-                       OBD_FREE_PTR(hss);
-                       return -EFAULT;
-               }
+               hss = memdup_user((char *)arg, sizeof(*hss));
+               if (IS_ERR(hss))
+                       return PTR_ERR(hss);
 
                rc = ll_hsm_state_set(inode, hss);
 
-               OBD_FREE_PTR(hss);
+               kfree(hss);
                return rc;
        }
        case LL_IOC_HSM_ACTION: {
@@ -2394,7 +2379,7 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
                                             LUSTRE_OPC_ANY, hca);
                if (IS_ERR(op_data)) {
-                       OBD_FREE_PTR(hca);
+                       kfree(hca);
                        return PTR_ERR(op_data);
                }
 
@@ -2405,7 +2390,7 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        rc = -EFAULT;
 
                ll_finish_md_op_data(op_data);
-               OBD_FREE_PTR(hca);
+               kfree(hca);
                return rc;
        }
        case LL_IOC_SET_LEASE: {
@@ -2495,25 +2480,20 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case LL_IOC_HSM_IMPORT: {
                struct hsm_user_import *hui;
 
-               hui = kzalloc(sizeof(*hui), GFP_NOFS);
-               if (!hui)
-                       return -ENOMEM;
-
-               if (copy_from_user(hui, (void *)arg, sizeof(*hui))) {
-                       OBD_FREE_PTR(hui);
-                       return -EFAULT;
-               }
+               hui = memdup_user((void *)arg, sizeof(*hui));
+               if (IS_ERR(hui))
+                       return PTR_ERR(hui);
 
                rc = ll_hsm_import(inode, file, hui);
 
-               OBD_FREE_PTR(hui);
+               kfree(hui);
                return rc;
        }
        default: {
                int err;
 
-               if (LLIOC_STOP ==
-                    ll_iocontrol_call(inode, file, cmd, arg, &err))
+               if (ll_iocontrol_call(inode, file, cmd, arg, &err) ==
+                    LLIOC_STOP)
                        return err;
 
                return obd_iocontrol(cmd, ll_i2dtexp(inode), 0, NULL,
@@ -2522,7 +2502,6 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        }
 }
 
-
 static loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
 {
        struct inode *inode = file_inode(file);
@@ -2583,7 +2562,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;
 
@@ -2595,15 +2573,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 = ccc_env_thread_io(env);
        io->ci_obj = cl_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);
@@ -2619,8 +2594,6 @@ 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;
 }
 
@@ -2629,7 +2602,6 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
        struct inode *inode = file_inode(file);
        struct ll_inode_info *lli = ll_i2info(inode);
        struct ptlrpc_request *req;
-       struct obd_capa *oc;
        int rc, err;
 
        CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
@@ -2651,10 +2623,7 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
                        rc = err;
        }
 
-       oc = ll_mdscapa_get(inode);
-       err = md_sync(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode), oc,
-                     &req);
-       capa_put(oc);
+       err = md_sync(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode), &req);
        if (!rc)
                rc = err;
        if (!err)
@@ -2688,7 +2657,7 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
        };
        struct md_op_data *op_data;
        struct lustre_handle lockh = {0};
-       ldlm_policy_data_t flock = {{0}};
+       ldlm_policy_data_t flock = { {0} };
        __u64 flags = 0;
        int rc;
        int rc2 = 0;
@@ -2781,13 +2750,9 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
        rc = md_enqueue(sbi->ll_md_exp, &einfo, NULL,
                        op_data, &lockh, &flock, 0, NULL /* req */, flags);
 
-       if ((file_lock->fl_flags & FL_FLOCK) &&
-           (rc == 0 || file_lock->fl_type == F_UNLCK))
-               rc2  = flock_lock_file_wait(file, file_lock);
-       if ((file_lock->fl_flags & FL_POSIX) &&
-           (rc == 0 || file_lock->fl_type == F_UNLCK) &&
+       if ((rc == 0 || file_lock->fl_type == F_UNLCK) &&
            !(flags & LDLM_FL_TEST_LOCK))
-               rc2  = posix_lock_file_wait(file, file_lock);
+               rc2  = locks_lock_file_wait(file, file_lock);
 
        if (rc2 && file_lock->fl_type != F_UNLCK) {
                einfo.ei_mode = LCK_NL;
@@ -2868,7 +2833,7 @@ ldlm_mode_t ll_take_md_lock(struct inode *inode, __u64 bits,
        fid = &ll_i2info(inode)->lli_fid;
        CDEBUG(D_INFO, "trying to match res "DFID"\n", PFID(fid));
 
-       rc = md_lock_match(ll_i2mdexp(inode), LDLM_FL_BLOCK_GRANTED|flags,
+       rc = md_lock_match(ll_i2mdexp(inode), flags | LDLM_FL_BLOCK_GRANTED,
                           fid, LDLM_IBITS, &policy, mode, lockh);
 
        return rc;
@@ -2972,9 +2937,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) {
@@ -3022,7 +2984,7 @@ int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat)
        struct inode *inode = d_inode(de);
        struct ll_sb_info *sbi = ll_i2sbi(inode);
        struct ll_inode_info *lli = ll_i2info(inode);
-       int res = 0;
+       int res;
 
        res = ll_inode_revalidate(de, MDS_INODELOCK_UPDATE |
                                      MDS_INODELOCK_LOOKUP);
@@ -3062,7 +3024,7 @@ static int ll_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 
        num_bytes = sizeof(*fiemap) + (extent_count *
                                       sizeof(struct ll_fiemap_extent));
-       OBD_ALLOC_LARGE(fiemap, num_bytes);
+       fiemap = libcfs_kvzalloc(num_bytes, GFP_NOFS);
 
        if (fiemap == NULL)
                return -ENOMEM;
@@ -3084,7 +3046,7 @@ static int ll_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
                       fiemap->fm_mapped_extents *
                       sizeof(struct ll_fiemap_extent));
 
-       OBD_FREE_LARGE(fiemap, num_bytes);
+       kvfree(fiemap);
        return rc;
 }
 
@@ -3101,7 +3063,6 @@ struct posix_acl *ll_get_acl(struct inode *inode, int type)
        return acl;
 }
 
-
 int ll_inode_permission(struct inode *inode, int mask)
 {
        int rc = 0;
@@ -3199,7 +3160,6 @@ static struct llioc_ctl_data {
        LIST_HEAD_INIT(llioc.ioc_head)
 };
 
-
 struct llioc_data {
        struct list_head              iocd_list;
        unsigned int        iocd_size;
@@ -3246,12 +3206,10 @@ void ll_iocontrol_unregister(void *magic)
        down_write(&llioc.ioc_sem);
        list_for_each_entry(tmp, &llioc.ioc_head, iocd_list) {
                if (tmp == magic) {
-                       unsigned int size = tmp->iocd_size;
-
                        list_del(&tmp->iocd_list);
                        up_write(&llioc.ioc_sem);
 
-                       OBD_FREE(tmp, size);
+                       kfree(tmp);
                        return;
                }
        }
@@ -3327,7 +3285,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;
@@ -3347,13 +3304,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,
-                               OBD_MD_FLXATTR, XATTR_NAME_LOV, NULL, 0,
-                               lmmsize, 0, &req);
-       capa_put(oc);
+               rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode),
+                                OBD_MD_FLXATTR, XATTR_NAME_LOV, NULL, 0,
+                                lmmsize, 0, &req);
        if (rc < 0)
                return rc;
 
@@ -3375,7 +3330,7 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
                goto out;
        }
 
-       OBD_ALLOC_LARGE(lvbdata, lmmsize);
+       lvbdata = libcfs_kvzalloc(lmmsize, GFP_NOFS);
        if (lvbdata == NULL) {
                rc = -ENOMEM;
                goto out;
@@ -3384,7 +3339,7 @@ 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);
+               kvfree(lock->l_lvb_data);
 
        lock->l_lvb_data = lvbdata;
        lock->l_lvb_len = lmmsize;
@@ -3619,6 +3574,6 @@ int ll_layout_restore(struct inode *inode)
        hur->hur_request.hr_itemcount = 1;
        rc = obd_iocontrol(LL_IOC_HSM_REQUEST, cl_i2sbi(inode)->ll_md_exp,
                           len, hur, NULL);
-       OBD_FREE(hur, len);
+       kfree(hur);
        return rc;
 }