Whamcloud - gitweb
b=17167 libcfs: ensure all libcfs exported symbols to have cfs_ prefix
[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: "DFID" at "LPU64": rc %d\n",
305                                PFID(ll_inode2fid(dir)), hash, rc);
306                         return ERR_PTR(rc);
307                 }
308         }
309         md_set_lock_data(ll_i2sbi(dir)->ll_md_exp, &lockh.cookie, dir, NULL);
310         ldlm_lock_dump_handle(D_OTHER, &lockh);
311
312         page = ll_dir_page_locate(dir, hash, &start, &end);
313         if (IS_ERR(page)) {
314                 CERROR("dir page locate: "DFID" at "LPU64": rc %ld\n",
315                        PFID(ll_inode2fid(dir)), hash, PTR_ERR(page));
316                 GOTO(out_unlock, page);
317         }
318
319         if (page != NULL) {
320                 /*
321                  * XXX nikita: not entirely correct handling of a corner case:
322                  * suppose hash chain of entries with hash value HASH crosses
323                  * border between pages P0 and P1. First both P0 and P1 are
324                  * cached, seekdir() is called for some entry from the P0 part
325                  * of the chain. Later P0 goes out of cache. telldir(HASH)
326                  * happens and finds P1, as it starts with matching hash
327                  * value. Remaining entries from P0 part of the chain are
328                  * skipped. (Is that really a bug?)
329                  *
330                  * Possible solutions: 0. don't cache P1 is such case, handle
331                  * it as an "overflow" page. 1. invalidate all pages at
332                  * once. 2. use HASH|1 as an index for P1.
333                  */
334                 if (exact && hash != start) {
335                         /*
336                          * readdir asked for a page starting _exactly_ from
337                          * given hash, but cache contains stale page, with
338                          * entries with smaller hash values. Stale page should
339                          * be invalidated, and new one fetched.
340                          */
341                         CDEBUG(D_OTHER, "Stale readpage page %p: "LPX64" != "LPX64"\n",
342                                page, hash, start);
343                         ll_release_page(page, hash, start, end);
344                 } else {
345                         GOTO(hash_collision, page);
346                 }
347         }
348
349         page = read_cache_page(mapping, hash_x_index((unsigned long)hash),
350                                (filler_t*)mapping->a_ops->readpage, NULL);
351         if (IS_ERR(page)) {
352                 CERROR("read cache page: "DFID" at "LPU64": rc %ld\n",
353                        PFID(ll_inode2fid(dir)), hash, PTR_ERR(page));
354                 GOTO(out_unlock, page);
355         }
356
357         wait_on_page(page);
358         (void)kmap(page);
359         if (!PageUptodate(page)) {
360                 CERROR("page not updated: "DFID" at "LPU64": rc %d\n",
361                        PFID(ll_inode2fid(dir)), hash, -5);
362                 goto fail;
363         }
364         if (!PageChecked(page))
365                 ll_check_page(dir, page);
366         if (PageError(page)) {
367                 CERROR("page error: "DFID" at "LPU64": rc %d\n",
368                        PFID(ll_inode2fid(dir)), hash, -5);
369                 goto fail;
370         }
371 hash_collision:
372         dp = page_address(page);
373
374         start = le64_to_cpu(dp->ldp_hash_start);
375         end   = le64_to_cpu(dp->ldp_hash_end);
376         if (end == start) {
377                 LASSERT(start == hash);
378                 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
379                 /*
380                  * Fetch whole overflow chain...
381                  *
382                  * XXX not yet.
383                  */
384                 goto fail;
385         }
386 out_unlock:
387         ldlm_lock_decref(&lockh, mode);
388         return page;
389
390 fail:
391         ll_put_page(page);
392         page = ERR_PTR(-EIO);
393         goto out_unlock;
394 }
395
396 int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
397 {
398         struct inode         *inode = filp->f_dentry->d_inode;
399         struct ll_inode_info *info  = ll_i2info(inode);
400         __u64                 pos   = filp->f_pos;
401         struct page          *page;
402         struct ll_dir_chain   chain;
403         int rc;
404         int done;
405         int shift;
406         __u16 type;
407         ENTRY;
408
409         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu\n",
410                inode->i_ino, inode->i_generation, inode,
411                (unsigned long)pos, i_size_read(inode));
412
413         if (pos == DIR_END_OFF)
414                 /*
415                  * end-of-file.
416                  */
417                 RETURN(0);
418
419         rc    = 0;
420         done  = 0;
421         shift = 0;
422         ll_dir_chain_init(&chain);
423
424         page = ll_get_dir_page(inode, pos, 0, &chain);
425
426         while (rc == 0 && !done) {
427                 struct lu_dirpage *dp;
428                 struct lu_dirent  *ent;
429
430                 if (!IS_ERR(page)) {
431                         /*
432                          * If page is empty (end of directory is reached),
433                          * use this value.
434                          */
435                         __u64 hash = DIR_END_OFF;
436                         __u64 next;
437
438                         dp = page_address(page);
439                         for (ent = lu_dirent_start(dp); ent != NULL && !done;
440                              ent = lu_dirent_next(ent)) {
441                                 char          *name;
442                                 int            namelen;
443                                 struct lu_fid  fid;
444                                 ino_t          ino;
445
446                                 /*
447                                  * XXX: implement correct swabbing here.
448                                  */
449
450                                 hash    = le64_to_cpu(ent->lde_hash);
451                                 namelen = le16_to_cpu(ent->lde_namelen);
452
453                                 if (hash < pos)
454                                         /*
455                                          * Skip until we find target hash
456                                          * value.
457                                          */
458                                         continue;
459
460                                 if (namelen == 0)
461                                         /*
462                                          * Skip dummy record.
463                                          */
464                                         continue;
465
466                                 fid  = ent->lde_fid;
467                                 name = ent->lde_name;
468                                 fid_le_to_cpu(&fid, &fid);
469                                 ino  = cl_fid_build_ino(&fid);
470                                 type = ll_dirent_type_get(ent);
471                                 done = filldir(cookie, name, namelen,
472                                                (loff_t)hash, ino, type);
473                         }
474                         next = le64_to_cpu(dp->ldp_hash_end);
475                         ll_put_page(page);
476                         if (!done) {
477                                 pos = next;
478                                 if (pos == DIR_END_OFF)
479                                         /*
480                                          * End of directory reached.
481                                          */
482                                         done = 1;
483                                 else if (1 /* chain is exhausted*/)
484                                         /*
485                                          * Normal case: continue to the next
486                                          * page.
487                                          */
488                                         page = ll_get_dir_page(inode, pos, 1,
489                                                                &chain);
490                                 else {
491                                         /*
492                                          * go into overflow page.
493                                          */
494                                 }
495                         } else
496                                 pos = hash;
497                 } else {
498                         rc = PTR_ERR(page);
499                         CERROR("error reading dir "DFID" at %lu: rc %d\n",
500                                PFID(&info->lli_fid), (unsigned long)pos, rc);
501                 }
502         }
503
504         filp->f_pos = (loff_t)pos;
505         filp->f_version = inode->i_version;
506         touch_atime(filp->f_vfsmnt, filp->f_dentry);
507
508         ll_dir_chain_fini(&chain);
509
510         RETURN(rc);
511 }
512
513 int ll_send_mgc_param(struct obd_export *mgc, char *string)
514 {
515         struct mgs_send_param *msp;
516         int rc = 0;
517
518         OBD_ALLOC_PTR(msp);
519         if (!msp)
520                 return -ENOMEM;
521
522         strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
523         rc = obd_set_info_async(mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
524                                 sizeof(struct mgs_send_param), msp, NULL);
525         if (rc)
526                 CERROR("Failed to set parameter: %d\n", rc);
527         OBD_FREE_PTR(msp);
528
529         return rc;
530 }
531
532 char *ll_get_fsname(struct inode *inode)
533 {
534         struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
535         char *ptr, *fsname;
536         int len;
537
538         OBD_ALLOC(fsname, MGS_PARAM_MAXLEN);
539         len = strlen(lsi->lsi_lmd->lmd_profile);
540         ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
541         if (ptr && (strcmp(ptr, "-client") == 0))
542                 len -= 7;
543         strncpy(fsname, lsi->lsi_lmd->lmd_profile, len);
544         fsname[len] = '\0';
545
546         return fsname;
547 }
548
549 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
550                      int set_default)
551 {
552         struct ll_sb_info *sbi = ll_i2sbi(inode);
553         struct md_op_data *op_data;
554         struct ptlrpc_request *req = NULL;
555         int rc = 0;
556         struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
557         struct obd_device *mgc = lsi->lsi_mgc;
558         char *fsname = NULL, *param = NULL;
559         int lum_size;
560
561         /*
562          * This is coming from userspace, so should be in
563          * local endian.  But the MDS would like it in little
564          * endian, so we swab it before we send it.
565          */
566         switch (lump->lmm_magic) {
567         case LOV_USER_MAGIC_V1: {
568                 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
569                         lustre_swab_lov_user_md_v1(lump);
570                 lum_size = sizeof(struct lov_user_md_v1);
571                 break;
572                 }
573         case LOV_USER_MAGIC_V3: {
574                 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
575                         lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lump);
576                 lum_size = sizeof(struct lov_user_md_v3);
577                 break;
578                 }
579         default: {
580                 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
581                                 " %#08x != %#08x nor %#08x\n",
582                                 lump->lmm_magic, LOV_USER_MAGIC_V1,
583                                 LOV_USER_MAGIC_V3);
584                 RETURN(-EINVAL);
585                 }
586         }
587
588         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
589                                      LUSTRE_OPC_ANY, NULL);
590         if (IS_ERR(op_data))
591                 RETURN(PTR_ERR(op_data));
592
593         /* swabbing is done in lov_setstripe() on server side */
594         rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
595                         NULL, 0, &req, NULL);
596         ll_finish_md_op_data(op_data);
597         ptlrpc_req_finished(req);
598         if (rc) {
599                 if (rc != -EPERM && rc != -EACCES)
600                         CERROR("mdc_setattr fails: rc = %d\n", rc);
601         }
602
603         /* In the following we use the fact that LOV_USER_MAGIC_V1 and
604          LOV_USER_MAGIC_V3 have the same initial fields so we do not
605          need the make the distiction between the 2 versions */
606         if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
607                 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
608
609                 /* Get fsname and assume devname to be -MDT0000. */
610                 fsname = ll_get_fsname(inode);
611                 /* Set root stripesize */
612                 sprintf(param, "%s-MDT0000.lov.stripesize=%u", fsname,
613                         lump->lmm_stripe_size);
614                 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
615                 if (rc)
616                         goto end;
617
618                 /* Set root stripecount */
619                 sprintf(param, "%s-MDT0000.lov.stripecount=%hd", fsname,
620                         lump->lmm_stripe_count);
621                 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
622                 if (rc)
623                         goto end;
624
625                 /* Set root stripeoffset */
626                 sprintf(param, "%s-MDT0000.lov.stripeoffset=%hd", fsname,
627                         lump->lmm_stripe_offset);
628                 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
629                 if (rc)
630                         goto end;
631 end:
632                 if (fsname)
633                         OBD_FREE(fsname, MGS_PARAM_MAXLEN);
634                 if (param)
635                         OBD_FREE(param, MGS_PARAM_MAXLEN);
636         }
637         return rc;
638 }
639
640 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
641                      int *lmm_size, struct ptlrpc_request **request)
642 {
643         struct ll_sb_info *sbi = ll_i2sbi(inode);
644         struct mdt_body   *body;
645         struct lov_mds_md *lmm = NULL;
646         struct ptlrpc_request *req = NULL;
647         int rc, lmmsize;
648         struct obd_capa *oc;
649
650         rc = ll_get_max_mdsize(sbi, &lmmsize);
651         if (rc)
652                 RETURN(rc);
653
654         oc = ll_mdscapa_get(inode);
655         rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode),
656                         oc, OBD_MD_FLEASIZE | OBD_MD_FLDIREA,
657                         lmmsize, &req);
658         capa_put(oc);
659         if (rc < 0) {
660                 CDEBUG(D_INFO, "md_getattr failed on inode "
661                        "%lu/%u: rc %d\n", inode->i_ino,
662                        inode->i_generation, rc);
663                 GOTO(out, rc);
664         }
665
666         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
667         LASSERT(body != NULL);
668
669         lmmsize = body->eadatasize;
670
671         if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
672             lmmsize == 0) {
673                 GOTO(out, rc = -ENODATA);
674         }
675
676         lmm = req_capsule_server_sized_get(&req->rq_pill,
677                                            &RMF_MDT_MD, lmmsize);
678         LASSERT(lmm != NULL);
679
680         /*
681          * This is coming from the MDS, so is probably in
682          * little endian.  We convert it to host endian before
683          * passing it to userspace.
684          */
685         /* We don't swab objects for directories */
686         switch (le32_to_cpu(lmm->lmm_magic)) {
687         case LOV_MAGIC_V1:
688                 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
689                         lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
690                 break;
691         case LOV_MAGIC_V3:
692                 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
693                         lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
694                 break;
695         default:
696                 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
697                 rc = -EPROTO;
698         }
699 out:
700         *lmmp = lmm;
701         *lmm_size = lmmsize;
702         *request = req;
703         return rc;
704 }
705
706 static int ll_dir_ioctl(struct inode *inode, struct file *file,
707                         unsigned int cmd, unsigned long arg)
708 {
709         struct ll_sb_info *sbi = ll_i2sbi(inode);
710         struct obd_ioctl_data *data;
711         ENTRY;
712
713         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
714                inode->i_ino, inode->i_generation, inode, cmd);
715
716         /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
717         if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
718                 return -ENOTTY;
719
720         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
721         switch(cmd) {
722         case FSFILT_IOC_GETFLAGS:
723         case FSFILT_IOC_SETFLAGS:
724                 RETURN(ll_iocontrol(inode, file, cmd, arg));
725         case FSFILT_IOC_GETVERSION_OLD:
726         case FSFILT_IOC_GETVERSION:
727                 RETURN(put_user(inode->i_generation, (int *)arg));
728         /* We need to special case any other ioctls we want to handle,
729          * to send them to the MDS/OST as appropriate and to properly
730          * network encode the arg field.
731         case FSFILT_IOC_SETVERSION_OLD:
732         case FSFILT_IOC_SETVERSION:
733         */
734         case IOC_MDC_LOOKUP: {
735                 struct ptlrpc_request *request = NULL;
736                 int namelen, rc, len = 0;
737                 char *buf = NULL;
738                 char *filename;
739                 struct obd_capa *oc;
740
741                 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
742                 if (rc)
743                         RETURN(rc);
744                 data = (void *)buf;
745
746                 filename = data->ioc_inlbuf1;
747                 namelen = data->ioc_inllen1;
748
749                 if (namelen < 1) {
750                         CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
751                         GOTO(out, rc = -EINVAL);
752                 }
753
754                 oc = ll_mdscapa_get(inode);
755                 rc = md_getattr_name(sbi->ll_md_exp, ll_inode2fid(inode), oc,
756                                      filename, namelen, OBD_MD_FLID, 0,
757                                      ll_i2suppgid(inode), &request);
758                 capa_put(oc);
759                 if (rc < 0) {
760                         CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
761                         GOTO(out, rc);
762                 }
763
764                 ptlrpc_req_finished(request);
765
766                 EXIT;
767         out:
768                 obd_ioctl_freedata(buf, len);
769                 return rc;
770         }
771         case LL_IOC_LOV_SETSTRIPE: {
772                 struct lov_user_md_v3 lumv3;
773                 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
774                 struct lov_user_md_v1 *lumv1p = (struct lov_user_md_v1 *)arg;
775                 struct lov_user_md_v3 *lumv3p = (struct lov_user_md_v3 *)arg;
776
777                 int rc = 0;
778                 int set_default = 0;
779
780                 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
781                 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
782                         sizeof(lumv3p->lmm_objects[0]));
783                 /* first try with v1 which is smaller than v3 */
784                 if (cfs_copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
785                         RETURN(-EFAULT);
786
787                 if (lumv1->lmm_magic == LOV_USER_MAGIC_V3) {
788                         if (cfs_copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
789                                 RETURN(-EFAULT);
790                 }
791
792                 if (inode->i_sb->s_root == file->f_dentry)
793                         set_default = 1;
794
795                 /* in v1 and v3 cases lumv1 points to data */
796                 rc = ll_dir_setstripe(inode, lumv1, set_default);
797
798                 RETURN(rc);
799         }
800         case LL_IOC_OBD_STATFS:
801                 RETURN(ll_obd_statfs(inode, (void *)arg));
802         case LL_IOC_LOV_GETSTRIPE:
803         case LL_IOC_MDC_GETINFO:
804         case IOC_MDC_GETFILEINFO:
805         case IOC_MDC_GETFILESTRIPE: {
806                 struct ptlrpc_request *request = NULL;
807                 struct lov_user_md *lump;
808                 struct lov_mds_md *lmm = NULL;
809                 struct mdt_body *body;
810                 char *filename = NULL;
811                 int rc, lmmsize;
812
813                 if (cmd == IOC_MDC_GETFILEINFO ||
814                     cmd == IOC_MDC_GETFILESTRIPE) {
815                         filename = getname((const char *)arg);
816                         if (IS_ERR(filename))
817                                 RETURN(PTR_ERR(filename));
818
819                         rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
820                                                       &lmmsize, &request);
821                 } else {
822                         rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
823                 }
824
825                 if (request) {
826                         body = req_capsule_server_get(&request->rq_pill,
827                                                       &RMF_MDT_BODY);
828                         LASSERT(body != NULL);
829                 } else {
830                         GOTO(out_req, rc);
831                 }
832
833                 if (rc < 0) {
834                         if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
835                                                cmd == LL_IOC_MDC_GETINFO))
836                                 GOTO(skip_lmm, rc = 0);
837                         else
838                                 GOTO(out_req, rc);
839                 }
840
841                 if (cmd == IOC_MDC_GETFILESTRIPE ||
842                     cmd == LL_IOC_LOV_GETSTRIPE) {
843                         lump = (struct lov_user_md *)arg;
844                 } else {
845                         struct lov_user_mds_data *lmdp;
846                         lmdp = (struct lov_user_mds_data *)arg;
847                         lump = &lmdp->lmd_lmm;
848                 }
849                 if (cfs_copy_to_user(lump, lmm, lmmsize))
850                         GOTO(out_req, rc = -EFAULT);
851         skip_lmm:
852                 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
853                         struct lov_user_mds_data *lmdp;
854                         lstat_t st = { 0 };
855
856                         st.st_dev     = inode->i_sb->s_dev;
857                         st.st_mode    = body->mode;
858                         st.st_nlink   = body->nlink;
859                         st.st_uid     = body->uid;
860                         st.st_gid     = body->gid;
861                         st.st_rdev    = body->rdev;
862                         st.st_size    = body->size;
863                         st.st_blksize = CFS_PAGE_SIZE;
864                         st.st_blocks  = body->blocks;
865                         st.st_atime   = body->atime;
866                         st.st_mtime   = body->mtime;
867                         st.st_ctime   = body->ctime;
868                         st.st_ino     = inode->i_ino;
869
870                         lmdp = (struct lov_user_mds_data *)arg;
871                         if (cfs_copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
872                                 GOTO(out_req, rc = -EFAULT);
873                 }
874
875                 EXIT;
876         out_req:
877                 ptlrpc_req_finished(request);
878                 if (filename)
879                         putname(filename);
880                 return rc;
881         }
882         case IOC_LOV_GETINFO: {
883                 struct lov_user_mds_data *lumd;
884                 struct lov_stripe_md *lsm;
885                 struct lov_user_md *lum;
886                 struct lov_mds_md *lmm;
887                 int lmmsize;
888                 lstat_t st;
889                 int rc;
890
891                 lumd = (struct lov_user_mds_data *)arg;
892                 lum = &lumd->lmd_lmm;
893
894                 rc = ll_get_max_mdsize(sbi, &lmmsize);
895                 if (rc)
896                         RETURN(rc);
897
898                 OBD_ALLOC(lmm, lmmsize);
899                 if (cfs_copy_from_user(lmm, lum, lmmsize))
900                         GOTO(free_lmm, rc = -EFAULT);
901
902                 switch (lmm->lmm_magic) {
903                 case LOV_USER_MAGIC_V1:
904                         if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
905                                 break;
906                         /* swab objects first so that stripes num will be sane */
907                         lustre_swab_lov_user_md_objects(
908                                 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
909                                 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
910                         lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
911                         break;
912                 case LOV_USER_MAGIC_V3:
913                         if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
914                                 break;
915                         /* swab objects first so that stripes num will be sane */
916                         lustre_swab_lov_user_md_objects(
917                                 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
918                                 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
919                         lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
920                         break;
921                 default:
922                         GOTO(free_lmm, rc = -EINVAL);
923                 }
924
925                 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
926                 if (rc < 0)
927                         GOTO(free_lmm, rc = -ENOMEM);
928
929                 /* Perform glimpse_size operation. */
930                 memset(&st, 0, sizeof(st));
931
932                 rc = ll_glimpse_ioctl(sbi, lsm, &st);
933                 if (rc)
934                         GOTO(free_lsm, rc);
935
936                 if (cfs_copy_to_user(&lumd->lmd_st, &st, sizeof(st)))
937                         GOTO(free_lsm, rc = -EFAULT);
938
939                 EXIT;
940         free_lsm:
941                 obd_free_memmd(sbi->ll_dt_exp, &lsm);
942         free_lmm:
943                 OBD_FREE(lmm, lmmsize);
944                 return rc;
945         }
946         case OBD_IOC_LLOG_CATINFO: {
947                 struct ptlrpc_request *req = NULL;
948                 char                  *buf = NULL;
949                 char                  *str;
950                 int                    len = 0;
951                 int                    rc;
952
953                 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
954                 if (rc)
955                         RETURN(rc);
956                 data = (void *)buf;
957
958                 if (!data->ioc_inlbuf1) {
959                         obd_ioctl_freedata(buf, len);
960                         RETURN(-EINVAL);
961                 }
962
963                 req = ptlrpc_request_alloc(sbi2mdc(sbi)->cl_import,
964                                            &RQF_LLOG_CATINFO);
965                 if (req == NULL)
966                         GOTO(out_catinfo, rc = -ENOMEM);
967
968                 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
969                                      data->ioc_inllen1);
970                 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_CLIENT,
971                                      data->ioc_inllen2);
972
973                 rc = ptlrpc_request_pack(req, LUSTRE_LOG_VERSION, LLOG_CATINFO);
974                 if (rc) {
975                         ptlrpc_request_free(req);
976                         GOTO(out_catinfo, rc);
977                 }
978
979                 str = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
980                 memcpy(str, data->ioc_inlbuf1, data->ioc_inllen1);
981                 if (data->ioc_inllen2) {
982                         str = req_capsule_client_get(&req->rq_pill,
983                                                      &RMF_STRING);
984                         memcpy(str, data->ioc_inlbuf2, data->ioc_inllen2);
985                 }
986
987                 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_SERVER,
988                                      data->ioc_plen1);
989                 ptlrpc_request_set_replen(req);
990
991                 rc = ptlrpc_queue_wait(req);
992                 if (!rc) {
993                         str = req_capsule_server_get(&req->rq_pill,
994                                                      &RMF_STRING);
995                         if (cfs_copy_to_user(data->ioc_pbuf1, str,
996                                              data->ioc_plen1))
997                                 rc = -EFAULT;
998                 }
999                 ptlrpc_req_finished(req);
1000         out_catinfo:
1001                 obd_ioctl_freedata(buf, len);
1002                 RETURN(rc);
1003         }
1004         case OBD_IOC_QUOTACHECK: {
1005                 struct obd_quotactl *oqctl;
1006                 int rc, error = 0;
1007
1008                 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1009                     sbi->ll_flags & LL_SBI_RMT_CLIENT)
1010                         RETURN(-EPERM);
1011
1012                 OBD_ALLOC_PTR(oqctl);
1013                 if (!oqctl)
1014                         RETURN(-ENOMEM);
1015                 oqctl->qc_type = arg;
1016                 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1017                 if (rc < 0) {
1018                         CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1019                         error = rc;
1020                 }
1021
1022                 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1023                 if (rc < 0)
1024                         CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1025
1026                 OBD_FREE_PTR(oqctl);
1027                 return error ?: rc;
1028         }
1029         case OBD_IOC_POLL_QUOTACHECK: {
1030                 struct if_quotacheck *check;
1031                 int rc;
1032
1033                 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1034                     sbi->ll_flags & LL_SBI_RMT_CLIENT)
1035                         RETURN(-EPERM);
1036
1037                 OBD_ALLOC_PTR(check);
1038                 if (!check)
1039                         RETURN(-ENOMEM);
1040
1041                 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1042                                    NULL);
1043                 if (rc) {
1044                         CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1045                         if (cfs_copy_to_user((void *)arg, check,
1046                                              sizeof(*check)))
1047                                 rc = -EFAULT;
1048                         GOTO(out_poll, rc);
1049                 }
1050
1051                 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1052                                    NULL);
1053                 if (rc) {
1054                         CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1055                         if (cfs_copy_to_user((void *)arg, check,
1056                                              sizeof(*check)))
1057                                 rc = -EFAULT;
1058                         GOTO(out_poll, rc);
1059                 }
1060         out_poll:
1061                 OBD_FREE_PTR(check);
1062                 RETURN(rc);
1063         }
1064         case OBD_IOC_QUOTACTL: {
1065                 struct if_quotactl *qctl;
1066                 int cmd, type, id, valid, rc = 0;
1067
1068                 OBD_ALLOC_PTR(qctl);
1069                 if (!qctl)
1070                         RETURN(-ENOMEM);
1071
1072                 if (cfs_copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1073                         GOTO(out_quotactl, rc = -EFAULT);
1074
1075                 cmd = qctl->qc_cmd;
1076                 type = qctl->qc_type;
1077                 id = qctl->qc_id;
1078                 valid = qctl->qc_valid;
1079
1080                 switch (cmd) {
1081                 case LUSTRE_Q_INVALIDATE:
1082                 case LUSTRE_Q_FINVALIDATE:
1083                 case Q_QUOTAON:
1084                 case Q_QUOTAOFF:
1085                 case Q_SETQUOTA:
1086                 case Q_SETINFO:
1087                         if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1088                             sbi->ll_flags & LL_SBI_RMT_CLIENT)
1089                                 GOTO(out_quotactl, rc = -EPERM);
1090                         break;
1091                 case Q_GETQUOTA:
1092                         if (((type == USRQUOTA && current->euid != id) ||
1093                              (type == GRPQUOTA && !in_egroup_p(id))) &&
1094                             (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1095                              sbi->ll_flags & LL_SBI_RMT_CLIENT))
1096                                 GOTO(out_quotactl, rc = -EPERM);
1097                         break;
1098                 case Q_GETINFO:
1099                         break;
1100                 default:
1101                         CERROR("unsupported quotactl op: %#x\n", cmd);
1102                         GOTO(out_quotactl, rc = -ENOTTY);
1103                 }
1104
1105                 if (valid != QC_GENERAL) {
1106                         if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
1107                                 GOTO(out_quotactl, rc = -EOPNOTSUPP);
1108
1109                         if (cmd == Q_GETINFO)
1110                                 qctl->qc_cmd = Q_GETOINFO;
1111                         else if (cmd == Q_GETQUOTA)
1112                                 qctl->qc_cmd = Q_GETOQUOTA;
1113                         else
1114                                 GOTO(out_quotactl, rc = -EINVAL);
1115
1116                         switch (valid) {
1117                         case QC_MDTIDX:
1118                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1119                                                    sbi->ll_md_exp,
1120                                                    sizeof(*qctl), qctl, NULL);
1121                                 break;
1122                         case QC_OSTIDX:
1123                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1124                                                    sbi->ll_dt_exp,
1125                                                    sizeof(*qctl), qctl, NULL);
1126                                 break;
1127                         case QC_UUID:
1128                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1129                                                    sbi->ll_md_exp,
1130                                                    sizeof(*qctl), qctl, NULL);
1131                                 if (rc == -EAGAIN)
1132                                         rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1133                                                            sbi->ll_dt_exp,
1134                                                            sizeof(*qctl), qctl,
1135                                                            NULL);
1136                                 break;
1137                         default:
1138                                 rc = -EINVAL;
1139                                 break;
1140                         }
1141
1142                         if (rc)
1143                                 GOTO(out_quotactl, rc);
1144                         else
1145                                 qctl->qc_cmd = cmd;
1146                 } else {
1147                         struct obd_quotactl *oqctl;
1148
1149                         OBD_ALLOC_PTR(oqctl);
1150                         if (!oqctl)
1151                                 GOTO(out_quotactl, rc = -ENOMEM);
1152
1153                         QCTL_COPY(oqctl, qctl);
1154                         rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1155                         if (rc) {
1156                                 if (rc != -EALREADY && cmd == Q_QUOTAON) {
1157                                         oqctl->qc_cmd = Q_QUOTAOFF;
1158                                         obd_quotactl(sbi->ll_md_exp, oqctl);
1159                                 }
1160                                 OBD_FREE_PTR(oqctl);
1161                                 GOTO(out_quotactl, rc);
1162                         } else {
1163                                 QCTL_COPY(qctl, oqctl);
1164                                 OBD_FREE_PTR(oqctl);
1165                         }
1166                 }
1167
1168                 if (cfs_copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1169                         rc = -EFAULT;
1170
1171         out_quotactl:
1172                 OBD_FREE_PTR(qctl);
1173                 RETURN(rc);
1174         }
1175         case OBD_IOC_GETNAME: {
1176                 struct obd_device *obd = class_exp2obd(sbi->ll_dt_exp);
1177                 if (!obd)
1178                         RETURN(-EFAULT);
1179                 if (cfs_copy_to_user((void *)arg, obd->obd_name,
1180                                      strlen(obd->obd_name) + 1))
1181                         RETURN (-EFAULT);
1182                 RETURN(0);
1183         }
1184         case LL_IOC_FLUSHCTX:
1185                 RETURN(ll_flush_ctx(inode));
1186 #ifdef CONFIG_FS_POSIX_ACL
1187         case LL_IOC_RMTACL: {
1188             if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1189                 inode == inode->i_sb->s_root->d_inode) {
1190                 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1191                 int rc;
1192
1193                 LASSERT(fd != NULL);
1194                 rc = rct_add(&sbi->ll_rct, cfs_curproc_pid(), arg);
1195                 if (!rc)
1196                         fd->fd_flags |= LL_FILE_RMTACL;
1197                 RETURN(rc);
1198             } else
1199                 RETURN(0);
1200         }
1201 #endif
1202         case LL_IOC_GETOBDCOUNT: {
1203                 int count;
1204
1205                 if (cfs_copy_from_user(&count, (int *)arg, sizeof(int)))
1206                         RETURN(-EFAULT);
1207
1208                 if (!count) {
1209                         /* get ost count */
1210                         struct lov_obd *lov = &sbi->ll_dt_exp->exp_obd->u.lov;
1211                         count = lov->desc.ld_tgt_count;
1212                 } else {
1213                         /* get mdt count */
1214                         struct lmv_obd *lmv = &sbi->ll_md_exp->exp_obd->u.lmv;
1215                         count = lmv->desc.ld_tgt_count;
1216                 }
1217
1218                 if (cfs_copy_to_user((int *)arg, &count, sizeof(int)))
1219                         RETURN(-EFAULT);
1220
1221                 RETURN(0);
1222         }
1223         case LL_IOC_PATH2FID:
1224                 if (cfs_copy_to_user((void *)arg, ll_inode2fid(inode),
1225                                      sizeof(struct lu_fid)))
1226                         RETURN(-EFAULT);
1227                 RETURN(0);
1228         case OBD_IOC_CHANGELOG_CLEAR: {
1229                 struct ioc_changelog_clear *icc;
1230                 int rc;
1231
1232                 OBD_ALLOC_PTR(icc);
1233                 if (icc == NULL)
1234                         RETURN(-ENOMEM);
1235                 if (cfs_copy_from_user(icc, (void *)arg, sizeof(*icc)))
1236                         GOTO(icc_free, rc = -EFAULT);
1237
1238                 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(*icc), icc,NULL);
1239
1240 icc_free:
1241                 OBD_FREE_PTR(icc);
1242                 RETURN(rc);
1243         }
1244         case OBD_IOC_FID2PATH:
1245                 RETURN(ll_fid2path(ll_i2mdexp(inode), (void *)arg));
1246
1247         default:
1248                 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp,0,NULL,(void *)arg));
1249         }
1250 }
1251
1252 int ll_dir_open(struct inode *inode, struct file *file)
1253 {
1254         ENTRY;
1255         RETURN(ll_file_open(inode, file));
1256 }
1257
1258 int ll_dir_release(struct inode *inode, struct file *file)
1259 {
1260         ENTRY;
1261         RETURN(ll_file_release(inode, file));
1262 }
1263
1264 struct file_operations ll_dir_operations = {
1265         .open     = ll_dir_open,
1266         .release  = ll_dir_release,
1267         .read     = generic_read_dir,
1268         .readdir  = ll_readdir,
1269         .ioctl    = ll_dir_ioctl
1270 };