Whamcloud - gitweb
LU-9206 llite: access striped directory with missing stripe
[fs/lustre-release.git] / lustre / llite / dir.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lustre/llite/dir.c
32  *
33  * Directory code for lustre client.
34  */
35
36 #include <linux/fs.h>
37 #include <linux/pagemap.h>
38 #include <linux/mm.h>
39 #include <linux/version.h>
40 #include <linux/security.h>
41 #include <linux/user_namespace.h>
42 #include <linux/uidgid.h>
43 #include <linux/uaccess.h>
44 #include <linux/buffer_head.h>   // for wait_on_buffer
45 #include <linux/pagevec.h>
46
47 #define DEBUG_SUBSYSTEM S_LLITE
48
49 #include <obd_support.h>
50 #include <obd_class.h>
51 #include <uapi/linux/lustre/lustre_ioctl.h>
52 #include <uapi/linux/llcrypt.h>
53 #include <lustre_lib.h>
54 #include <lustre_dlm.h>
55 #include <lustre_fid.h>
56 #include <lustre_kernelcomm.h>
57 #include <lustre_swab.h>
58 #include <libcfs/libcfs_crypto.h>
59
60 #include "llite_internal.h"
61
62 /*
63  * (new) readdir implementation overview.
64  *
65  * Original lustre readdir implementation cached exact copy of raw directory
66  * pages on the client. These pages were indexed in client page cache by
67  * logical offset in the directory file. This design, while very simple and
68  * intuitive had some inherent problems:
69  *
70  *     . it implies that byte offset to the directory entry serves as a
71  *     telldir(3)/seekdir(3) cookie, but that offset is not stable: in
72  *     ext3/htree directory entries may move due to splits, and more
73  *     importantly,
74  *
75  *     . it is incompatible with the design of split directories for cmd3,
76  *     that assumes that names are distributed across nodes based on their
77  *     hash, and so readdir should be done in hash order.
78  *
79  * New readdir implementation does readdir in hash order, and uses hash of a
80  * file name as a telldir/seekdir cookie. This led to number of complications:
81  *
82  *     . hash is not unique, so it cannot be used to index cached directory
83  *     pages on the client (note, that it requires a whole pageful of hash
84  *     collided entries to cause two pages to have identical hashes);
85  *
86  *     . hash is not unique, so it cannot, strictly speaking, be used as an
87  *     entry cookie. ext3/htree has the same problem and lustre implementation
88  *     mimics their solution: seekdir(hash) positions directory at the first
89  *     entry with the given hash.
90  *
91  * Client side.
92  *
93  * 0. caching
94  *
95  * Client caches directory pages using hash of the first entry as an index. As
96  * noted above hash is not unique, so this solution doesn't work as is:
97  * special processing is needed for "page hash chains" (i.e., sequences of
98  * pages filled with entries all having the same hash value).
99  *
100  * First, such chains have to be detected. To this end, server returns to the
101  * client the hash of the first entry on the page next to one returned. When
102  * client detects that this hash is the same as hash of the first entry on the
103  * returned page, page hash collision has to be handled. Pages in the
104  * hash chain, except first one, are termed "overflow pages".
105  *
106  * Proposed (unimplimented) solution to index uniqueness problem is to
107  * not cache overflow pages.  Instead, when page hash collision is
108  * detected, all overflow pages from emerging chain should be
109  * immediately requested from the server and placed in a special data
110  * structure.  This data structure can be used by ll_readdir() to
111  * process entries from overflow pages.  When readdir invocation
112  * finishes, overflow pages are discarded.  If page hash collision chain
113  * weren't completely processed, next call to readdir will again detect
114  * page hash collision, again read overflow pages in, process next
115  * portion of entries and again discard the pages.  This is not as
116  * wasteful as it looks, because, given reasonable hash, page hash
117  * collisions are extremely rare.
118  *
119  * 1. directory positioning
120  *
121  * When seekdir(hash) is called, original
122  *
123  *
124  *
125  *
126  *
127  *
128  *
129  *
130  * Server.
131  *
132  * identification of and access to overflow pages
133  *
134  * page format
135  *
136  * Page in MDS_READPAGE RPC is packed in LU_PAGE_SIZE, and each page contains
137  * a header lu_dirpage which describes the start/end hash, and whether this
138  * page is empty (contains no dir entry) or hash collide with next page.
139  * After client receives reply, several pages will be integrated into dir page
140  * in PAGE_SIZE (if PAGE_SIZE greater than LU_PAGE_SIZE), and the
141  * lu_dirpage for this integrated page will be adjusted. See
142  * mdc_adjust_dirpages().
143  *
144  */
145 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
146                              __u64 offset, int *partial_readdir_rc)
147 {
148         struct md_readdir_info mrinfo = {
149                                         .mr_blocking_ast = ll_md_blocking_ast };
150         struct page *page;
151         int rc;
152
153         rc = md_read_page(ll_i2mdexp(dir), op_data, &mrinfo, offset, &page);
154         if (rc != 0)
155                 return ERR_PTR(rc);
156
157         if (partial_readdir_rc && mrinfo.mr_partial_readdir_rc)
158                 *partial_readdir_rc = mrinfo.mr_partial_readdir_rc;
159
160         return page;
161 }
162
163 void ll_release_page(struct inode *inode, struct page *page,
164                      bool remove)
165 {
166         kunmap(page);
167
168         /* Always remove the page for striped dir, because the page is
169          * built from temporarily in LMV layer */
170         if (inode && ll_dir_striped(inode)) {
171                 __free_page(page);
172                 return;
173         }
174
175         if (remove) {
176                 lock_page(page);
177                 if (likely(page->mapping != NULL))
178                         delete_from_page_cache(page);
179                 unlock_page(page);
180         }
181         put_page(page);
182 }
183
184 #ifdef HAVE_DIR_CONTEXT
185 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
186                 struct dir_context *ctx, int *partial_readdir_rc)
187 {
188 #else
189 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
190                 void *cookie, filldir_t filldir, int *partial_readdir_rc)
191 {
192 #endif
193         struct ll_sb_info *sbi = ll_i2sbi(inode);
194         __u64 pos = *ppos;
195         bool is_api32 = ll_need_32bit_api(sbi);
196         bool is_hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
197         struct page *page;
198         bool done = false;
199         struct llcrypt_str lltr = LLTR_INIT(NULL, 0);
200         int rc = 0;
201         ENTRY;
202
203         if (IS_ENCRYPTED(inode)) {
204                 rc = llcrypt_fname_alloc_buffer(inode, NAME_MAX, &lltr);
205                 if (rc < 0)
206                         RETURN(rc);
207         }
208
209         page = ll_get_dir_page(inode, op_data, pos, partial_readdir_rc);
210
211         while (rc == 0 && !done) {
212                 struct lu_dirpage *dp;
213                 struct lu_dirent  *ent;
214                 __u64 hash;
215                 __u64 next;
216
217                 if (IS_ERR(page)) {
218                         rc = PTR_ERR(page);
219                         break;
220                 }
221
222                 hash = MDS_DIR_END_OFF;
223                 dp = page_address(page);
224                 for (ent = lu_dirent_start(dp); ent != NULL && !done;
225                      ent = lu_dirent_next(ent)) {
226                         __u16          type;
227                         int            namelen;
228                         struct lu_fid  fid;
229                         __u64          lhash;
230                         __u64          ino;
231
232                         hash = le64_to_cpu(ent->lde_hash);
233                         if (hash < pos) /* Skip until we find target hash */
234                                 continue;
235
236                         namelen = le16_to_cpu(ent->lde_namelen);
237                         if (namelen == 0) /* Skip dummy record */
238                                 continue;
239
240                         if (is_api32 && is_hash64)
241                                 lhash = hash >> 32;
242                         else
243                                 lhash = hash;
244                         fid_le_to_cpu(&fid, &ent->lde_fid);
245                         ino = cl_fid_build_ino(&fid, is_api32);
246                         type = S_DT(lu_dirent_type_get(ent));
247                         /* For ll_nfs_get_name_filldir(), it will try to access
248                          * 'ent' through 'lde_name', so the parameter 'name'
249                          * for 'filldir()' must be part of the 'ent'. */
250 #ifdef HAVE_DIR_CONTEXT
251                         ctx->pos = lhash;
252                         if (!IS_ENCRYPTED(inode)) {
253                                 done = !dir_emit(ctx, ent->lde_name, namelen,
254                                                  ino, type);
255                         } else {
256                                 /* Directory is encrypted */
257                                 int save_len = lltr.len;
258                                 struct llcrypt_str de_name =
259                                         LLTR_INIT(ent->lde_name, namelen);
260
261                                 rc = ll_fname_disk_to_usr(inode, 0, 0, &de_name,
262                                                           &lltr, &fid);
263                                 de_name = lltr;
264                                 lltr.len = save_len;
265                                 if (rc) {
266                                         done = 1;
267                                         break;
268                                 }
269                                 done = !dir_emit(ctx, de_name.name, de_name.len,
270                                                  ino, type);
271                         }
272 #else
273                         /* HAVE_DIR_CONTEXT is defined from kernel 3.11, whereas
274                          * IS_ENCRYPTED is brought by kernel 4.14.
275                          * So there is no need to handle encryption case here.
276                          */
277                         done = filldir(cookie, ent->lde_name, namelen, lhash,
278                                        ino, type);
279 #endif
280                 }
281
282                 if (done) {
283                         pos = hash;
284                         ll_release_page(inode, page, false);
285                         break;
286                 }
287
288                 next = le64_to_cpu(dp->ldp_hash_end);
289                 pos = next;
290                 if (pos == MDS_DIR_END_OFF) {
291                         /*
292                          * End of directory reached.
293                          */
294                         done = 1;
295                         ll_release_page(inode, page, false);
296                 } else {
297                         /*
298                          * Normal case: continue to the next
299                          * page.
300                          */
301                         ll_release_page(inode, page,
302                                         le32_to_cpu(dp->ldp_flags) &
303                                         LDF_COLLIDE);
304                         next = pos;
305                         page = ll_get_dir_page(inode, op_data, pos,
306                                                partial_readdir_rc);
307                 }
308         }
309 #ifdef HAVE_DIR_CONTEXT
310         ctx->pos = pos;
311 #else
312         *ppos = pos;
313 #endif
314         llcrypt_fname_free_buffer(&lltr);
315         RETURN(rc);
316 }
317
318 #ifdef HAVE_DIR_CONTEXT
319 static int ll_iterate(struct file *filp, struct dir_context *ctx)
320 #else
321 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
322 #endif
323 {
324         struct inode *inode = file_inode(filp);
325         struct ll_file_data *lfd = filp->private_data;
326         struct ll_sb_info *sbi = ll_i2sbi(inode);
327         bool hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
328         int api32 = ll_need_32bit_api(sbi);
329         struct md_op_data *op_data;
330         struct lu_fid pfid = { 0 };
331         ktime_t kstart = ktime_get();
332         /* result of possible partial readdir */
333         int partial_readdir_rc = 0;
334         __u64 pos;
335         int rc;
336
337         ENTRY;
338
339         LASSERT(lfd != NULL);
340         pos = lfd->lfd_pos;
341
342         CDEBUG(D_VFSTRACE,
343                "VFS Op:inode="DFID"(%p) pos/size%lu/%llu 32bit_api %d\n",
344                PFID(ll_inode2fid(inode)),
345                inode, (unsigned long)pos, i_size_read(inode), api32);
346
347         if (IS_ENCRYPTED(inode)) {
348                 rc = llcrypt_get_encryption_info(inode);
349                 if (rc && rc != -ENOKEY)
350                         GOTO(out, rc);
351         }
352
353         if (pos == MDS_DIR_END_OFF)
354                 /*
355                  * end-of-file.
356                  */
357                 GOTO(out, rc = 0);
358
359         if (unlikely(ll_dir_striped(inode))) {
360                 /*
361                  * This is only needed for striped dir to fill ..,
362                  * see lmv_read_page()
363                  */
364                 if (file_dentry(filp)->d_parent != NULL &&
365                     file_dentry(filp)->d_parent->d_inode != NULL) {
366                         __u64 ibits = MDS_INODELOCK_LOOKUP;
367                         struct inode *parent =
368                                 file_dentry(filp)->d_parent->d_inode;
369
370                         if (ll_have_md_lock(parent, &ibits, LCK_MINMODE))
371                                 pfid = *ll_inode2fid(parent);
372                 }
373
374                 /* If it can not find in cache, do lookup .. on the master
375                  * object */
376                 if (fid_is_zero(&pfid)) {
377                         rc = ll_dir_get_parent_fid(inode, &pfid);
378                         if (rc != 0)
379                                 RETURN(rc);
380                 }
381         }
382
383         op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
384                                      LUSTRE_OPC_ANY, inode);
385         if (IS_ERR(op_data))
386                 GOTO(out, rc = PTR_ERR(op_data));
387
388         /* foreign dirs are browsed out of Lustre */
389         if (unlikely(op_data->op_mea1 != NULL &&
390                      op_data->op_mea1->lsm_md_magic == LMV_MAGIC_FOREIGN)) {
391                 ll_finish_md_op_data(op_data);
392                 RETURN(-ENODATA);
393         }
394
395         op_data->op_fid3 = pfid;
396
397 #ifdef HAVE_DIR_CONTEXT
398         ctx->pos = pos;
399         rc = ll_dir_read(inode, &pos, op_data, ctx, &partial_readdir_rc);
400         pos = ctx->pos;
401 #else
402         rc = ll_dir_read(inode, &pos, op_data, cookie, filldir,
403                          &partial_readdir_rc);
404 #endif
405         lfd->lfd_pos = pos;
406         if (!lfd->fd_partial_readdir_rc)
407                 lfd->fd_partial_readdir_rc = partial_readdir_rc;
408
409         if (pos == MDS_DIR_END_OFF) {
410                 if (api32)
411                         pos = LL_DIR_END_OFF_32BIT;
412                 else
413                         pos = LL_DIR_END_OFF;
414         } else {
415                 if (api32 && hash64)
416                         pos = pos >> 32;
417         }
418 #ifdef HAVE_DIR_CONTEXT
419         ctx->pos = pos;
420 #else
421         filp->f_pos = pos;
422 #endif
423         ll_finish_md_op_data(op_data);
424
425 out:
426         if (!rc)
427                 ll_stats_ops_tally(sbi, LPROC_LL_READDIR,
428                                    ktime_us_delta(ktime_get(), kstart));
429
430         RETURN(rc);
431 }
432
433 /**
434  * Create striped directory with specified stripe(@lump)
435  *
436  * \param[in] dparent   the parent of the directory.
437  * \param[in] lump      the specified stripes.
438  * \param[in] dirname   the name of the directory.
439  * \param[in] mode      the specified mode of the directory.
440  *
441  * \retval              =0 if striped directory is being created successfully.
442  *                      <0 if the creation is failed.
443  */
444 static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
445                                size_t len, const char *dirname, umode_t mode,
446                                bool createonly)
447 {
448         struct inode *parent = dparent->d_inode;
449         struct ptlrpc_request *request = NULL;
450         struct md_op_data *op_data;
451         struct ll_sb_info *sbi = ll_i2sbi(parent);
452         struct inode *inode = NULL;
453         struct dentry dentry = {
454                 .d_parent = dparent,
455                 .d_name = {
456                         .name = dirname,
457                         .len = strlen(dirname),
458                         .hash = ll_full_name_hash(dparent, dirname,
459                                                   strlen(dirname)),
460                 },
461         };
462         bool encrypt = false;
463         int hash_flags;
464         int err;
465
466         ENTRY;
467         if (unlikely(!lmv_user_magic_supported(lump->lum_magic)))
468                 RETURN(-EINVAL);
469
470         if (lump->lum_magic != LMV_MAGIC_FOREIGN) {
471                 CDEBUG(D_VFSTRACE,
472                        "VFS Op:inode="DFID"(%p) name %s stripe_offset %d, stripe_count: %u\n",
473                        PFID(ll_inode2fid(parent)), parent, dirname,
474                        (int)lump->lum_stripe_offset, lump->lum_stripe_count);
475         } else {
476                 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lump;
477
478                 CDEBUG(D_VFSTRACE,
479                        "VFS Op:inode="DFID"(%p) name %s foreign, length %u, value '%.*s'\n",
480                        PFID(ll_inode2fid(parent)), parent, dirname,
481                        lfm->lfm_length, lfm->lfm_length, lfm->lfm_value);
482         }
483
484         if (lump->lum_stripe_count > 1 &&
485             !(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_DIR_STRIPE))
486                 RETURN(-EINVAL);
487
488         if (IS_DEADDIR(parent) &&
489             !OBD_FAIL_CHECK(OBD_FAIL_LLITE_NO_CHECK_DEAD))
490                 RETURN(-ENOENT);
491
492         /* MDS < 2.14 doesn't support 'crush' hash type, and cannot handle
493          * unknown hash if client doesn't set a valid one. switch to fnv_1a_64.
494          */
495         if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) {
496                 enum lmv_hash_type type = lump->lum_hash_type &
497                                           LMV_HASH_TYPE_MASK;
498
499                 if (type == LMV_HASH_TYPE_CRUSH ||
500                     type == LMV_HASH_TYPE_UNKNOWN)
501                         lump->lum_hash_type = (lump->lum_hash_type ^ type) |
502                                               LMV_HASH_TYPE_FNV_1A_64;
503         }
504
505         hash_flags = lump->lum_hash_type & ~LMV_HASH_TYPE_MASK;
506         if (hash_flags & ~LMV_HASH_FLAG_KNOWN)
507                 RETURN(-EINVAL);
508
509         if (unlikely(!lmv_user_magic_supported(cpu_to_le32(lump->lum_magic))))
510                 lustre_swab_lmv_user_md(lump);
511
512         if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
513                 mode &= ~current_umask();
514         mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
515         op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
516                                      strlen(dirname), mode, LUSTRE_OPC_MKDIR,
517                                      lump);
518         if (IS_ERR(op_data))
519                 RETURN(PTR_ERR(op_data));
520
521         op_data->op_dir_depth = ll_i2info(parent)->lli_dir_depth;
522
523         if (ll_sbi_has_encrypt(sbi) &&
524             (IS_ENCRYPTED(parent) ||
525             unlikely(llcrypt_dummy_context_enabled(parent)))) {
526                 err = llcrypt_get_encryption_info(parent);
527                 if (err)
528                         GOTO(out_op_data, err);
529                 if (!llcrypt_has_encryption_key(parent))
530                         GOTO(out_op_data, err = -ENOKEY);
531                 encrypt = true;
532         }
533
534         if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
535                 /* selinux_dentry_init_security() uses dentry->d_parent and name
536                  * to determine the security context for the file. So our fake
537                  * dentry should be real enough for this purpose. */
538                 err = ll_dentry_init_security(&dentry, mode, &dentry.d_name,
539                                               &op_data->op_file_secctx_name,
540                                               &op_data->op_file_secctx,
541                                               &op_data->op_file_secctx_size);
542                 if (err < 0)
543                         GOTO(out_op_data, err);
544         }
545
546         if (encrypt) {
547                 err = llcrypt_inherit_context(parent, NULL, op_data, false);
548                 if (err)
549                         GOTO(out_op_data, err);
550         }
551
552         op_data->op_cli_flags |= CLI_SET_MEA;
553         if (createonly)
554                 op_data->op_bias |= MDS_SETSTRIPE_CREATE;
555
556         err = md_create(sbi->ll_md_exp, op_data, lump, len, mode,
557                         from_kuid(&init_user_ns, current_fsuid()),
558                         from_kgid(&init_user_ns, current_fsgid()),
559                         current_cap(), 0, &request);
560         if (err)
561                 GOTO(out_request, err);
562
563         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_SETDIRSTRIPE_PAUSE, cfs_fail_val);
564
565         err = ll_prep_inode(&inode, &request->rq_pill, parent->i_sb, NULL);
566         if (err)
567                 GOTO(out_inode, err);
568
569         dentry.d_inode = inode;
570
571         if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
572                 /* no need to protect selinux_inode_setsecurity() by
573                  * inode_lock. Taking it would lead to a client deadlock
574                  * LU-13617
575                  */
576                 err = security_inode_notifysecctx(inode,
577                                                   op_data->op_file_secctx,
578                                                   op_data->op_file_secctx_size);
579         } else {
580                 err = ll_inode_init_security(&dentry, inode, parent);
581         }
582         if (err)
583                 GOTO(out_inode, err);
584
585         if (encrypt) {
586                 err = ll_set_encflags(inode, op_data->op_file_encctx,
587                                       op_data->op_file_encctx_size, false);
588                 if (err)
589                         GOTO(out_inode, err);
590         }
591
592 out_inode:
593         iput(inode);
594 out_request:
595         ptlrpc_req_finished(request);
596 out_op_data:
597         ll_finish_md_op_data(op_data);
598
599         return err;
600 }
601
602 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
603                      int set_default)
604 {
605         struct ll_sb_info *sbi = ll_i2sbi(inode);
606         struct md_op_data *op_data;
607         struct ptlrpc_request *req = NULL;
608         int rc = 0;
609         int lum_size;
610         ENTRY;
611
612         if (lump != NULL) {
613                 switch (lump->lmm_magic) {
614                 case LOV_USER_MAGIC_V1:
615                         lum_size = sizeof(struct lov_user_md_v1);
616                         break;
617                 case LOV_USER_MAGIC_V3:
618                         lum_size = sizeof(struct lov_user_md_v3);
619                         break;
620                 case LOV_USER_MAGIC_COMP_V1:
621                         lum_size = ((struct lov_comp_md_v1 *)lump)->lcm_size;
622                         break;
623                 case LMV_USER_MAGIC:
624                         if (lump->lmm_magic != cpu_to_le32(LMV_USER_MAGIC))
625                                 lustre_swab_lmv_user_md(
626                                         (struct lmv_user_md *)lump);
627                         lum_size = sizeof(struct lmv_user_md);
628                         break;
629                 case LOV_USER_MAGIC_SPECIFIC: {
630                         struct lov_user_md_v3 *v3 =
631                                 (struct lov_user_md_v3 *)lump;
632                         if (v3->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
633                                 RETURN(-EINVAL);
634                         lum_size = lov_user_md_size(v3->lmm_stripe_count,
635                                                     LOV_USER_MAGIC_SPECIFIC);
636                         break;
637                 }
638                 default:
639                         CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
640                                         " %#08x != %#08x nor %#08x\n",
641                                         lump->lmm_magic, LOV_USER_MAGIC_V1,
642                                         LOV_USER_MAGIC_V3);
643                         RETURN(-EINVAL);
644                 }
645
646                 /*
647                  * This is coming from userspace, so should be in
648                  * local endian.  But the MDS would like it in little
649                  * endian, so we swab it before we send it.
650                  */
651                 if ((__swab32(lump->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) ==
652                     le32_to_cpu(LOV_MAGIC_MAGIC))
653                         lustre_swab_lov_user_md(lump, 0);
654         } else {
655                 lum_size = sizeof(struct lov_user_md_v1);
656         }
657
658         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
659                                      LUSTRE_OPC_ANY, NULL);
660         if (IS_ERR(op_data))
661                 RETURN(PTR_ERR(op_data));
662
663         /* swabbing is done in lov_setstripe() on server side */
664         rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req);
665         ll_finish_md_op_data(op_data);
666         ptlrpc_req_finished(req);
667         if (rc)
668                 RETURN(rc);
669
670         RETURN(rc);
671 }
672
673 static int ll_dir_get_default_layout(struct inode *inode, void **plmm,
674                                      int *plmm_size,
675                                      struct ptlrpc_request **request, u64 valid,
676                                      enum get_default_layout_type type)
677 {
678         struct ll_sb_info *sbi = ll_i2sbi(inode);
679         struct mdt_body   *body;
680         struct lov_mds_md *lmm = NULL;
681         struct ptlrpc_request *req = NULL;
682         int rc, lmm_size;
683         struct md_op_data *op_data;
684         struct lu_fid fid;
685         ENTRY;
686
687         rc = ll_get_default_mdsize(sbi, &lmm_size);
688         if (rc)
689                 RETURN(rc);
690
691         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
692                                      0, lmm_size, LUSTRE_OPC_ANY,
693                                      NULL);
694         if (IS_ERR(op_data))
695                 RETURN(PTR_ERR(op_data));
696
697         op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
698
699         if (type == GET_DEFAULT_LAYOUT_ROOT) {
700                 lu_root_fid(&op_data->op_fid1);
701                 fid = op_data->op_fid1;
702         } else {
703                 fid = *ll_inode2fid(inode);
704         }
705
706         rc = md_getattr(sbi->ll_md_exp, op_data, &req);
707         ll_finish_md_op_data(op_data);
708         if (rc < 0) {
709                 CDEBUG(D_INFO, "md_getattr failed on inode "DFID": rc %d\n",
710                        PFID(&fid), rc);
711                 GOTO(out, rc);
712         }
713
714         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
715         LASSERT(body != NULL);
716
717         lmm_size = body->mbo_eadatasize;
718
719         if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
720             lmm_size == 0) {
721                 GOTO(out, rc = -ENODATA);
722         }
723
724         lmm = req_capsule_server_sized_get(&req->rq_pill,
725                                            &RMF_MDT_MD, lmm_size);
726         LASSERT(lmm != NULL);
727
728         /*
729          * This is coming from the MDS, so is probably in
730          * little endian.  We convert it to host endian before
731          * passing it to userspace.
732          */
733         /* We don't swab objects for directories */
734         switch (le32_to_cpu(lmm->lmm_magic)) {
735         case LOV_MAGIC_V1:
736         case LOV_MAGIC_V3:
737         case LOV_MAGIC_COMP_V1:
738         case LOV_USER_MAGIC_SPECIFIC:
739                 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
740                         lustre_swab_lov_user_md((struct lov_user_md *)lmm, 0);
741                 break;
742         case LMV_MAGIC_V1:
743                 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
744                         lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
745                 break;
746         case LMV_USER_MAGIC:
747                 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
748                         lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
749                 break;
750         case LMV_MAGIC_FOREIGN: {
751                 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lmm;
752
753                 if (LMV_MAGIC_FOREIGN != cpu_to_le32(LMV_MAGIC_FOREIGN)) {
754                         __swab32s(&lfm->lfm_magic);
755                         __swab32s(&lfm->lfm_length);
756                         __swab32s(&lfm->lfm_type);
757                         __swab32s(&lfm->lfm_flags);
758                 }
759                 break;
760         }
761         default:
762                 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
763                 rc = -EPROTO;
764         }
765 out:
766         *plmm = lmm;
767         *plmm_size = lmm_size;
768         *request = req;
769         return rc;
770 }
771
772 /**
773  * This function will be used to get default LOV/LMV/Default LMV
774  * @valid will be used to indicate which stripe it will retrieve.
775  * If the directory does not have its own default layout, then the
776  * function will request the default layout from root FID.
777  *      OBD_MD_MEA              LMV stripe EA
778  *      OBD_MD_DEFAULT_MEA      Default LMV stripe EA
779  *      otherwise               Default LOV EA.
780  * Each time, it can only retrieve 1 stripe EA
781  **/
782 int ll_dir_getstripe_default(struct inode *inode, void **plmm, int *plmm_size,
783                              struct ptlrpc_request **request,
784                              struct ptlrpc_request **root_request,
785                              u64 valid)
786 {
787         struct ptlrpc_request *req = NULL;
788         struct ptlrpc_request *root_req = NULL;
789         struct lov_mds_md *lmm = NULL;
790         int lmm_size = 0;
791         int rc = 0;
792         ENTRY;
793
794         rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
795                                        &req, valid, 0);
796         if (rc == -ENODATA && !fid_is_root(ll_inode2fid(inode)) &&
797             !(valid & (OBD_MD_MEA|OBD_MD_DEFAULT_MEA)) && root_request != NULL){
798                 int rc2 = ll_dir_get_default_layout(inode, (void **)&lmm,
799                                                     &lmm_size, &root_req, valid,
800                                                     GET_DEFAULT_LAYOUT_ROOT);
801                 if (rc2 == 0)
802                         rc = 0;
803         }
804
805         *plmm = lmm;
806         *plmm_size = lmm_size;
807         *request = req;
808         if (root_request != NULL)
809                 *root_request = root_req;
810
811         RETURN(rc);
812 }
813
814 /**
815  * This function will be used to get default LOV/LMV/Default LMV
816  * @valid will be used to indicate which stripe it will retrieve
817  *      OBD_MD_MEA              LMV stripe EA
818  *      OBD_MD_DEFAULT_MEA      Default LMV stripe EA
819  *      otherwise               Default LOV EA.
820  * Each time, it can only retrieve 1 stripe EA
821  **/
822 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
823                      struct ptlrpc_request **request, u64 valid)
824 {
825         struct ptlrpc_request *req = NULL;
826         struct lov_mds_md *lmm = NULL;
827         int lmm_size = 0;
828         int rc = 0;
829         ENTRY;
830
831         rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
832                                        &req, valid, 0);
833
834         *plmm = lmm;
835         *plmm_size = lmm_size;
836         *request = req;
837
838         RETURN(rc);
839 }
840
841 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
842 {
843         struct md_op_data       *op_data;
844         int                     rc;
845         int                     mdt_index;
846         ENTRY;
847
848         OBD_ALLOC_PTR(op_data);
849         if (op_data == NULL)
850                 RETURN(-ENOMEM);
851
852         op_data->op_flags |= MF_GET_MDT_IDX;
853         op_data->op_fid1 = *fid;
854         rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
855         mdt_index = op_data->op_mds;
856         OBD_FREE_PTR(op_data);
857         if (rc < 0)
858                 RETURN(rc);
859
860         RETURN(mdt_index);
861 }
862
863 /*
864  *  Get MDT index for the inode.
865  */
866 int ll_get_mdt_idx(struct inode *inode)
867 {
868         return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
869 }
870
871 /**
872  * Generic handler to do any pre-copy work.
873  *
874  * It sends a first hsm_progress (with extent length == 0) to coordinator as a
875  * first information for it that real work has started.
876  *
877  * Moreover, for a ARCHIVE request, it will sample the file data version and
878  * store it in \a copy.
879  *
880  * \return 0 on success.
881  */
882 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
883 {
884         struct ll_sb_info               *sbi = ll_s2sbi(sb);
885         struct hsm_progress_kernel       hpk;
886         int                              rc = 0;
887         int                              rc2;
888         ENTRY;
889
890         /* Forge a hsm_progress based on data from copy. */
891         hpk.hpk_fid = copy->hc_hai.hai_fid;
892         hpk.hpk_cookie = copy->hc_hai.hai_cookie;
893         hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
894         hpk.hpk_extent.length = 0;
895         hpk.hpk_flags = 0;
896         hpk.hpk_errval = 0;
897         hpk.hpk_data_version = 0;
898
899
900         /* For archive request, we need to read the current file version. */
901         if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
902                 struct inode    *inode;
903                 __u64            data_version = 0;
904
905                 /* Get inode for this fid */
906                 inode = search_inode_for_lustre(sb, &copy->hc_hai.hai_fid);
907                 if (IS_ERR(inode)) {
908                         hpk.hpk_flags |= HP_FLAG_RETRY;
909                         /* hpk_errval is >= 0 */
910                         hpk.hpk_errval = -PTR_ERR(inode);
911                         GOTO(progress, rc = PTR_ERR(inode));
912                 }
913
914                 /* Read current file data version */
915                 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
916                 iput(inode);
917                 if (rc != 0) {
918                         CDEBUG(D_HSM, "Could not read file data version of "
919                                       DFID" (rc = %d). Archive request ("
920                                       "%#llx) could not be done.\n",
921                                       PFID(&copy->hc_hai.hai_fid), rc,
922                                       copy->hc_hai.hai_cookie);
923                         hpk.hpk_flags |= HP_FLAG_RETRY;
924                         /* hpk_errval must be >= 0 */
925                         hpk.hpk_errval = -rc;
926                         GOTO(progress, rc);
927                 }
928
929                 /* Store in the hsm_copy for later copytool use.
930                  * Always modified even if no lsm. */
931                 copy->hc_data_version = data_version;
932         }
933
934 progress:
935         /* On error, the request should be considered as completed */
936         if (hpk.hpk_errval > 0)
937                 hpk.hpk_flags |= HP_FLAG_COMPLETED;
938
939         rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
940                             &hpk, NULL);
941
942         /* Return first error */
943         RETURN(rc != 0 ? rc : rc2);
944 }
945
946 /**
947  * Generic handler to do any post-copy work.
948  *
949  * It will send the last hsm_progress update to coordinator to inform it
950  * that copy is finished and whether it was successful or not.
951  *
952  * Moreover,
953  * - for ARCHIVE request, it will sample the file data version and compare it
954  *   with the version saved in ll_ioc_copy_start(). If they do not match, copy
955  *   will be considered as failed.
956  * - for RESTORE request, it will sample the file data version and send it to
957  *   coordinator which is useful if the file was imported as 'released'.
958  *
959  * \return 0 on success.
960  */
961 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
962 {
963         struct ll_sb_info               *sbi = ll_s2sbi(sb);
964         struct hsm_progress_kernel       hpk;
965         int                              rc = 0;
966         int                              rc2;
967         ENTRY;
968
969         /* If you modify the logic here, also check llapi_hsm_copy_end(). */
970         /* Take care: copy->hc_hai.hai_action, len, gid and data are not
971          * initialized if copy_end was called with copy == NULL.
972          */
973
974         /* Forge a hsm_progress based on data from copy. */
975         hpk.hpk_fid = copy->hc_hai.hai_fid;
976         hpk.hpk_cookie = copy->hc_hai.hai_cookie;
977         hpk.hpk_extent = copy->hc_hai.hai_extent;
978         hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
979         hpk.hpk_errval = copy->hc_errval;
980         hpk.hpk_data_version = 0;
981
982         /* For archive request, we need to check the file data was not changed.
983          *
984          * For restore request, we need to send the file data version, this is
985          * useful when the file was created using hsm_import.
986          */
987         if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
988              (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
989             (copy->hc_errval == 0)) {
990                 struct inode    *inode;
991                 __u64            data_version = 0;
992
993                 /* Get lsm for this fid */
994                 inode = search_inode_for_lustre(sb, &copy->hc_hai.hai_fid);
995                 if (IS_ERR(inode)) {
996                         hpk.hpk_flags |= HP_FLAG_RETRY;
997                         /* hpk_errval must be >= 0 */
998                         hpk.hpk_errval = -PTR_ERR(inode);
999                         GOTO(progress, rc = PTR_ERR(inode));
1000                 }
1001
1002                 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
1003                 iput(inode);
1004                 if (rc) {
1005                         CDEBUG(D_HSM, "Could not read file data version. "
1006                                       "Request could not be confirmed.\n");
1007                         if (hpk.hpk_errval == 0)
1008                                 hpk.hpk_errval = -rc;
1009                         GOTO(progress, rc);
1010                 }
1011
1012                 /* Store in the hsm_copy for later copytool use.
1013                  * Always modified even if no lsm. */
1014                 hpk.hpk_data_version = data_version;
1015
1016                 /* File could have been stripped during archiving, so we need
1017                  * to check anyway. */
1018                 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
1019                     (copy->hc_data_version != data_version)) {
1020                         CDEBUG(D_HSM, "File data version mismatched. "
1021                               "File content was changed during archiving. "
1022                                DFID", start:%#llx current:%#llx\n",
1023                                PFID(&copy->hc_hai.hai_fid),
1024                                copy->hc_data_version, data_version);
1025                         /* File was changed, send error to cdt. Do not ask for
1026                          * retry because if a file is modified frequently,
1027                          * the cdt will loop on retried archive requests.
1028                          * The policy engine will ask for a new archive later
1029                          * when the file will not be modified for some tunable
1030                          * time */
1031                         hpk.hpk_flags &= ~HP_FLAG_RETRY;
1032                         rc = -EBUSY;
1033                         /* hpk_errval must be >= 0 */
1034                         hpk.hpk_errval = -rc;
1035                         GOTO(progress, rc);
1036                 }
1037
1038         }
1039
1040 progress:
1041         rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
1042                             &hpk, NULL);
1043
1044         /* Return first error */
1045         RETURN(rc != 0 ? rc : rc2);
1046 }
1047
1048
1049 static int copy_and_ct_start(int cmd, struct obd_export *exp,
1050                              const struct lustre_kernelcomm __user *data)
1051 {
1052         struct lustre_kernelcomm *lk;
1053         struct lustre_kernelcomm *tmp;
1054         size_t size = sizeof(*lk);
1055         size_t new_size;
1056         int i;
1057         int rc;
1058
1059         /* copy data from userspace to get numbers of archive_id */
1060         OBD_ALLOC(lk, size);
1061         if (lk == NULL)
1062                 return -ENOMEM;
1063
1064         if (copy_from_user(lk, data, size))
1065                 GOTO(out_lk, rc = -EFAULT);
1066
1067         if (lk->lk_flags & LK_FLG_STOP)
1068                 goto do_ioctl;
1069
1070         if (!(lk->lk_flags & LK_FLG_DATANR)) {
1071                 __u32 archive_mask = lk->lk_data_count;
1072                 int count;
1073
1074                 /* old hsm agent to old MDS */
1075                 if (!exp_connect_archive_id_array(exp))
1076                         goto do_ioctl;
1077
1078                 /* old hsm agent to new MDS */
1079                 lk->lk_flags |= LK_FLG_DATANR;
1080
1081                 if (archive_mask == 0)
1082                         goto do_ioctl;
1083
1084                 count = hweight32(archive_mask);
1085                 new_size = offsetof(struct lustre_kernelcomm, lk_data[count]);
1086                 OBD_ALLOC(tmp, new_size);
1087                 if (tmp == NULL)
1088                         GOTO(out_lk, rc = -ENOMEM);
1089
1090                 memcpy(tmp, lk, size);
1091                 tmp->lk_data_count = count;
1092                 OBD_FREE(lk, size);
1093                 lk = tmp;
1094                 size = new_size;
1095
1096                 count = 0;
1097                 for (i = 0; i < sizeof(archive_mask) * 8; i++) {
1098                         if (BIT(i) & archive_mask) {
1099                                 lk->lk_data[count] = i + 1;
1100                                 count++;
1101                         }
1102                 }
1103                 goto do_ioctl;
1104         }
1105
1106         /* new hsm agent to new mds */
1107         if (lk->lk_data_count > 0) {
1108                 new_size = offsetof(struct lustre_kernelcomm,
1109                                     lk_data[lk->lk_data_count]);
1110                 OBD_ALLOC(tmp, new_size);
1111                 if (tmp == NULL)
1112                         GOTO(out_lk, rc = -ENOMEM);
1113
1114                 OBD_FREE(lk, size);
1115                 lk = tmp;
1116                 size = new_size;
1117
1118                 if (copy_from_user(lk, data, size))
1119                         GOTO(out_lk, rc = -EFAULT);
1120         }
1121
1122         /* new hsm agent to old MDS */
1123         if (!exp_connect_archive_id_array(exp)) {
1124                 __u32 archives = 0;
1125
1126                 if (lk->lk_data_count > LL_HSM_ORIGIN_MAX_ARCHIVE)
1127                         GOTO(out_lk, rc = -EINVAL);
1128
1129                 for (i = 0; i < lk->lk_data_count; i++) {
1130                         if (lk->lk_data[i] > LL_HSM_ORIGIN_MAX_ARCHIVE) {
1131                                 rc = -EINVAL;
1132                                 CERROR("%s: archive id %d requested but only "
1133                                        "[0 - %zu] supported: rc = %d\n",
1134                                        exp->exp_obd->obd_name, lk->lk_data[i],
1135                                        LL_HSM_ORIGIN_MAX_ARCHIVE, rc);
1136                                 GOTO(out_lk, rc);
1137                         }
1138
1139                         if (lk->lk_data[i] == 0) {
1140                                 archives = 0;
1141                                 break;
1142                         }
1143
1144                         archives |= (1 << (lk->lk_data[i] - 1));
1145                 }
1146                 lk->lk_flags &= ~LK_FLG_DATANR;
1147                 lk->lk_data_count = archives;
1148         }
1149 do_ioctl:
1150         rc = obd_iocontrol(cmd, exp, size, lk, NULL);
1151 out_lk:
1152         OBD_FREE(lk, size);
1153         return rc;
1154 }
1155
1156 static int check_owner(int type, int id)
1157 {
1158         switch (type) {
1159         case USRQUOTA:
1160                 if (!uid_eq(current_euid(), make_kuid(&init_user_ns, id)))
1161                         return -EPERM;
1162                 break;
1163         case GRPQUOTA:
1164                 if (!in_egroup_p(make_kgid(&init_user_ns, id)))
1165                         return -EPERM;
1166                 break;
1167         case PRJQUOTA:
1168                 break;
1169         }
1170         return 0;
1171 }
1172
1173 int quotactl_ioctl(struct super_block *sb, struct if_quotactl *qctl)
1174 {
1175         struct ll_sb_info *sbi = ll_s2sbi(sb);
1176         int cmd = qctl->qc_cmd;
1177         int type = qctl->qc_type;
1178         int id = qctl->qc_id;
1179         int valid = qctl->qc_valid;
1180         int rc = 0;
1181
1182         ENTRY;
1183
1184         switch (cmd) {
1185         case Q_SETQUOTA:
1186         case Q_SETINFO:
1187         case LUSTRE_Q_SETDEFAULT:
1188         case LUSTRE_Q_SETQUOTAPOOL:
1189         case LUSTRE_Q_SETINFOPOOL:
1190         case LUSTRE_Q_SETDEFAULT_POOL:
1191                 if (!capable(CAP_SYS_ADMIN))
1192                         RETURN(-EPERM);
1193
1194                 if (sb->s_flags & SB_RDONLY)
1195                         RETURN(-EROFS);
1196                 break;
1197         case Q_GETQUOTA:
1198         case LUSTRE_Q_GETDEFAULT:
1199         case LUSTRE_Q_GETQUOTAPOOL:
1200         case LUSTRE_Q_GETDEFAULT_POOL:
1201                 if (check_owner(type, id) &&
1202                     (!capable(CAP_SYS_ADMIN)))
1203                         RETURN(-EPERM);
1204                 break;
1205         case Q_GETINFO:
1206         case LUSTRE_Q_GETINFOPOOL:
1207                 break;
1208         default:
1209                 CERROR("unsupported quotactl op: %#x\n", cmd);
1210                 RETURN(-ENOTSUPP);
1211         }
1212
1213         if (valid != QC_GENERAL) {
1214                 if (cmd == Q_GETINFO)
1215                         qctl->qc_cmd = Q_GETOINFO;
1216                 else if (cmd == Q_GETQUOTA ||
1217                          cmd == LUSTRE_Q_GETQUOTAPOOL)
1218                         qctl->qc_cmd = Q_GETOQUOTA;
1219                 else
1220                         RETURN(-EINVAL);
1221
1222                 switch (valid) {
1223                 case QC_MDTIDX:
1224                         rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1225                                            sizeof(*qctl), qctl, NULL);
1226                         break;
1227                 case QC_OSTIDX:
1228                         rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
1229                                            sizeof(*qctl), qctl, NULL);
1230                         break;
1231                 case QC_UUID:
1232                         rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1233                                            sizeof(*qctl), qctl, NULL);
1234                         if (rc == -EAGAIN)
1235                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1236                                                    sbi->ll_dt_exp,
1237                                                    sizeof(*qctl), qctl, NULL);
1238                         break;
1239                 default:
1240                         rc = -EINVAL;
1241                         break;
1242                 }
1243
1244                 if (rc)
1245                         RETURN(rc);
1246
1247                 qctl->qc_cmd = cmd;
1248         } else {
1249                 struct obd_quotactl *oqctl;
1250                 int oqctl_len = sizeof(*oqctl);
1251
1252                 if (LUSTRE_Q_CMD_IS_POOL(cmd))
1253                         oqctl_len += LOV_MAXPOOLNAME + 1;
1254
1255                 OBD_ALLOC(oqctl, oqctl_len);
1256                 if (oqctl == NULL)
1257                         RETURN(-ENOMEM);
1258
1259                 QCTL_COPY(oqctl, qctl);
1260                 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1261                 if (rc) {
1262                         OBD_FREE(oqctl, oqctl_len);
1263                         RETURN(rc);
1264                 }
1265                 /* If QIF_SPACE is not set, client should collect the
1266                  * space usage from OSSs by itself */
1267                 if ((cmd == Q_GETQUOTA || cmd == LUSTRE_Q_GETQUOTAPOOL) &&
1268                     !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
1269                     !oqctl->qc_dqblk.dqb_curspace) {
1270                         struct obd_quotactl *oqctl_tmp;
1271                         int qctl_len = sizeof(*oqctl_tmp) + LOV_MAXPOOLNAME + 1;
1272
1273                         OBD_ALLOC(oqctl_tmp, qctl_len);
1274                         if (oqctl_tmp == NULL)
1275                                 GOTO(out, rc = -ENOMEM);
1276
1277                         if (cmd == LUSTRE_Q_GETQUOTAPOOL) {
1278                                 oqctl_tmp->qc_cmd = LUSTRE_Q_GETQUOTAPOOL;
1279                                 memcpy(oqctl_tmp->qc_poolname,
1280                                        qctl->qc_poolname,
1281                                        LOV_MAXPOOLNAME + 1);
1282                         } else {
1283                                 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1284                         }
1285                         oqctl_tmp->qc_id = oqctl->qc_id;
1286                         oqctl_tmp->qc_type = oqctl->qc_type;
1287
1288                         /* collect space usage from OSTs */
1289                         oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1290                         rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
1291                         if (!rc || rc == -EREMOTEIO) {
1292                                 oqctl->qc_dqblk.dqb_curspace =
1293                                         oqctl_tmp->qc_dqblk.dqb_curspace;
1294                                 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
1295                         }
1296
1297                         /* collect space & inode usage from MDTs */
1298                         oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1299                         oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1300                         oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
1301                         rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
1302                         if (!rc || rc == -EREMOTEIO) {
1303                                 oqctl->qc_dqblk.dqb_curspace +=
1304                                         oqctl_tmp->qc_dqblk.dqb_curspace;
1305                                 oqctl->qc_dqblk.dqb_curinodes =
1306                                         oqctl_tmp->qc_dqblk.dqb_curinodes;
1307                                 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1308                         } else {
1309                                 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1310                         }
1311
1312                         OBD_FREE(oqctl_tmp, qctl_len);
1313                 }
1314 out:
1315                 QCTL_COPY(qctl, oqctl);
1316                 OBD_FREE(oqctl, oqctl_len);
1317         }
1318
1319         RETURN(rc);
1320 }
1321
1322 int ll_rmfid(struct file *file, void __user *arg)
1323 {
1324         const struct fid_array __user *ufa = arg;
1325         struct inode *inode = file_inode(file);
1326         struct fid_array *lfa = NULL;
1327         size_t size;
1328         unsigned nr;
1329         int i, rc, *rcs = NULL;
1330         ENTRY;
1331
1332         if (!capable(CAP_DAC_READ_SEARCH) &&
1333             !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
1334                 RETURN(-EPERM);
1335         /* Only need to get the buflen */
1336         if (get_user(nr, &ufa->fa_nr))
1337                 RETURN(-EFAULT);
1338         /* DoS protection */
1339         if (nr > OBD_MAX_FIDS_IN_ARRAY)
1340                 RETURN(-E2BIG);
1341
1342         size = offsetof(struct fid_array, fa_fids[nr]);
1343         OBD_ALLOC(lfa, size);
1344         if (!lfa)
1345                 RETURN(-ENOMEM);
1346         OBD_ALLOC_PTR_ARRAY(rcs, nr);
1347         if (!rcs)
1348                 GOTO(free_lfa, rc = -ENOMEM);
1349
1350         if (copy_from_user(lfa, arg, size))
1351                 GOTO(free_rcs, rc = -EFAULT);
1352
1353         /* Call mdc_iocontrol */
1354         rc = md_rmfid(ll_i2mdexp(file_inode(file)), lfa, rcs, NULL);
1355         if (!rc) {
1356                 for (i = 0; i < nr; i++)
1357                         if (rcs[i])
1358                                 lfa->fa_fids[i].f_ver = rcs[i];
1359                 if (copy_to_user(arg, lfa, size))
1360                         rc = -EFAULT;
1361         }
1362
1363 free_rcs:
1364         OBD_FREE_PTR_ARRAY(rcs, nr);
1365 free_lfa:
1366         OBD_FREE(lfa, size);
1367
1368         RETURN(rc);
1369 }
1370
1371 /* This function tries to get a single name component,
1372  * to send to the server. No actual path traversal involved,
1373  * so we limit to NAME_MAX */
1374 static char *ll_getname(const char __user *filename)
1375 {
1376         int ret = 0, len;
1377         char *tmp;
1378
1379         OBD_ALLOC(tmp, NAME_MAX + 1);
1380
1381         if (!tmp)
1382                 return ERR_PTR(-ENOMEM);
1383
1384         len = strncpy_from_user(tmp, filename, NAME_MAX + 1);
1385         if (len < 0)
1386                 ret = -ENOENT;
1387         else if (len > NAME_MAX)
1388                 ret = -ENAMETOOLONG;
1389
1390         if (ret) {
1391                 OBD_FREE(tmp, NAME_MAX + 1);
1392                 tmp =  ERR_PTR(ret);
1393         }
1394         return tmp;
1395 }
1396
1397 #define ll_putname(filename) OBD_FREE(filename, NAME_MAX + 1);
1398
1399 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1400 {
1401         struct dentry *dentry = file_dentry(file);
1402         struct inode *inode = file_inode(file);
1403         struct ll_sb_info *sbi = ll_i2sbi(inode);
1404         struct obd_ioctl_data *data = NULL;
1405         int rc = 0;
1406         ENTRY;
1407
1408         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1409                PFID(ll_inode2fid(inode)), inode, cmd);
1410
1411         /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1412         if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1413                 return -ENOTTY;
1414
1415         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1416         switch (cmd) {
1417         case FS_IOC_GETFLAGS:
1418         case FS_IOC_SETFLAGS:
1419                 RETURN(ll_iocontrol(inode, file, cmd, arg));
1420         case FSFILT_IOC_GETVERSION:
1421         case FS_IOC_GETVERSION:
1422                 RETURN(put_user(inode->i_generation, (int __user *)arg));
1423         /* We need to special case any other ioctls we want to handle,
1424          * to send them to the MDS/OST as appropriate and to properly
1425          * network encode the arg field. */
1426         case FS_IOC_SETVERSION:
1427                 RETURN(-ENOTSUPP);
1428
1429         case LL_IOC_GET_MDTIDX: {
1430                 int mdtidx;
1431
1432                 mdtidx = ll_get_mdt_idx(inode);
1433                 if (mdtidx < 0)
1434                         RETURN(mdtidx);
1435
1436                 if (put_user((int)mdtidx, (int __user *)arg))
1437                         RETURN(-EFAULT);
1438
1439                 return 0;
1440         }
1441         case IOC_MDC_LOOKUP: {
1442                 int namelen, len = 0;
1443                 char *filename;
1444
1445                 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1446                 if (rc != 0)
1447                         RETURN(rc);
1448
1449                 filename = data->ioc_inlbuf1;
1450                 namelen = strlen(filename);
1451                 if (namelen < 1) {
1452                         CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1453                         GOTO(out_free, rc = -EINVAL);
1454                 }
1455
1456                 rc = ll_get_fid_by_name(inode, filename, namelen, NULL, NULL);
1457                 if (rc < 0) {
1458                         CERROR("%s: lookup %.*s failed: rc = %d\n",
1459                                sbi->ll_fsname, namelen, filename, rc);
1460                         GOTO(out_free, rc);
1461                 }
1462 out_free:
1463                 OBD_FREE_LARGE(data, len);
1464                 return rc;
1465         }
1466         case LL_IOC_LMV_SETSTRIPE: {
1467                 struct lmv_user_md  *lum;
1468                 char *filename;
1469                 int namelen = 0;
1470                 int lumlen = 0;
1471                 umode_t mode;
1472                 bool createonly = false;
1473                 int len;
1474                 int rc;
1475
1476                 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1477                 if (rc)
1478                         RETURN(rc);
1479
1480                 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1481                     data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1482                         GOTO(lmv_out_free, rc = -EINVAL);
1483
1484                 filename = data->ioc_inlbuf1;
1485                 namelen = data->ioc_inllen1;
1486
1487                 if (namelen < 1) {
1488                         CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1489                         GOTO(lmv_out_free, rc = -EINVAL);
1490                 }
1491                 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1492                 lumlen = data->ioc_inllen2;
1493
1494                 if (!lmv_user_magic_supported(lum->lum_magic)) {
1495                         CERROR("%s: wrong lum magic %x : rc = %d\n", filename,
1496                                lum->lum_magic, -EINVAL);
1497                         GOTO(lmv_out_free, rc = -EINVAL);
1498                 }
1499
1500                 if ((lum->lum_magic == LMV_USER_MAGIC ||
1501                      lum->lum_magic == LMV_USER_MAGIC_SPECIFIC) &&
1502                     lumlen < sizeof(*lum)) {
1503                         CERROR("%s: wrong lum size %d for magic %x : rc = %d\n",
1504                                filename, lumlen, lum->lum_magic, -EINVAL);
1505                         GOTO(lmv_out_free, rc = -EINVAL);
1506                 }
1507
1508                 if (lum->lum_magic == LMV_MAGIC_FOREIGN &&
1509                     lumlen < sizeof(struct lmv_foreign_md)) {
1510                         CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1511                                filename, lum->lum_magic, lumlen, -EFAULT);
1512                         GOTO(lmv_out_free, rc = -EINVAL);
1513                 }
1514
1515                 mode = data->ioc_type;
1516                 createonly = data->ioc_obdo1.o_flags & OBD_FL_OBDMDEXISTS;
1517                 rc = ll_dir_setdirstripe(dentry, lum, lumlen, filename, mode,
1518                                          createonly);
1519 lmv_out_free:
1520                 OBD_FREE_LARGE(data, len);
1521                 RETURN(rc);
1522
1523         }
1524         case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1525                 struct lmv_user_md        lum;
1526                 struct lmv_user_md __user *ulump =
1527                                         (struct lmv_user_md __user *)arg;
1528                 int                       rc;
1529
1530                 if (copy_from_user(&lum, ulump, sizeof(lum)))
1531                         RETURN(-EFAULT);
1532
1533                 if (lum.lum_magic != LMV_USER_MAGIC)
1534                         RETURN(-EINVAL);
1535
1536                 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1537
1538                 RETURN(rc);
1539         }
1540         case LL_IOC_LOV_SETSTRIPE_NEW:
1541         case LL_IOC_LOV_SETSTRIPE: {
1542                 struct lov_user_md_v3 *lumv3 = NULL;
1543                 struct lov_user_md_v1 lumv1;
1544                 struct lov_user_md_v1 *lumv1_ptr = &lumv1;
1545                 struct lov_user_md_v1 __user *lumv1p =
1546                         (struct lov_user_md_v1 __user *)arg;
1547                 struct lov_user_md_v3 __user *lumv3p =
1548                         (struct lov_user_md_v3 __user *)arg;
1549                 int lum_size = 0;
1550
1551                 int set_default = 0;
1552
1553                 BUILD_BUG_ON(sizeof(struct lov_user_md_v3) <=
1554                              sizeof(struct lov_comp_md_v1));
1555                 BUILD_BUG_ON(sizeof(*lumv3) != sizeof(*lumv3p));
1556                 /* first try with v1 which is smaller than v3 */
1557                 if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1)))
1558                         RETURN(-EFAULT);
1559
1560                 if (is_root_inode(inode))
1561                         set_default = 1;
1562
1563                 switch (lumv1.lmm_magic) {
1564                 case LOV_USER_MAGIC_V3:
1565                 case LOV_USER_MAGIC_SPECIFIC:
1566                         lum_size = ll_lov_user_md_size(&lumv1);
1567                         if (lum_size < 0)
1568                                 RETURN(lum_size);
1569                         OBD_ALLOC(lumv3, lum_size);
1570                         if (!lumv3)
1571                                 RETURN(-ENOMEM);
1572                         if (copy_from_user(lumv3, lumv3p, lum_size))
1573                                 GOTO(out, rc = -EFAULT);
1574                         lumv1_ptr = (struct lov_user_md_v1 *)lumv3;
1575                         break;
1576                 case LOV_USER_MAGIC_V1:
1577                         break;
1578                 default:
1579                         GOTO(out, rc = -ENOTSUPP);
1580                 }
1581
1582                 /* in v1 and v3 cases lumv1 points to data */
1583                 rc = ll_dir_setstripe(inode, lumv1_ptr, set_default);
1584 out:
1585                 if (lumv3)
1586                         OBD_FREE(lumv3, lum_size);
1587                 RETURN(rc);
1588         }
1589         case LL_IOC_LMV_GETSTRIPE: {
1590                 struct lmv_user_md __user *ulmv =
1591                                         (struct lmv_user_md __user *)arg;
1592                 struct lmv_user_md      lum;
1593                 struct ptlrpc_request   *request = NULL;
1594                 struct ptlrpc_request   *root_request = NULL;
1595                 union lmv_mds_md        *lmm = NULL;
1596                 int                     lmmsize;
1597                 u64                     valid = 0;
1598                 struct lmv_user_md      *tmp = NULL;
1599                 int                     mdt_index;
1600                 int                     lum_size;
1601                 int                     stripe_count;
1602                 int                     max_stripe_count;
1603                 int                     i;
1604                 int                     rc;
1605
1606                 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1607                         RETURN(-EFAULT);
1608
1609                 max_stripe_count = lum.lum_stripe_count;
1610                 /* lum_magic will indicate which stripe the ioctl will like
1611                  * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1612                  * is for default LMV stripe */
1613                 if (lum.lum_magic == LMV_MAGIC_V1)
1614                         valid |= OBD_MD_MEA;
1615                 else if (lum.lum_magic == LMV_USER_MAGIC)
1616                         valid |= OBD_MD_DEFAULT_MEA;
1617                 else
1618                         RETURN(-EINVAL);
1619
1620                 rc = ll_dir_getstripe_default(inode, (void **)&lmm, &lmmsize,
1621                                               &request, &root_request, valid);
1622                 if (rc != 0)
1623                         GOTO(finish_req, rc);
1624
1625                 /* Get default LMV EA */
1626                 if (lum.lum_magic == LMV_USER_MAGIC) {
1627                         if (lmmsize > sizeof(*ulmv))
1628                                 GOTO(finish_req, rc = -EINVAL);
1629
1630                         if (copy_to_user(ulmv, lmm, lmmsize))
1631                                 GOTO(finish_req, rc = -EFAULT);
1632
1633                         GOTO(finish_req, rc);
1634                 }
1635
1636                 /* if foreign LMV case, fake stripes number */
1637                 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1638                         struct lmv_foreign_md *lfm;
1639
1640                         lfm = (struct lmv_foreign_md *)lmm;
1641                         if (lfm->lfm_length < XATTR_SIZE_MAX -
1642                             offsetof(typeof(*lfm), lfm_value)) {
1643                                 __u32 size = lfm->lfm_length +
1644                                              offsetof(typeof(*lfm), lfm_value);
1645
1646                                 stripe_count = lmv_foreign_to_md_stripes(size);
1647                         } else {
1648                                 CERROR("invalid %d foreign size returned\n",
1649                                             lfm->lfm_length);
1650                                 return -EINVAL;
1651                         }
1652                 } else {
1653                         stripe_count = lmv_mds_md_stripe_count_get(lmm);
1654                 }
1655                 if (max_stripe_count < stripe_count) {
1656                         lum.lum_stripe_count = stripe_count;
1657                         if (copy_to_user(ulmv, &lum, sizeof(lum)))
1658                                 GOTO(finish_req, rc = -EFAULT);
1659                         GOTO(finish_req, rc = -E2BIG);
1660                 }
1661
1662                 /* enough room on user side and foreign case */
1663                 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1664                         struct lmv_foreign_md *lfm;
1665                         __u32 size;
1666
1667                         lfm = (struct lmv_foreign_md *)lmm;
1668                         size = lfm->lfm_length +
1669                                offsetof(struct lmv_foreign_md, lfm_value);
1670                         if (copy_to_user(ulmv, lfm, size))
1671                                 GOTO(finish_req, rc = -EFAULT);
1672                         GOTO(finish_req, rc);
1673                 }
1674
1675                 lum_size = lmv_user_md_size(stripe_count,
1676                                             LMV_USER_MAGIC_SPECIFIC);
1677                 OBD_ALLOC(tmp, lum_size);
1678                 if (tmp == NULL)
1679                         GOTO(finish_req, rc = -ENOMEM);
1680
1681                 mdt_index = ll_get_mdt_idx(inode);
1682                 if (mdt_index < 0)
1683                         GOTO(out_tmp, rc = -ENOMEM);
1684
1685                 tmp->lum_magic = LMV_MAGIC_V1;
1686                 tmp->lum_stripe_count = 0;
1687                 tmp->lum_stripe_offset = mdt_index;
1688                 tmp->lum_hash_type = lmv_mds_md_hash_type_get(lmm);
1689                 for (i = 0; i < stripe_count; i++) {
1690                         struct lu_fid   fid;
1691
1692                         fid_le_to_cpu(&fid, &lmm->lmv_md_v1.lmv_stripe_fids[i]);
1693                         if (fid_is_sane(&fid)) {
1694                                 mdt_index = ll_get_mdt_idx_by_fid(sbi, &fid);
1695                                 if (mdt_index < 0)
1696                                         GOTO(out_tmp, rc = mdt_index);
1697
1698                                 tmp->lum_objects[i].lum_mds = mdt_index;
1699                                 tmp->lum_objects[i].lum_fid = fid;
1700                         }
1701
1702                         tmp->lum_stripe_count++;
1703                 }
1704
1705                 if (copy_to_user(ulmv, tmp, lum_size))
1706                         GOTO(out_tmp, rc = -EFAULT);
1707 out_tmp:
1708                 OBD_FREE(tmp, lum_size);
1709 finish_req:
1710                 ptlrpc_req_finished(request);
1711                 ptlrpc_req_finished(root_request);
1712                 return rc;
1713         }
1714
1715         case LL_IOC_UNLOCK_FOREIGN:
1716                 /* if not a foreign symlink do nothing */
1717                 if (ll_foreign_is_removable(dentry, true)) {
1718                         CDEBUG(D_INFO,
1719                                "prevent rmdir of non-foreign dir ("DFID")\n",
1720                                PFID(ll_inode2fid(inode)));
1721                         RETURN(-EOPNOTSUPP);
1722                 }
1723                 RETURN(0);
1724
1725         case LL_IOC_REMOVE_ENTRY: {
1726                 char            *filename = NULL;
1727                 int              namelen = 0;
1728                 int              rc;
1729
1730                 /* Here is a little hack to avoid sending REINT_RMENTRY to
1731                  * unsupported server, which might crash the server(LU-2730),
1732                  * Because both LVB_TYPE and REINT_RMENTRY will be supported
1733                  * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1734                  * server will support REINT_RMENTRY XXX*/
1735                 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1736                         RETURN(-ENOTSUPP);
1737
1738                 filename = ll_getname((const char __user *)arg);
1739                 if (IS_ERR(filename))
1740                         RETURN(PTR_ERR(filename));
1741
1742                 namelen = strlen(filename);
1743                 if (namelen < 1)
1744                         GOTO(out_rmdir, rc = -EINVAL);
1745
1746                 rc = ll_rmdir_entry(inode, filename, namelen);
1747 out_rmdir:
1748                 if (filename)
1749                         ll_putname(filename);
1750                 RETURN(rc);
1751         }
1752         case LL_IOC_RMFID:
1753                 RETURN(ll_rmfid(file, (void __user *)arg));
1754         case LL_IOC_LOV_SWAP_LAYOUTS:
1755                 RETURN(-EPERM);
1756         case IOC_OBD_STATFS:
1757                 RETURN(ll_obd_statfs(inode, (void __user *)arg));
1758         case LL_IOC_LOV_GETSTRIPE:
1759         case LL_IOC_LOV_GETSTRIPE_NEW:
1760         case LL_IOC_MDC_GETINFO_V1:
1761         case LL_IOC_MDC_GETINFO_V2:
1762         case IOC_MDC_GETFILEINFO_V1:
1763         case IOC_MDC_GETFILEINFO_V2:
1764         case IOC_MDC_GETFILESTRIPE: {
1765                 struct ptlrpc_request *request = NULL;
1766                 struct ptlrpc_request *root_request = NULL;
1767                 struct lov_user_md __user *lump;
1768                 struct lov_mds_md *lmm = NULL;
1769                 struct mdt_body *body;
1770                 char *filename = NULL;
1771                 lstat_t __user *statp = NULL;
1772                 lstatx_t __user *stxp = NULL;
1773                 __u64 __user *flagsp = NULL;
1774                 __u32 __user *lmmsizep = NULL;
1775                 struct lu_fid __user *fidp = NULL;
1776                 int lmmsize;
1777                 bool api32;
1778
1779                 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1780                     cmd == IOC_MDC_GETFILEINFO_V2 ||
1781                     cmd == IOC_MDC_GETFILESTRIPE) {
1782                         filename = ll_getname((const char __user *)arg);
1783                         if (IS_ERR(filename))
1784                                 RETURN(PTR_ERR(filename));
1785
1786                         rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1787                                                       &lmmsize, &request);
1788                 } else {
1789                         rc = ll_dir_getstripe_default(inode, (void **)&lmm,
1790                                                       &lmmsize, &request,
1791                                                       &root_request, 0);
1792                 }
1793
1794                 if (request) {
1795                         body = req_capsule_server_get(&request->rq_pill,
1796                                                       &RMF_MDT_BODY);
1797                         LASSERT(body != NULL);
1798                 } else {
1799                         GOTO(out_req, rc);
1800                 }
1801
1802                 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO_V1 ||
1803                                        cmd == LL_IOC_MDC_GETINFO_V1 ||
1804                                        cmd == IOC_MDC_GETFILEINFO_V2 ||
1805                                        cmd == LL_IOC_MDC_GETINFO_V2)) {
1806                         lmmsize = 0;
1807                         rc = 0;
1808                 }
1809
1810                 if (rc < 0)
1811                         GOTO(out_req, rc);
1812
1813                 if (cmd == IOC_MDC_GETFILESTRIPE ||
1814                     cmd == LL_IOC_LOV_GETSTRIPE ||
1815                     cmd == LL_IOC_LOV_GETSTRIPE_NEW) {
1816                         lump = (struct lov_user_md __user *)arg;
1817                 } else if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1818                            cmd == LL_IOC_MDC_GETINFO_V1){
1819                         struct lov_user_mds_data_v1 __user *lmdp;
1820
1821                         lmdp = (struct lov_user_mds_data_v1 __user *)arg;
1822                         statp = &lmdp->lmd_st;
1823                         lump = &lmdp->lmd_lmm;
1824                 } else {
1825                         struct lov_user_mds_data __user *lmdp;
1826
1827                         lmdp = (struct lov_user_mds_data __user *)arg;
1828                         fidp = &lmdp->lmd_fid;
1829                         stxp = &lmdp->lmd_stx;
1830                         flagsp = &lmdp->lmd_flags;
1831                         lmmsizep = &lmdp->lmd_lmmsize;
1832                         lump = &lmdp->lmd_lmm;
1833                 }
1834
1835                 if (lmmsize == 0) {
1836                         /* If the file has no striping then zero out *lump so
1837                          * that the caller isn't confused by garbage. */
1838                         if (clear_user(lump, sizeof(*lump)))
1839                                 GOTO(out_req, rc = -EFAULT);
1840                 } else if (copy_to_user(lump, lmm, lmmsize)) {
1841                         if (copy_to_user(lump, lmm, sizeof(*lump)))
1842                                 GOTO(out_req, rc = -EFAULT);
1843                         rc = -EOVERFLOW;
1844                 }
1845                 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
1846
1847                 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1848                     cmd == LL_IOC_MDC_GETINFO_V1) {
1849                         lstat_t st = { 0 };
1850
1851                         st.st_dev       = inode->i_sb->s_dev;
1852                         st.st_mode      = body->mbo_mode;
1853                         st.st_nlink     = body->mbo_nlink;
1854                         st.st_uid       = body->mbo_uid;
1855                         st.st_gid       = body->mbo_gid;
1856                         st.st_rdev      = body->mbo_rdev;
1857                         if (llcrypt_require_key(inode) == -ENOKEY)
1858                                 st.st_size = round_up(st.st_size,
1859                                                    LUSTRE_ENCRYPTION_UNIT_SIZE);
1860                         else
1861                                 st.st_size = body->mbo_size;
1862                         st.st_blksize   = PAGE_SIZE;
1863                         st.st_blocks    = body->mbo_blocks;
1864                         st.st_atime     = body->mbo_atime;
1865                         st.st_mtime     = body->mbo_mtime;
1866                         st.st_ctime     = body->mbo_ctime;
1867                         st.st_ino       = cl_fid_build_ino(&body->mbo_fid1,
1868                                                            api32);
1869
1870                         if (copy_to_user(statp, &st, sizeof(st)))
1871                                 GOTO(out_req, rc = -EFAULT);
1872                 } else if (cmd == IOC_MDC_GETFILEINFO_V2 ||
1873                            cmd == LL_IOC_MDC_GETINFO_V2) {
1874                         lstatx_t stx = { 0 };
1875                         __u64 valid = body->mbo_valid;
1876
1877                         stx.stx_blksize = PAGE_SIZE;
1878                         stx.stx_nlink = body->mbo_nlink;
1879                         stx.stx_uid = body->mbo_uid;
1880                         stx.stx_gid = body->mbo_gid;
1881                         stx.stx_mode = body->mbo_mode;
1882                         stx.stx_ino = cl_fid_build_ino(&body->mbo_fid1,
1883                                                        api32);
1884                         if (llcrypt_require_key(inode) == -ENOKEY)
1885                                 stx.stx_size = round_up(stx.stx_size,
1886                                                    LUSTRE_ENCRYPTION_UNIT_SIZE);
1887                         else
1888                                 stx.stx_size = body->mbo_size;
1889                         stx.stx_blocks = body->mbo_blocks;
1890                         stx.stx_atime.tv_sec = body->mbo_atime;
1891                         stx.stx_ctime.tv_sec = body->mbo_ctime;
1892                         stx.stx_mtime.tv_sec = body->mbo_mtime;
1893                         stx.stx_btime.tv_sec = body->mbo_btime;
1894                         stx.stx_rdev_major = MAJOR(body->mbo_rdev);
1895                         stx.stx_rdev_minor = MINOR(body->mbo_rdev);
1896                         stx.stx_dev_major = MAJOR(inode->i_sb->s_dev);
1897                         stx.stx_dev_minor = MINOR(inode->i_sb->s_dev);
1898                         stx.stx_mask |= STATX_BASIC_STATS | STATX_BTIME;
1899
1900                         /*
1901                          * For a striped directory, the size and blocks returned
1902                          * from MDT is not correct.
1903                          * The size and blocks are aggregated by client across
1904                          * all stripes.
1905                          * Thus for a striped directory, do not return the valid
1906                          * FLSIZE and FLBLOCKS flags to the caller.
1907                          * However, this whould be better decided by the MDS
1908                          * instead of the client.
1909                          */
1910                         if (cmd == LL_IOC_MDC_GETINFO_V2 &&
1911                             ll_i2info(inode)->lli_lsm_md != NULL)
1912                                 valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
1913
1914                         if (flagsp && copy_to_user(flagsp, &valid,
1915                                                    sizeof(*flagsp)))
1916                                 GOTO(out_req, rc = -EFAULT);
1917
1918                         if (fidp && copy_to_user(fidp, &body->mbo_fid1,
1919                                                  sizeof(*fidp)))
1920                                 GOTO(out_req, rc = -EFAULT);
1921
1922                         if (!(valid & OBD_MD_FLSIZE))
1923                                 stx.stx_mask &= ~STATX_SIZE;
1924                         if (!(valid & OBD_MD_FLBLOCKS))
1925                                 stx.stx_mask &= ~STATX_BLOCKS;
1926
1927                         if (stxp && copy_to_user(stxp, &stx, sizeof(stx)))
1928                                 GOTO(out_req, rc = -EFAULT);
1929
1930                         if (lmmsizep && copy_to_user(lmmsizep, &lmmsize,
1931                                                      sizeof(*lmmsizep)))
1932                                 GOTO(out_req, rc = -EFAULT);
1933                 }
1934
1935                 EXIT;
1936 out_req:
1937                 ptlrpc_req_finished(request);
1938                 ptlrpc_req_finished(root_request);
1939                 if (filename)
1940                         ll_putname(filename);
1941                 return rc;
1942         }
1943         case OBD_IOC_QUOTACTL: {
1944                 struct if_quotactl *qctl;
1945                 int qctl_len = sizeof(*qctl) + LOV_MAXPOOLNAME + 1;
1946
1947                 OBD_ALLOC(qctl, qctl_len);
1948                 if (!qctl)
1949                         RETURN(-ENOMEM);
1950
1951                 if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl)))
1952                         GOTO(out_quotactl, rc = -EFAULT);
1953
1954                 if (LUSTRE_Q_CMD_IS_POOL(qctl->qc_cmd)) {
1955                         char __user *from = (char __user *)arg +
1956                                         offsetof(typeof(*qctl), qc_poolname);
1957                         if (copy_from_user(qctl->qc_poolname, from,
1958                                            LOV_MAXPOOLNAME + 1))
1959                                 GOTO(out_quotactl, rc = -EFAULT);
1960                 }
1961
1962                 rc = quotactl_ioctl(inode->i_sb, qctl);
1963                 if (rc == 0 &&
1964                     copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
1965                         rc = -EFAULT;
1966
1967 out_quotactl:
1968                 OBD_FREE(qctl, qctl_len);
1969                 RETURN(rc);
1970         }
1971         case OBD_IOC_GETNAME_OLD:
1972                 /* fall through */
1973         case OBD_IOC_GETDTNAME:
1974                 /* fall through */
1975         case OBD_IOC_GETMDNAME:
1976                 RETURN(ll_get_obd_name(inode, cmd, arg));
1977         case LL_IOC_FLUSHCTX:
1978                 RETURN(ll_flush_ctx(inode));
1979         case LL_IOC_GETOBDCOUNT: {
1980                 u32 count, vallen;
1981                 struct obd_export *exp;
1982
1983                 if (copy_from_user(&count, (int __user *)arg, sizeof(int)))
1984                         RETURN(-EFAULT);
1985
1986                 /* get ost count when count is zero, get mdt count otherwise */
1987                 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
1988                 vallen = sizeof(count);
1989                 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
1990                                   KEY_TGT_COUNT, &vallen, &count);
1991                 if (rc) {
1992                         CERROR("get target count failed: %d\n", rc);
1993                         RETURN(rc);
1994                 }
1995
1996                 if (copy_to_user((int __user *)arg, &count, sizeof(int)))
1997                         RETURN(-EFAULT);
1998
1999                 RETURN(0);
2000         }
2001         case LL_IOC_PATH2FID:
2002                 if (copy_to_user((void __user *)arg, ll_inode2fid(inode),
2003                                      sizeof(struct lu_fid)))
2004                         RETURN(-EFAULT);
2005                 RETURN(0);
2006         case LL_IOC_GET_CONNECT_FLAGS: {
2007                 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL,
2008                                      (void __user *)arg));
2009         }
2010         case OBD_IOC_FID2PATH:
2011                 RETURN(ll_fid2path(inode, (void __user *)arg));
2012         case LL_IOC_GETPARENT:
2013                 RETURN(ll_getparent(file, (void __user *)arg));
2014         case LL_IOC_FID2MDTIDX: {
2015                 struct obd_export *exp = ll_i2mdexp(inode);
2016                 struct lu_fid     fid;
2017                 __u32             index;
2018
2019                 if (copy_from_user(&fid, (const struct lu_fid __user *)arg,
2020                                    sizeof(fid)))
2021                         RETURN(-EFAULT);
2022
2023                 /* Call mdc_iocontrol */
2024                 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
2025                                    (__u32 __user *)&index);
2026                 if (rc != 0)
2027                         RETURN(rc);
2028
2029                 RETURN(index);
2030         }
2031         case LL_IOC_HSM_REQUEST: {
2032                 struct hsm_user_request *hur;
2033                 ssize_t                  totalsize;
2034
2035                 OBD_ALLOC_PTR(hur);
2036                 if (hur == NULL)
2037                         RETURN(-ENOMEM);
2038
2039                 /* We don't know the true size yet; copy the fixed-size part */
2040                 if (copy_from_user(hur, (void __user *)arg, sizeof(*hur))) {
2041                         OBD_FREE_PTR(hur);
2042                         RETURN(-EFAULT);
2043                 }
2044
2045                 /* Compute the whole struct size */
2046                 totalsize = hur_len(hur);
2047                 OBD_FREE_PTR(hur);
2048                 if (totalsize < 0)
2049                         RETURN(-E2BIG);
2050
2051                 /* Final size will be more than double totalsize */
2052                 if (totalsize >= MDS_MAXREQSIZE / 3)
2053                         RETURN(-E2BIG);
2054
2055                 OBD_ALLOC_LARGE(hur, totalsize);
2056                 if (hur == NULL)
2057                         RETURN(-ENOMEM);
2058
2059                 /* Copy the whole struct */
2060                 if (copy_from_user(hur, (void __user *)arg, totalsize))
2061                         GOTO(out_hur, rc = -EFAULT);
2062
2063                 if (hur->hur_request.hr_action == HUA_RELEASE) {
2064                         const struct lu_fid *fid;
2065                         struct inode *f;
2066                         int i;
2067
2068                         for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
2069                                 fid = &hur->hur_user_item[i].hui_fid;
2070                                 f = search_inode_for_lustre(inode->i_sb, fid);
2071                                 if (IS_ERR(f)) {
2072                                         rc = PTR_ERR(f);
2073                                         break;
2074                                 }
2075
2076                                 rc = ll_hsm_release(f);
2077                                 iput(f);
2078                                 if (rc != 0)
2079                                         break;
2080                         }
2081                 } else {
2082                         rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
2083                                            hur, NULL);
2084                 }
2085
2086 out_hur:
2087                 OBD_FREE_LARGE(hur, totalsize);
2088
2089                 RETURN(rc);
2090         }
2091         case LL_IOC_HSM_PROGRESS: {
2092                 struct hsm_progress_kernel      hpk;
2093                 struct hsm_progress             hp;
2094
2095                 if (copy_from_user(&hp, (void __user *)arg, sizeof(hp)))
2096                         RETURN(-EFAULT);
2097
2098                 hpk.hpk_fid = hp.hp_fid;
2099                 hpk.hpk_cookie = hp.hp_cookie;
2100                 hpk.hpk_extent = hp.hp_extent;
2101                 hpk.hpk_flags = hp.hp_flags;
2102                 hpk.hpk_errval = hp.hp_errval;
2103                 hpk.hpk_data_version = 0;
2104
2105                 /* File may not exist in Lustre; all progress
2106                  * reported to Lustre root */
2107                 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
2108                                    NULL);
2109                 RETURN(rc);
2110         }
2111         case LL_IOC_HSM_CT_START:
2112                 if (!capable(CAP_SYS_ADMIN))
2113                         RETURN(-EPERM);
2114
2115                 rc = copy_and_ct_start(cmd, sbi->ll_md_exp,
2116                                        (struct lustre_kernelcomm __user *)arg);
2117                 RETURN(rc);
2118
2119         case LL_IOC_HSM_COPY_START: {
2120                 struct hsm_copy *copy;
2121                 int              rc;
2122
2123                 OBD_ALLOC_PTR(copy);
2124                 if (copy == NULL)
2125                         RETURN(-ENOMEM);
2126                 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2127                         OBD_FREE_PTR(copy);
2128                         RETURN(-EFAULT);
2129                 }
2130
2131                 rc = ll_ioc_copy_start(inode->i_sb, copy);
2132                 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2133                         rc = -EFAULT;
2134
2135                 OBD_FREE_PTR(copy);
2136                 RETURN(rc);
2137         }
2138         case LL_IOC_HSM_COPY_END: {
2139                 struct hsm_copy *copy;
2140                 int              rc;
2141
2142                 OBD_ALLOC_PTR(copy);
2143                 if (copy == NULL)
2144                         RETURN(-ENOMEM);
2145                 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2146                         OBD_FREE_PTR(copy);
2147                         RETURN(-EFAULT);
2148                 }
2149
2150                 rc = ll_ioc_copy_end(inode->i_sb, copy);
2151                 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2152                         rc = -EFAULT;
2153
2154                 OBD_FREE_PTR(copy);
2155                 RETURN(rc);
2156         }
2157         case LL_IOC_MIGRATE: {
2158                 struct lmv_user_md *lum;
2159                 int len;
2160                 char *filename;
2161                 int namelen = 0;
2162                 __u32 flags;
2163                 int rc;
2164
2165                 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
2166                 if (rc)
2167                         RETURN(rc);
2168
2169                 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
2170                     data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
2171                         GOTO(migrate_free, rc = -EINVAL);
2172
2173                 filename = data->ioc_inlbuf1;
2174                 namelen = data->ioc_inllen1;
2175                 flags = data->ioc_type;
2176
2177                 if (namelen < 1 || namelen != strlen(filename) + 1) {
2178                         CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
2179                         GOTO(migrate_free, rc = -EINVAL);
2180                 }
2181
2182                 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
2183                 if (lum->lum_magic != LMV_USER_MAGIC &&
2184                     lum->lum_magic != LMV_USER_MAGIC_SPECIFIC) {
2185                         rc = -EINVAL;
2186                         CERROR("%s: wrong lum magic %x: rc = %d\n",
2187                                filename, lum->lum_magic, rc);
2188                         GOTO(migrate_free, rc);
2189                 }
2190
2191                 rc = ll_migrate(inode, file, lum, filename, flags);
2192 migrate_free:
2193                 OBD_FREE_LARGE(data, len);
2194
2195                 RETURN(rc);
2196         }
2197         case FS_IOC_FSGETXATTR:
2198                 RETURN(ll_ioctl_fsgetxattr(inode, cmd, arg));
2199         case FS_IOC_FSSETXATTR:
2200                 RETURN(ll_ioctl_fssetxattr(inode, cmd, arg));
2201         case LL_IOC_PROJECT:
2202                 RETURN(ll_ioctl_project(file, cmd, arg));
2203         case LL_IOC_PCC_DETACH_BY_FID: {
2204                 struct lu_pcc_detach_fid *detach;
2205                 struct lu_fid *fid;
2206                 struct inode *inode2;
2207                 unsigned long ino;
2208
2209                 OBD_ALLOC_PTR(detach);
2210                 if (detach == NULL)
2211                         RETURN(-ENOMEM);
2212
2213                 if (copy_from_user(detach,
2214                                    (const struct lu_pcc_detach_fid __user *)arg,
2215                                    sizeof(*detach)))
2216                         GOTO(out_detach, rc = -EFAULT);
2217
2218                 fid = &detach->pccd_fid;
2219                 ino = cl_fid_build_ino(fid, ll_need_32bit_api(sbi));
2220                 inode2 = ilookup5(inode->i_sb, ino, ll_test_inode_by_fid, fid);
2221                 if (inode2 == NULL)
2222                         /* Target inode is not in inode cache, and PCC file
2223                          * has aleady released, return immdiately.
2224                          */
2225                         GOTO(out_detach, rc = 0);
2226
2227                 if (!S_ISREG(inode2->i_mode))
2228                         GOTO(out_iput, rc = -EINVAL);
2229
2230                 if (!inode_owner_or_capable(inode2))
2231                         GOTO(out_iput, rc = -EPERM);
2232
2233                 rc = pcc_ioctl_detach(inode2, detach->pccd_opt);
2234 out_iput:
2235                 iput(inode2);
2236 out_detach:
2237                 OBD_FREE_PTR(detach);
2238                 RETURN(rc);
2239         }
2240 #ifdef HAVE_LUSTRE_CRYPTO
2241         case LL_IOC_SET_ENCRYPTION_POLICY:
2242                 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2243                         return -EOPNOTSUPP;
2244                 return llcrypt_ioctl_set_policy(file, (const void __user *)arg);
2245         case LL_IOC_GET_ENCRYPTION_POLICY_EX:
2246                 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2247                         return -EOPNOTSUPP;
2248                 return llcrypt_ioctl_get_policy_ex(file, (void __user *)arg);
2249         case LL_IOC_ADD_ENCRYPTION_KEY:
2250                 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2251                         return -EOPNOTSUPP;
2252                 return llcrypt_ioctl_add_key(file, (void __user *)arg);
2253         case LL_IOC_REMOVE_ENCRYPTION_KEY:
2254                 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2255                         return -EOPNOTSUPP;
2256                 return llcrypt_ioctl_remove_key(file, (void __user *)arg);
2257         case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
2258                 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2259                         return -EOPNOTSUPP;
2260                 return llcrypt_ioctl_remove_key_all_users(file,
2261                                                           (void __user *)arg);
2262         case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
2263                 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2264                         return -EOPNOTSUPP;
2265                 return llcrypt_ioctl_get_key_status(file, (void __user *)arg);
2266 #endif
2267         default:
2268                 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
2269                                      (void __user *)arg));
2270         }
2271 }
2272
2273 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
2274 {
2275         struct inode *inode = file->f_mapping->host;
2276         struct ll_file_data *fd = file->private_data;
2277         struct ll_sb_info *sbi = ll_i2sbi(inode);
2278         int api32 = ll_need_32bit_api(sbi);
2279         loff_t ret = -EINVAL;
2280         ENTRY;
2281
2282         inode_lock(inode);
2283         switch (origin) {
2284         case SEEK_SET:
2285                 break;
2286         case SEEK_CUR:
2287                 offset += file->f_pos;
2288                 break;
2289         case SEEK_END:
2290                 if (offset > 0)
2291                         GOTO(out, ret);
2292                 if (api32)
2293                         offset += LL_DIR_END_OFF_32BIT;
2294                 else
2295                         offset += LL_DIR_END_OFF;
2296                 break;
2297         default:
2298                 GOTO(out, ret);
2299         }
2300
2301         if (offset >= 0 &&
2302             ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
2303              (!api32 && offset <= LL_DIR_END_OFF))) {
2304                 if (offset != file->f_pos) {
2305                         bool hash64;
2306
2307                         hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
2308                         if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
2309                             (!api32 && offset == LL_DIR_END_OFF))
2310                                 fd->lfd_pos = MDS_DIR_END_OFF;
2311                         else if (api32 && hash64)
2312                                 fd->lfd_pos = offset << 32;
2313                         else
2314                                 fd->lfd_pos = offset;
2315                         file->f_pos = offset;
2316                         file->f_version = 0;
2317                 }
2318                 ret = offset;
2319         }
2320         GOTO(out, ret);
2321
2322 out:
2323         inode_unlock(inode);
2324         return ret;
2325 }
2326
2327 static int ll_dir_open(struct inode *inode, struct file *file)
2328 {
2329         ENTRY;
2330         RETURN(ll_file_open(inode, file));
2331 }
2332
2333 static int ll_dir_release(struct inode *inode, struct file *file)
2334 {
2335         ENTRY;
2336         RETURN(ll_file_release(inode, file));
2337 }
2338
2339 /* notify error if partially read striped directory */
2340 static int ll_dir_flush(struct file *file, fl_owner_t id)
2341 {
2342         struct ll_file_data *lfd = file->private_data;
2343         int rc = lfd->fd_partial_readdir_rc;
2344
2345         lfd->fd_partial_readdir_rc = 0;
2346
2347         return rc;
2348 }
2349
2350 const struct file_operations ll_dir_operations = {
2351         .llseek         = ll_dir_seek,
2352         .open           = ll_dir_open,
2353         .release        = ll_dir_release,
2354         .read           = generic_read_dir,
2355 #ifdef HAVE_DIR_CONTEXT
2356         .iterate_shared = ll_iterate,
2357 #else
2358         .readdir        = ll_readdir,
2359 #endif
2360         .unlocked_ioctl = ll_dir_ioctl,
2361         .fsync          = ll_fsync,
2362         .flush          = ll_dir_flush,
2363 };