Whamcloud - gitweb
b=18144
[fs/lustre-release.git] / lustre / llite / dir.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/llite/dir.c
37  *
38  * Directory code for lustre client.
39  */
40
41 #include <linux/fs.h>
42 #include <linux/pagemap.h>
43 #include <linux/mm.h>
44 #include <linux/version.h>
45 #include <linux/smp_lock.h>
46 #include <asm/uaccess.h>
47 #include <linux/buffer_head.h>   // for wait_on_buffer
48
49 #define DEBUG_SUBSYSTEM S_LLITE
50
51 #include <obd_support.h>
52 #include <obd_class.h>
53 #include <lustre_lib.h>
54 #include <lustre/lustre_idl.h>
55 #include <lustre_lite.h>
56 #include <lustre_dlm.h>
57 #include <lustre_fid.h>
58 #include "llite_internal.h"
59
60 #ifndef HAVE_PAGE_CHECKED
61 #ifdef HAVE_PG_FS_MISC
62 #define PageChecked(page)        test_bit(PG_fs_misc, &(page)->flags)
63 #define SetPageChecked(page)     set_bit(PG_fs_misc, &(page)->flags)
64 #else
65 #error PageChecked or PageFsMisc not defined in kernel
66 #endif
67 #endif
68
69 /*
70  * (new) readdir implementation overview.
71  *
72  * Original lustre readdir implementation cached exact copy of raw directory
73  * pages on the client. These pages were indexed in client page cache by
74  * logical offset in the directory file. This design, while very simple and
75  * intuitive had some inherent problems:
76  *
77  *     . it implies that byte offset to the directory entry serves as a
78  *     telldir(3)/seekdir(3) cookie, but that offset is not stable: in
79  *     ext3/htree directory entries may move due to splits, and more
80  *     importantly,
81  *
82  *     . it is incompatible with the design of split directories for cmd3,
83  *     that assumes that names are distributed across nodes based on their
84  *     hash, and so readdir should be done in hash order.
85  *
86  * New readdir implementation does readdir in hash order, and uses hash of a
87  * file name as a telldir/seekdir cookie. This led to number of complications:
88  *
89  *     . hash is not unique, so it cannot be used to index cached directory
90  *     pages on the client (note, that it requires a whole pageful of hash
91  *     collided entries to cause two pages to have identical hashes);
92  *
93  *     . hash is not unique, so it cannot, strictly speaking, be used as an
94  *     entry cookie. ext3/htree has the same problem and lustre implementation
95  *     mimics their solution: seekdir(hash) positions directory at the first
96  *     entry with the given hash.
97  *
98  * Client side.
99  *
100  * 0. caching
101  *
102  * Client caches directory pages using hash of the first entry as an index. As
103  * noted above hash is not unique, so this solution doesn't work as is:
104  * special processing is needed for "page hash chains" (i.e., sequences of
105  * pages filled with entries all having the same hash value).
106  *
107  * First, such chains have to be detected. To this end, server returns to the
108  * client the hash of the first entry on the page next to one returned. When
109  * client detects that this hash is the same as hash of the first entry on the
110  * returned page, page hash collision has to be handled. Pages in the
111  * hash chain, except first one, are termed "overflow pages".
112  *
113  * Solution to index uniqueness problem is to not cache overflow
114  * pages. Instead, when page hash collision is detected, all overflow pages
115  * from emerging chain are immediately requested from the server and placed in
116  * a special data structure (struct ll_dir_chain). This data structure is used
117  * by ll_readdir() to process entries from overflow pages. When readdir
118  * invocation finishes, overflow pages are discarded. If page hash collision
119  * chain weren't completely processed, next call to readdir will again detect
120  * page hash collision, again read overflow pages in, process next portion of
121  * entries and again discard the pages. This is not as wasteful as it looks,
122  * because, given reasonable hash, page hash collisions are extremely rare.
123  *
124  * 1. directory positioning
125  *
126  * When seekdir(hash) is called, original
127  *
128  *
129  *
130  *
131  *
132  *
133  *
134  *
135  * Server.
136  *
137  * identification of and access to overflow pages
138  *
139  * page format
140  *
141  *
142  *
143  *
144  *
145  */
146
147 /* returns the page unlocked, but with a reference */
148 static int ll_dir_readpage(struct file *file, struct page *page)
149 {
150         struct inode *inode = page->mapping->host;
151         struct ptlrpc_request *request;
152         struct mdt_body *body;
153         struct obd_capa *oc;
154         __u64 hash;
155         int rc;
156         ENTRY;
157
158         hash = (__u64)hash_x_index(page->index);
159         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) off %lu\n",
160                inode->i_ino, inode->i_generation, inode, (unsigned long)hash);
161
162         oc = ll_mdscapa_get(inode);
163         rc = md_readpage(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode),
164                          oc, hash, page, &request);
165         capa_put(oc);
166         if (!rc) {
167                 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
168                 /* Checked by mdc_readpage() */
169                 LASSERT(body != NULL);
170
171                 if (body->valid & OBD_MD_FLSIZE) {
172                         ll_inode_size_lock(inode, 0);
173                         i_size_write(inode, body->size);
174                         ll_inode_size_unlock(inode, 0);
175                 }
176                 SetPageUptodate(page);
177         }
178         ptlrpc_req_finished(request);
179
180         unlock_page(page);
181         EXIT;
182         return rc;
183 }
184
185 struct address_space_operations ll_dir_aops = {
186         .readpage  = ll_dir_readpage,
187 };
188
189 static void ll_check_page(struct inode *dir, struct page *page)
190 {
191         /* XXX: check page format later */
192         SetPageChecked(page);
193 }
194
195 static void ll_release_page(struct page *page, __u64 hash,
196                             __u64 start, __u64 end)
197 {
198         kunmap(page);
199         lock_page(page);
200         if (likely(page->mapping != NULL)) {
201                 ll_truncate_complete_page(page);
202                 unlock_page(page);
203         } else {
204                 unlock_page(page);
205                 CWARN("NULL mapping page %p, truncated by others: "
206                       "hash("LPX64") | start("LPX64") | end("LPX64")\n",
207                       page, hash, start, end);
208         }
209         page_cache_release(page);
210 }
211
212 /*
213  * Find, kmap and return page that contains given hash.
214  */
215 static struct page *ll_dir_page_locate(struct inode *dir, __u64 hash,
216                                        __u64 *start, __u64 *end)
217 {
218         struct address_space *mapping = dir->i_mapping;
219         /*
220          * Complement of hash is used as an index so that
221          * radix_tree_gang_lookup() can be used to find a page with starting
222          * hash _smaller_ than one we are looking for.
223          */
224         unsigned long offset = hash_x_index((unsigned long)hash);
225         struct page *page;
226         int found;
227
228         TREE_READ_LOCK_IRQ(mapping);
229         found = radix_tree_gang_lookup(&mapping->page_tree,
230                                        (void **)&page, offset, 1);
231         if (found > 0) {
232                 struct lu_dirpage *dp;
233
234                 page_cache_get(page);
235                 TREE_READ_UNLOCK_IRQ(mapping);
236                 /*
237                  * In contrast to find_lock_page() we are sure that directory
238                  * page cannot be truncated (while DLM lock is held) and,
239                  * hence, can avoid restart.
240                  *
241                  * In fact, page cannot be locked here at all, because
242                  * ll_dir_readpage() does synchronous io.
243                  */
244                 wait_on_page(page);
245                 if (PageUptodate(page)) {
246                         dp = kmap(page);
247                         *start = le64_to_cpu(dp->ldp_hash_start);
248                         *end   = le64_to_cpu(dp->ldp_hash_end);
249                         LASSERT(*start <= hash);
250                         if (hash > *end || (*end != *start && hash == *end)) {
251                                 ll_release_page(page, hash, *start, *end);
252                                 page = NULL;
253                         }
254                 } else {
255                         page_cache_release(page);
256                         page = ERR_PTR(-EIO);
257                 }
258
259         } else {
260                 TREE_READ_UNLOCK_IRQ(mapping);
261                 page = NULL;
262         }
263         return page;
264 }
265
266 struct page *ll_get_dir_page(struct inode *dir, __u64 hash, int exact,
267                              struct ll_dir_chain *chain)
268 {
269         ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
270         struct address_space *mapping = dir->i_mapping;
271         struct lustre_handle lockh;
272         struct lu_dirpage *dp;
273         struct page *page;
274         ldlm_mode_t mode;
275         int rc;
276         __u64 start = 0;
277         __u64 end = 0;
278
279         mode = LCK_PR;
280         rc = md_lock_match(ll_i2sbi(dir)->ll_md_exp, LDLM_FL_BLOCK_GRANTED,
281                            ll_inode2fid(dir), LDLM_IBITS, &policy, mode, &lockh);
282         if (!rc) {
283                 struct ldlm_enqueue_info einfo = { LDLM_IBITS, mode,
284                        ll_md_blocking_ast, ldlm_completion_ast,
285                        NULL, NULL, dir };
286                 struct lookup_intent it = { .it_op = IT_READDIR };
287                 struct ptlrpc_request *request;
288                 struct md_op_data *op_data;
289
290                 op_data = ll_prep_md_op_data(NULL, dir, NULL, NULL, 0, 0,
291                                              LUSTRE_OPC_ANY, NULL);
292                 if (IS_ERR(op_data))
293                         return (void *)op_data;
294
295                 rc = md_enqueue(ll_i2sbi(dir)->ll_md_exp, &einfo, &it,
296                                 op_data, &lockh, NULL, 0, NULL, 0);
297
298                 ll_finish_md_op_data(op_data);
299
300                 request = (struct ptlrpc_request *)it.d.lustre.it_data;
301                 if (request)
302                         ptlrpc_req_finished(request);
303                 if (rc < 0) {
304                         CERROR("lock enqueue: rc: %d\n", rc);
305                         return ERR_PTR(rc);
306                 }
307         } else {
308                 /* for cross-ref object, l_ast_data of the lock may not be set,
309                  * we reset it here */
310                 md_set_lock_data(ll_i2sbi(dir)->ll_md_exp, &lockh.cookie, dir);
311         }
312         ldlm_lock_dump_handle(D_OTHER, &lockh);
313
314         page = ll_dir_page_locate(dir, hash, &start, &end);
315         if (IS_ERR(page))
316                 GOTO(out_unlock, page);
317
318         if (page != NULL) {
319                 /*
320                  * XXX nikita: not entirely correct handling of a corner case:
321                  * suppose hash chain of entries with hash value HASH crosses
322                  * border between pages P0 and P1. First both P0 and P1 are
323                  * cached, seekdir() is called for some entry from the P0 part
324                  * of the chain. Later P0 goes out of cache. telldir(HASH)
325                  * happens and finds P1, as it starts with matching hash
326                  * value. Remaining entries from P0 part of the chain are
327                  * skipped. (Is that really a bug?)
328                  *
329                  * Possible solutions: 0. don't cache P1 is such case, handle
330                  * it as an "overflow" page. 1. invalidate all pages at
331                  * once. 2. use HASH|1 as an index for P1.
332                  */
333                 if (exact && hash != start) {
334                         /*
335                          * readdir asked for a page starting _exactly_ from
336                          * given hash, but cache contains stale page, with
337                          * entries with smaller hash values. Stale page should
338                          * be invalidated, and new one fetched.
339                          */
340                         CWARN("Stale readpage page %p: "LPX64" != "LPX64"\n",
341                               page, hash, start);
342                         ll_release_page(page, hash, start, end);
343                 } else {
344                         GOTO(hash_collision, page);
345                 }
346         }
347
348         page = read_cache_page(mapping, hash_x_index((unsigned long)hash),
349                                (filler_t*)mapping->a_ops->readpage, NULL);
350         if (IS_ERR(page))
351                 GOTO(out_unlock, page);
352
353         wait_on_page(page);
354         (void)kmap(page);
355         if (!PageUptodate(page))
356                 goto fail;
357         if (!PageChecked(page))
358                 ll_check_page(dir, page);
359         if (PageError(page))
360                 goto fail;
361 hash_collision:
362         dp = page_address(page);
363
364         start = le64_to_cpu(dp->ldp_hash_start);
365         end   = le64_to_cpu(dp->ldp_hash_end);
366         if (end == start) {
367                 LASSERT(start == hash);
368                 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
369                 /*
370                  * Fetch whole overflow chain...
371                  *
372                  * XXX not yet.
373                  */
374                 goto fail;
375         }
376 out_unlock:
377         ldlm_lock_decref(&lockh, mode);
378         return page;
379
380 fail:
381         ll_put_page(page);
382         page = ERR_PTR(-EIO);
383         goto out_unlock;
384 }
385
386 int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
387 {
388         struct inode         *inode = filp->f_dentry->d_inode;
389         struct ll_inode_info *info  = ll_i2info(inode);
390         struct ll_sb_info    *sbi   = ll_i2sbi(inode);
391         __u64                 pos   = filp->f_pos;
392         struct page          *page;
393         struct ll_dir_chain   chain;
394         int rc;
395         int done;
396         int shift;
397         __u16 type;
398         ENTRY;
399
400         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu\n",
401                inode->i_ino, inode->i_generation, inode,
402                (unsigned long)pos, i_size_read(inode));
403
404         if (pos == DIR_END_OFF)
405                 /*
406                  * end-of-file.
407                  */
408                 RETURN(0);
409
410         rc    = 0;
411         done  = 0;
412         shift = 0;
413         ll_dir_chain_init(&chain);
414
415         page = ll_get_dir_page(inode, pos, 0, &chain);
416
417         while (rc == 0 && !done) {
418                 struct lu_dirpage *dp;
419                 struct lu_dirent  *ent;
420
421                 if (!IS_ERR(page)) {
422                         /*
423                          * If page is empty (end of directory is reached),
424                          * use this value.
425                          */
426                         __u64 hash = DIR_END_OFF;
427                         __u64 next;
428
429                         dp = page_address(page);
430                         for (ent = lu_dirent_start(dp); ent != NULL && !done;
431                              ent = lu_dirent_next(ent)) {
432                                 char          *name;
433                                 int            namelen;
434                                 struct lu_fid  fid;
435                                 ino_t          ino;
436
437                                 /*
438                                  * XXX: implement correct swabbing here.
439                                  */
440
441                                 hash    = le64_to_cpu(ent->lde_hash);
442                                 namelen = le16_to_cpu(ent->lde_namelen);
443
444                                 if (hash < pos)
445                                         /*
446                                          * Skip until we find target hash
447                                          * value.
448                                          */
449                                         continue;
450
451                                 if (namelen == 0)
452                                         /*
453                                          * Skip dummy record.
454                                          */
455                                         continue;
456
457                                 fid  = ent->lde_fid;
458                                 name = ent->lde_name;
459                                 fid_le_to_cpu(&fid, &fid);
460                                 ino  = ll_fid_build_ino(sbi, &fid);
461                                 type = ll_dirent_type_get(ent);
462                                 done = filldir(cookie, name, namelen,
463                                                (loff_t)hash, ino, type);
464                         }
465                         next = le64_to_cpu(dp->ldp_hash_end);
466                         ll_put_page(page);
467                         if (!done) {
468                                 pos = next;
469                                 if (pos == DIR_END_OFF)
470                                         /*
471                                          * End of directory reached.
472                                          */
473                                         done = 1;
474                                 else if (1 /* chain is exhausted*/)
475                                         /*
476                                          * Normal case: continue to the next
477                                          * page.
478                                          */
479                                         page = ll_get_dir_page(inode, pos, 1,
480                                                                &chain);
481                                 else {
482                                         /*
483                                          * go into overflow page.
484                                          */
485                                 }
486                         } else
487                                 pos = hash;
488                 } else {
489                         rc = PTR_ERR(page);
490                         CERROR("error reading dir "DFID" at %lu: rc %d\n",
491                                PFID(&info->lli_fid), (unsigned long)pos, rc);
492                 }
493         }
494
495         filp->f_pos = (loff_t)pos;
496         filp->f_version = inode->i_version;
497         touch_atime(filp->f_vfsmnt, filp->f_dentry);
498
499         ll_dir_chain_fini(&chain);
500
501         RETURN(rc);
502 }
503
504 int ll_send_mgc_param(struct obd_export *mgc, char *string)
505 {
506         struct mgs_send_param *msp;
507         int rc = 0;
508
509         OBD_ALLOC_PTR(msp);
510         if (!msp)
511                 return -ENOMEM;
512
513         strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
514         rc = obd_set_info_async(mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
515                                 sizeof(struct mgs_send_param), msp, NULL);
516         if (rc)
517                 CERROR("Failed to set parameter: %d\n", rc);
518         OBD_FREE_PTR(msp);
519
520         return rc;
521 }
522
523 char *ll_get_fsname(struct inode *inode)
524 {
525         struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
526         char *ptr, *fsname;
527         int len;
528
529         OBD_ALLOC(fsname, MGS_PARAM_MAXLEN);
530         len = strlen(lsi->lsi_lmd->lmd_profile);
531         ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
532         if (ptr && (strcmp(ptr, "-client") == 0))
533                 len -= 7;
534         strncpy(fsname, lsi->lsi_lmd->lmd_profile, len);
535         fsname[len] = '\0';
536
537         return fsname;
538 }
539
540 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
541                      int set_default)
542 {
543         struct ll_sb_info *sbi = ll_i2sbi(inode);
544         struct md_op_data *op_data;
545         struct ptlrpc_request *req = NULL;
546         int rc = 0;
547         struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
548         struct obd_device *mgc = lsi->lsi_mgc;
549         char *fsname = NULL, *param = NULL;
550         int lum_size;
551
552         /*
553          * This is coming from userspace, so should be in
554          * local endian.  But the MDS would like it in little
555          * endian, so we swab it before we send it.
556          */
557         switch (lump->lmm_magic) {
558         case LOV_USER_MAGIC_V1: {
559                 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
560                         lustre_swab_lov_user_md_v1(lump);
561                 lum_size = sizeof(struct lov_user_md_v1);
562                 break;
563                 }
564         case LOV_USER_MAGIC_V3: {
565                 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
566                         lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lump);
567                 lum_size = sizeof(struct lov_user_md_v3);
568                 break;
569                 }
570         default: {
571                 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
572                                 " %#08x != %#08x nor %#08x\n",
573                                 lump->lmm_magic, LOV_USER_MAGIC_V1,
574                                 LOV_USER_MAGIC_V3);
575                 RETURN(-EINVAL);
576                 }
577         }
578
579         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
580                                      LUSTRE_OPC_ANY, NULL);
581         if (IS_ERR(op_data))
582                 RETURN(PTR_ERR(op_data));
583
584         /* swabbing is done in lov_setstripe() on server side */
585         rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
586                         NULL, 0, &req, NULL);
587         ll_finish_md_op_data(op_data);
588         ptlrpc_req_finished(req);
589         if (rc) {
590                 if (rc != -EPERM && rc != -EACCES)
591                         CERROR("mdc_setattr fails: rc = %d\n", rc);
592         }
593
594         /* In the following we use the fact that LOV_USER_MAGIC_V1 and
595          LOV_USER_MAGIC_V3 have the same initial fields so we do not
596          need the make the distiction between the 2 versions */
597         if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
598                 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
599
600                 /* Get fsname and assume devname to be -MDT0000. */
601                 fsname = ll_get_fsname(inode);
602                 /* Set root stripesize */
603                 sprintf(param, "%s-MDT0000.lov.stripesize=%u", fsname,
604                         lump->lmm_stripe_size);
605                 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
606                 if (rc)
607                         goto end;
608
609                 /* Set root stripecount */
610                 sprintf(param, "%s-MDT0000.lov.stripecount=%hd", fsname,
611                         lump->lmm_stripe_count);
612                 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
613                 if (rc)
614                         goto end;
615
616                 /* Set root stripeoffset */
617                 sprintf(param, "%s-MDT0000.lov.stripeoffset=%hd", fsname,
618                         lump->lmm_stripe_offset);
619                 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
620                 if (rc)
621                         goto end;
622 end:
623                 if (fsname)
624                         OBD_FREE(fsname, MGS_PARAM_MAXLEN);
625                 if (param)
626                         OBD_FREE(param, MGS_PARAM_MAXLEN);
627         }
628         return rc;
629 }
630
631 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
632                      int *lmm_size, struct ptlrpc_request **request)
633 {
634         struct ll_sb_info *sbi = ll_i2sbi(inode);
635         struct mdt_body   *body;
636         struct lov_mds_md *lmm = NULL;
637         struct ptlrpc_request *req = NULL;
638         int rc, lmmsize;
639         struct obd_capa *oc;
640
641         rc = ll_get_max_mdsize(sbi, &lmmsize);
642         if (rc)
643                 RETURN(rc);
644
645         oc = ll_mdscapa_get(inode);
646         rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode),
647                         oc, OBD_MD_FLEASIZE | OBD_MD_FLDIREA,
648                         lmmsize, &req);
649         capa_put(oc);
650         if (rc < 0) {
651                 CDEBUG(D_INFO, "md_getattr failed on inode "
652                        "%lu/%u: rc %d\n", inode->i_ino,
653                        inode->i_generation, rc);
654                 GOTO(out, rc);
655         }
656
657         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
658         LASSERT(body != NULL);
659
660         lmmsize = body->eadatasize;
661
662         if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
663             lmmsize == 0) {
664                 GOTO(out, rc = -ENODATA);
665         }
666
667         lmm = req_capsule_server_sized_get(&req->rq_pill,
668                                            &RMF_MDT_MD, lmmsize);
669         LASSERT(lmm != NULL);
670
671         /*
672          * This is coming from the MDS, so is probably in
673          * little endian.  We convert it to host endian before
674          * passing it to userspace.
675          */
676         /* We don't swab objects for directories */
677         switch (le32_to_cpu(lmm->lmm_magic)) {
678         case LOV_MAGIC_V1:
679                 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
680                         lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
681                 break;
682         case LOV_MAGIC_V3:
683                 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
684                         lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
685                 break;
686         default:
687                 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
688                 rc = -EPROTO;
689         }
690 out:
691         *lmmp = lmm;
692         *lmm_size = lmmsize;
693         *request = req;
694         return rc;
695 }
696
697 static int ll_dir_ioctl(struct inode *inode, struct file *file,
698                         unsigned int cmd, unsigned long arg)
699 {
700         struct ll_sb_info *sbi = ll_i2sbi(inode);
701         struct obd_ioctl_data *data;
702         ENTRY;
703
704         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
705                inode->i_ino, inode->i_generation, inode, cmd);
706
707         /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
708         if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
709                 return -ENOTTY;
710
711         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
712         switch(cmd) {
713         case EXT3_IOC_GETFLAGS:
714         case EXT3_IOC_SETFLAGS:
715                 RETURN(ll_iocontrol(inode, file, cmd, arg));
716         case EXT3_IOC_GETVERSION_OLD:
717         case EXT3_IOC_GETVERSION:
718                 RETURN(put_user(inode->i_generation, (int *)arg));
719         /* We need to special case any other ioctls we want to handle,
720          * to send them to the MDS/OST as appropriate and to properly
721          * network encode the arg field.
722         case EXT3_IOC_SETVERSION_OLD:
723         case EXT3_IOC_SETVERSION:
724         */
725         case IOC_MDC_LOOKUP: {
726                 struct ptlrpc_request *request = NULL;
727                 int namelen, rc, len = 0;
728                 char *buf = NULL;
729                 char *filename;
730                 struct obd_capa *oc;
731
732                 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
733                 if (rc)
734                         RETURN(rc);
735                 data = (void *)buf;
736
737                 filename = data->ioc_inlbuf1;
738                 namelen = data->ioc_inllen1;
739
740                 if (namelen < 1) {
741                         CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
742                         GOTO(out, rc = -EINVAL);
743                 }
744
745                 oc = ll_mdscapa_get(inode);
746                 rc = md_getattr_name(sbi->ll_md_exp, ll_inode2fid(inode), oc,
747                                      filename, namelen, OBD_MD_FLID, 0,
748                                      ll_i2suppgid(inode), &request);
749                 capa_put(oc);
750                 if (rc < 0) {
751                         CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
752                         GOTO(out, rc);
753                 }
754
755                 ptlrpc_req_finished(request);
756
757                 EXIT;
758         out:
759                 obd_ioctl_freedata(buf, len);
760                 return rc;
761         }
762         case LL_IOC_LOV_SETSTRIPE: {
763                 struct lov_user_md_v3 lumv3;
764                 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
765                 struct lov_user_md_v1 *lumv1p = (struct lov_user_md_v1 *)arg;
766                 struct lov_user_md_v3 *lumv3p = (struct lov_user_md_v3 *)arg;
767
768                 int rc = 0;
769                 int set_default = 0;
770
771                 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
772                 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
773                         sizeof(lumv3p->lmm_objects[0]));
774                 /* first try with v1 which is smaller than v3 */
775                 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
776                         RETURN(-EFAULT);
777
778                 if (lumv1->lmm_magic == LOV_USER_MAGIC_V3) {
779                         if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
780                                 RETURN(-EFAULT);
781                 }
782
783                 if (inode->i_sb->s_root == file->f_dentry)
784                         set_default = 1;
785
786                 /* in v1 and v3 cases lumv1 points to data */
787                 rc = ll_dir_setstripe(inode, lumv1, set_default);
788
789                 RETURN(rc);
790         }
791         case LL_IOC_OBD_STATFS:
792                 RETURN(ll_obd_statfs(inode, (void *)arg));
793         case LL_IOC_LOV_GETSTRIPE:
794         case LL_IOC_MDC_GETINFO:
795         case IOC_MDC_GETFILEINFO:
796         case IOC_MDC_GETFILESTRIPE: {
797                 struct ptlrpc_request *request = NULL;
798                 struct lov_user_md *lump;
799                 struct lov_mds_md *lmm = NULL;
800                 struct mdt_body *body;
801                 char *filename = NULL;
802                 int rc, lmmsize;
803
804                 if (cmd == IOC_MDC_GETFILEINFO ||
805                     cmd == IOC_MDC_GETFILESTRIPE) {
806                         filename = getname((const char *)arg);
807                         if (IS_ERR(filename))
808                                 RETURN(PTR_ERR(filename));
809
810                         rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
811                                                       &lmmsize, &request);
812                 } else {
813                         rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
814                 }
815
816                 if (request) {
817                         body = req_capsule_server_get(&request->rq_pill,
818                                                       &RMF_MDT_BODY);
819                         LASSERT(body != NULL);
820                 } else {
821                         GOTO(out_req, rc);
822                 }
823
824                 if (rc < 0) {
825                         if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
826                                                cmd == LL_IOC_MDC_GETINFO))
827                                 GOTO(skip_lmm, rc = 0);
828                         else
829                                 GOTO(out_req, rc);
830                 }
831
832                 if (cmd == IOC_MDC_GETFILESTRIPE ||
833                     cmd == LL_IOC_LOV_GETSTRIPE) {
834                         lump = (struct lov_user_md *)arg;
835                 } else {
836                         struct lov_user_mds_data *lmdp;
837                         lmdp = (struct lov_user_mds_data *)arg;
838                         lump = &lmdp->lmd_lmm;
839                 }
840                 if (copy_to_user(lump, lmm, lmmsize))
841                         GOTO(out_lmm, rc = -EFAULT);
842         skip_lmm:
843                 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
844                         struct lov_user_mds_data *lmdp;
845                         lstat_t st = { 0 };
846
847                         st.st_dev     = inode->i_sb->s_dev;
848                         st.st_mode    = body->mode;
849                         st.st_nlink   = body->nlink;
850                         st.st_uid     = body->uid;
851                         st.st_gid     = body->gid;
852                         st.st_rdev    = body->rdev;
853                         st.st_size    = body->size;
854                         st.st_blksize = CFS_PAGE_SIZE;
855                         st.st_blocks  = body->blocks;
856                         st.st_atime   = body->atime;
857                         st.st_mtime   = body->mtime;
858                         st.st_ctime   = body->ctime;
859                         st.st_ino     = inode->i_ino;
860
861                         lmdp = (struct lov_user_mds_data *)arg;
862                         if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
863                                 GOTO(out_lmm, rc = -EFAULT);
864                 }
865
866                 EXIT;
867         out_lmm:
868                 if (lmm && lmm->lmm_magic == LOV_MAGIC_JOIN)
869                         OBD_FREE(lmm, lmmsize);
870         out_req:
871                 ptlrpc_req_finished(request);
872                 if (filename)
873                         putname(filename);
874                 return rc;
875         }
876         case IOC_LOV_GETINFO: {
877                 struct lov_user_mds_data *lumd;
878                 struct lov_stripe_md *lsm;
879                 struct lov_user_md *lum;
880                 struct lov_mds_md *lmm;
881                 int lmmsize;
882                 lstat_t st;
883                 int rc;
884
885                 lumd = (struct lov_user_mds_data *)arg;
886                 lum = &lumd->lmd_lmm;
887
888                 rc = ll_get_max_mdsize(sbi, &lmmsize);
889                 if (rc)
890                         RETURN(rc);
891
892                 OBD_ALLOC(lmm, lmmsize);
893                 if (copy_from_user(lmm, lum, lmmsize))
894                         GOTO(free_lmm, rc = -EFAULT);
895
896                 switch (lmm->lmm_magic) {
897                 case LOV_USER_MAGIC_V1:
898                         if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
899                                 break;
900                         /* swab objects first so that stripes num will be sane */
901                         lustre_swab_lov_user_md_objects(
902                                 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
903                                 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
904                         lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
905                         break;
906                 case LOV_USER_MAGIC_V3:
907                         if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
908                                 break;
909                         /* swab objects first so that stripes num will be sane */
910                         lustre_swab_lov_user_md_objects(
911                                 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
912                                 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
913                         lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
914                         break;
915                 default:
916                         GOTO(free_lmm, rc = -EINVAL);
917                 }
918
919                 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
920                 if (rc < 0)
921                         GOTO(free_lmm, rc = -ENOMEM);
922
923                 rc = obd_checkmd(sbi->ll_dt_exp, sbi->ll_md_exp, lsm);
924                 if (rc)
925                         GOTO(free_lsm, rc);
926
927                 /* Perform glimpse_size operation. */
928                 memset(&st, 0, sizeof(st));
929
930                 rc = ll_glimpse_ioctl(sbi, lsm, &st);
931                 if (rc)
932                         GOTO(free_lsm, rc);
933
934                 if (copy_to_user(&lumd->lmd_st, &st, sizeof(st)))
935                         GOTO(free_lsm, rc = -EFAULT);
936
937                 EXIT;
938         free_lsm:
939                 obd_free_memmd(sbi->ll_dt_exp, &lsm);
940         free_lmm:
941                 OBD_FREE(lmm, lmmsize);
942                 return rc;
943         }
944         case OBD_IOC_LLOG_CATINFO: {
945                 struct ptlrpc_request *req = NULL;
946                 char                  *buf = NULL;
947                 char                  *str;
948                 int                    len = 0;
949                 int                    rc;
950
951                 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
952                 if (rc)
953                         RETURN(rc);
954                 data = (void *)buf;
955
956                 if (!data->ioc_inlbuf1) {
957                         obd_ioctl_freedata(buf, len);
958                         RETURN(-EINVAL);
959                 }
960
961                 req = ptlrpc_request_alloc(sbi2mdc(sbi)->cl_import,
962                                            &RQF_LLOG_CATINFO);
963                 if (req == NULL)
964                         GOTO(out_catinfo, rc = -ENOMEM);
965
966                 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
967                                      data->ioc_inllen1);
968                 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_CLIENT,
969                                      data->ioc_inllen2);
970
971                 rc = ptlrpc_request_pack(req, LUSTRE_LOG_VERSION, LLOG_CATINFO);
972                 if (rc) {
973                         ptlrpc_request_free(req);
974                         GOTO(out_catinfo, rc);
975                 }
976
977                 str = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
978                 memcpy(str, data->ioc_inlbuf1, data->ioc_inllen1);
979                 if (data->ioc_inllen2) {
980                         str = req_capsule_client_get(&req->rq_pill,
981                                                      &RMF_STRING);
982                         memcpy(str, data->ioc_inlbuf2, data->ioc_inllen2);
983                 }
984
985                 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_SERVER,
986                                      data->ioc_plen1);
987                 ptlrpc_request_set_replen(req);
988
989                 rc = ptlrpc_queue_wait(req);
990                 if (!rc) {
991                         str = req_capsule_server_get(&req->rq_pill,
992                                                      &RMF_STRING);
993                         if (copy_to_user(data->ioc_pbuf1, str, data->ioc_plen1))
994                                 rc = -EFAULT;
995                 }
996                 ptlrpc_req_finished(req);
997         out_catinfo:
998                 obd_ioctl_freedata(buf, len);
999                 RETURN(rc);
1000         }
1001         case OBD_IOC_QUOTACHECK: {
1002                 struct obd_quotactl *oqctl;
1003                 int rc, error = 0;
1004
1005                 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1006                     sbi->ll_flags & LL_SBI_RMT_CLIENT)
1007                         RETURN(-EPERM);
1008
1009                 OBD_ALLOC_PTR(oqctl);
1010                 if (!oqctl)
1011                         RETURN(-ENOMEM);
1012                 oqctl->qc_type = arg;
1013                 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1014                 if (rc < 0) {
1015                         CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1016                         error = rc;
1017                 }
1018
1019                 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1020                 if (rc < 0)
1021                         CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1022
1023                 OBD_FREE_PTR(oqctl);
1024                 return error ?: rc;
1025         }
1026         case OBD_IOC_POLL_QUOTACHECK: {
1027                 struct if_quotacheck *check;
1028                 int rc;
1029
1030                 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1031                     sbi->ll_flags & LL_SBI_RMT_CLIENT)
1032                         RETURN(-EPERM);
1033
1034                 OBD_ALLOC_PTR(check);
1035                 if (!check)
1036                         RETURN(-ENOMEM);
1037
1038                 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1039                                    NULL);
1040                 if (rc) {
1041                         CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1042                         if (copy_to_user((void *)arg, check, sizeof(*check)))
1043                                 rc = -EFAULT;
1044                         GOTO(out_poll, rc);
1045                 }
1046
1047                 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1048                                    NULL);
1049                 if (rc) {
1050                         CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1051                         if (copy_to_user((void *)arg, check, sizeof(*check)))
1052                                 rc = -EFAULT;
1053                         GOTO(out_poll, rc);
1054                 }
1055         out_poll:
1056                 OBD_FREE_PTR(check);
1057                 RETURN(rc);
1058         }
1059         case OBD_IOC_QUOTACTL: {
1060                 struct if_quotactl *qctl;
1061                 int cmd, type, id, valid, rc = 0;
1062
1063                 OBD_ALLOC_PTR(qctl);
1064                 if (!qctl)
1065                         RETURN(-ENOMEM);
1066
1067                 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1068                         GOTO(out_quotactl, rc = -EFAULT);
1069
1070                 cmd = qctl->qc_cmd;
1071                 type = qctl->qc_type;
1072                 id = qctl->qc_id;
1073                 valid = qctl->qc_valid;
1074
1075                 switch (cmd) {
1076                 case LUSTRE_Q_INVALIDATE:
1077                 case LUSTRE_Q_FINVALIDATE:
1078                 case Q_QUOTAON:
1079                 case Q_QUOTAOFF:
1080                 case Q_SETQUOTA:
1081                 case Q_SETINFO:
1082                         if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1083                             sbi->ll_flags & LL_SBI_RMT_CLIENT)
1084                                 GOTO(out_quotactl, rc = -EPERM);
1085                         break;
1086                 case Q_GETQUOTA:
1087                         if (((type == USRQUOTA && current->euid != id) ||
1088                              (type == GRPQUOTA && !in_egroup_p(id))) &&
1089                             (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1090                              sbi->ll_flags & LL_SBI_RMT_CLIENT))
1091                                 GOTO(out_quotactl, rc = -EPERM);
1092                         break;
1093                 case Q_GETINFO:
1094                         break;
1095                 default:
1096                         CERROR("unsupported quotactl op: %#x\n", cmd);
1097                         GOTO(out_quotactl, rc = -ENOTTY);
1098                 }
1099
1100                 if (valid != QC_GENERAL) {
1101                         if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
1102                                 GOTO(out_quotactl, rc = -EOPNOTSUPP);
1103
1104                         if (cmd == Q_GETINFO)
1105                                 qctl->qc_cmd = Q_GETOINFO;
1106                         else if (cmd == Q_GETQUOTA)
1107                                 qctl->qc_cmd = Q_GETOQUOTA;
1108                         else
1109                                 GOTO(out_quotactl, rc = -EINVAL);
1110
1111                         switch (valid) {
1112                         case QC_MDTIDX:
1113                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1114                                                    sbi->ll_md_exp,
1115                                                    sizeof(*qctl), qctl, NULL);
1116                                 break;
1117                         case QC_OSTIDX:
1118                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1119                                                    sbi->ll_dt_exp,
1120                                                    sizeof(*qctl), qctl, NULL);
1121                                 break;
1122                         case QC_UUID:
1123                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1124                                                    sbi->ll_md_exp,
1125                                                    sizeof(*qctl), qctl, NULL);
1126                                 if (rc == -EAGAIN)
1127                                         rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1128                                                            sbi->ll_dt_exp,
1129                                                            sizeof(*qctl), qctl,
1130                                                            NULL);
1131                                 break;
1132                         default:
1133                                 rc = -EINVAL;
1134                                 break;
1135                         }
1136
1137                         if (rc)
1138                                 GOTO(out_quotactl, rc);
1139                         else
1140                                 qctl->qc_cmd = cmd;
1141                 } else {
1142                         struct obd_quotactl *oqctl;
1143
1144                         OBD_ALLOC_PTR(oqctl);
1145                         if (!oqctl)
1146                                 GOTO(out_quotactl, rc = -ENOMEM);
1147
1148                         QCTL_COPY(oqctl, qctl);
1149                         rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1150                         if (rc) {
1151                                 if (rc != -EBUSY && cmd == Q_QUOTAON) {
1152                                         oqctl->qc_cmd = Q_QUOTAOFF;
1153                                         obd_quotactl(sbi->ll_md_exp, oqctl);
1154                                 }
1155                                 OBD_FREE_PTR(oqctl);
1156                                 GOTO(out_quotactl, rc);
1157                         } else {
1158                                 QCTL_COPY(qctl, oqctl);
1159                                 OBD_FREE_PTR(oqctl);
1160                         }
1161                 }
1162
1163                 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1164                         rc = -EFAULT;
1165
1166         out_quotactl:
1167                 OBD_FREE_PTR(qctl);
1168                 RETURN(rc);
1169         }
1170         case OBD_IOC_GETNAME: {
1171                 struct obd_device *obd = class_exp2obd(sbi->ll_dt_exp);
1172                 if (!obd)
1173                         RETURN(-EFAULT);
1174                 if (copy_to_user((void *)arg, obd->obd_name,
1175                                 strlen(obd->obd_name) + 1))
1176                         RETURN (-EFAULT);
1177                 RETURN(0);
1178         }
1179         case LL_IOC_FLUSHCTX:
1180                 RETURN(ll_flush_ctx(inode));
1181 #ifdef CONFIG_FS_POSIX_ACL
1182         case LL_IOC_RMTACL: {
1183             if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1184                 inode == inode->i_sb->s_root->d_inode) {
1185                 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1186                 int rc;
1187
1188                 LASSERT(fd != NULL);
1189                 rc = rct_add(&sbi->ll_rct, cfs_curproc_pid(), arg);
1190                 if (!rc)
1191                         fd->fd_flags |= LL_FILE_RMTACL;
1192                 RETURN(rc);
1193             } else
1194                 RETURN(0);
1195         }
1196 #endif
1197         case LL_IOC_GETOBDCOUNT: {
1198                 int count;
1199
1200                 if (copy_from_user(&count, (int *)arg, sizeof(int)))
1201                         RETURN(-EFAULT);
1202
1203                 if (!count) {
1204                         /* get ost count */
1205                         struct lov_obd *lov = &sbi->ll_dt_exp->exp_obd->u.lov;
1206                         count = lov->desc.ld_tgt_count;
1207                 } else {
1208                         /* get mdt count */
1209                         struct lmv_obd *lmv = &sbi->ll_md_exp->exp_obd->u.lmv;
1210                         count = lmv->desc.ld_tgt_count;
1211                 }
1212
1213                 if (copy_to_user((int *)arg, &count, sizeof(int)))
1214                         RETURN(-EFAULT);
1215
1216                 RETURN(0);
1217         }
1218         case LL_IOC_PATH2FID:
1219                 if (copy_to_user((void *)arg, &ll_i2info(inode)->lli_fid,
1220                                  sizeof(struct lu_fid)))
1221                         RETURN(-EFAULT);
1222                 RETURN(0);
1223         case OBD_IOC_CHANGELOG_CLEAR: {
1224                 struct ioc_changelog_clear *icc;
1225                 int rc;
1226
1227                 OBD_ALLOC_PTR(icc);
1228                 if (icc == NULL)
1229                         RETURN(-ENOMEM);
1230                 if (copy_from_user(icc, (void *)arg, sizeof(*icc)))
1231                         GOTO(icc_free, rc = -EFAULT);
1232
1233                 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(*icc), icc,NULL);
1234
1235 icc_free:
1236                 OBD_FREE_PTR(icc);
1237                 RETURN(rc);
1238         }
1239         case OBD_IOC_FID2PATH:
1240                 RETURN(ll_fid2path(ll_i2mdexp(inode), (void *)arg));
1241
1242         default:
1243                 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp,0,NULL,(void *)arg));
1244         }
1245 }
1246
1247 int ll_dir_open(struct inode *inode, struct file *file)
1248 {
1249         ENTRY;
1250         RETURN(ll_file_open(inode, file));
1251 }
1252
1253 int ll_dir_release(struct inode *inode, struct file *file)
1254 {
1255         ENTRY;
1256         RETURN(ll_file_release(inode, file));
1257 }
1258
1259 struct file_operations ll_dir_operations = {
1260         .open     = ll_dir_open,
1261         .release  = ll_dir_release,
1262         .read     = generic_read_dir,
1263         .readdir  = ll_readdir,
1264         .ioctl    = ll_dir_ioctl
1265 };