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