Whamcloud - gitweb
822110fc9712f293ed3f8f98fe9dc2a1d1a74351
[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  * Copyright (C) 1992, 1993, 1994, 1995
5  * Remy Card (card@masi.ibp.fr)
6  * Laboratoire MASI - Institut Blaise Pascal
7  * Universite Pierre et Marie Curie (Paris VI)
8  *
9  *  from
10  *
11  *  linux/fs/minix/dir.c
12  *  linux/fs/ext2/dir.c
13  *
14  *  Copyright (C) 1991, 1992  Linus Torvalds
15  *
16  *  ext2 directory handling functions
17  *
18  *  Big-endian to little-endian byte-swapping/bitmaps by
19  *        David S. Miller (davem@caip.rutgers.edu), 1995
20  *
21  *  All code that works with directory layout had been switched to pagecache
22  *  and moved here. AV
23  *
24  *  Adapted for Lustre Light
25  *  Copyright (C) 2002-2003, Cluster File Systems, Inc.
26  *
27  */
28
29 #include <linux/fs.h>
30 #include <linux/ext2_fs.h>
31 #include <linux/pagemap.h>
32 #include <linux/mm.h>
33 #include <linux/version.h>
34 #include <linux/smp_lock.h>
35 #include <asm/uaccess.h>
36 #include <linux/file.h>
37 #include <linux/kmod.h>
38 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
39 # include <linux/locks.h>   // for wait_on_buffer
40 #else
41 # include <linux/buffer_head.h>   // for wait_on_buffer
42 #endif
43
44 #define DEBUG_SUBSYSTEM S_LLITE
45
46 #include <linux/obd_support.h>
47 #include <linux/obd_class.h>
48 #include <linux/lustre_lib.h>
49 #include <linux/lustre_idl.h>
50 #include <linux/lustre_mds.h>
51 #include <linux/lustre_lite.h>
52 #include <linux/lustre_dlm.h>
53 #include "llite_internal.h"
54
55 typedef struct ext2_dir_entry_2 ext2_dirent;
56
57 #define PageChecked(page)        test_bit(PG_checked, &(page)->flags)
58 #define SetPageChecked(page)     set_bit(PG_checked, &(page)->flags)
59
60 /* returns the page unlocked, but with a reference */
61 static int ll_dir_readpage(struct file *file, struct page *page)
62 {
63         struct inode *inode = page->mapping->host;
64         struct ll_fid mdc_fid;
65         __u64 offset;
66         struct ptlrpc_request *request;
67         struct mds_body *body;
68         int rc = 0;
69         ENTRY;
70
71         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
72                inode->i_generation, inode);
73
74         mdc_pack_fid(&mdc_fid, inode->i_ino, inode->i_generation, S_IFDIR);
75         mdc_fid.mds = ll_i2info(inode)->lli_mds;
76         offset = page->index << PAGE_SHIFT;
77         rc = md_readpage(ll_i2sbi(inode)->ll_mdc_exp, &mdc_fid,
78                          offset, page, &request);
79         if (!rc) {
80                 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof (*body));
81                 LASSERT (body != NULL);         /* checked by md_readpage() */
82                 LASSERT_REPSWABBED (request, 0); /* swabbed by md_readpage() */
83
84 #warning "FIXME ASAP!"
85                 //inode->i_size = body->size;
86                 SetPageUptodate(page);
87         }
88         ptlrpc_req_finished(request);
89
90         unlock_page(page);
91         EXIT;
92         return rc;
93 }
94
95 struct address_space_operations ll_dir_aops = {
96         .readpage  = ll_dir_readpage,
97 };
98
99 /*
100  * ext2 uses block-sized chunks. Arguably, sector-sized ones would be
101  * more robust, but we have what we have
102  */
103 static inline unsigned ext2_chunk_size(struct inode *inode)
104 {
105         return inode->i_sb->s_blocksize;
106 }
107
108 static inline void ext2_put_page(struct page *page)
109 {
110         kunmap(page);
111         page_cache_release(page);
112 }
113
114 static inline unsigned long dir_pages(struct inode *inode)
115 {
116         return (inode->i_size+PAGE_CACHE_SIZE-1)>>PAGE_CACHE_SHIFT;
117 }
118
119
120 static void ext2_check_page(struct page *page)
121 {
122         struct inode *dir = page->mapping->host;
123         unsigned chunk_size = ext2_chunk_size(dir);
124         char *kaddr = page_address(page);
125         //      u32 max_inumber = le32_to_cpu(sb->u.ext2_sb.s_es->s_inodes_count);
126         unsigned offs, rec_len;
127         unsigned limit = PAGE_CACHE_SIZE;
128         ext2_dirent *p;
129         char *error;
130
131         if ((dir->i_size >> PAGE_CACHE_SHIFT) == page->index) {
132                 limit = dir->i_size & ~PAGE_CACHE_MASK;
133                 if (limit & (chunk_size - 1)) {
134                         CERROR("limit %d dir size %lld index %ld\n",
135                                limit, dir->i_size, page->index);
136                         goto Ebadsize;
137                 }
138                 for (offs = limit; offs<PAGE_CACHE_SIZE; offs += chunk_size) {
139                         ext2_dirent *p = (ext2_dirent*)(kaddr + offs);
140                         p->rec_len = cpu_to_le16(chunk_size);
141                         p->name_len = 0;
142                         p->inode = 0;
143                 }
144                 if (!limit)
145                         goto out;
146         }
147         for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
148                 p = (ext2_dirent *)(kaddr + offs);
149                 rec_len = le16_to_cpu(p->rec_len);
150
151                 if (rec_len < EXT2_DIR_REC_LEN(1))
152                         goto Eshort;
153                 if (rec_len & 3)
154                         goto Ealign;
155                 if (rec_len < EXT2_DIR_REC_LEN(p->name_len))
156                         goto Enamelen;
157                 if (((offs + rec_len - 1) ^ offs) & ~(chunk_size-1))
158                         goto Espan;
159                 //              if (le32_to_cpu(p->inode) > max_inumber)
160                 //goto Einumber;
161         }
162         if (offs != limit)
163                 goto Eend;
164 out:
165         SetPageChecked(page);
166         return;
167
168         /* Too bad, we had an error */
169
170 Ebadsize:
171         CERROR("ext2_check_page"
172                 "size of directory #%lu is not a multiple of chunk size\n",
173                 dir->i_ino
174         );
175         goto fail;
176 Eshort:
177         error = "rec_len is smaller than minimal";
178         goto bad_entry;
179 Ealign:
180         error = "unaligned directory entry";
181         goto bad_entry;
182 Enamelen:
183         error = "rec_len is too small for name_len";
184         goto bad_entry;
185 Espan:
186         error = "directory entry across blocks";
187         goto bad_entry;
188         //Einumber:
189         // error = "inode out of bounds";
190 bad_entry:
191         CERROR("ext2_check_page: bad entry in directory #%lu: %s - "
192                 "offset=%lu+%u, inode=%lu, rec_len=%d, name_len=%d",
193                 dir->i_ino, error, (page->index<<PAGE_CACHE_SHIFT), offs,
194                 (unsigned long) le32_to_cpu(p->inode),
195                 rec_len, p->name_len);
196         goto fail;
197 Eend:
198         p = (ext2_dirent *)(kaddr + offs);
199         CERROR("ext2_check_page"
200                 "entry in directory #%lu spans the page boundary"
201                 "offset=%lu, inode=%lu",
202                 dir->i_ino, (page->index<<PAGE_CACHE_SHIFT)+offs,
203                 (unsigned long) le32_to_cpu(p->inode));
204 fail:
205         SetPageChecked(page);
206         SetPageError(page);
207 }
208
209 static struct page *ll_get_dir_page(struct inode *dir, unsigned long n)
210 {
211         struct ldlm_res_id res_id =
212                 { .name = { dir->i_ino, (__u64)dir->i_generation} };
213         struct lustre_handle lockh;
214         struct obd_device *obddev = class_exp2obd(ll_i2sbi(dir)->ll_mdc_exp);
215         struct address_space *mapping = dir->i_mapping;
216         struct page *page;
217         ldlm_policy_data_t policy = { .l_inodebits = { MDS_INODELOCK_UPDATE } };
218         int rc;
219
220         obddev = md_get_real_obd(ll_i2sbi(dir)->ll_mdc_exp, NULL, 0);
221         rc = ldlm_lock_match(obddev->obd_namespace, LDLM_FL_BLOCK_GRANTED,
222                              &res_id, LDLM_IBITS, &policy, LCK_PR, &lockh);
223         if (!rc) {
224                 struct lookup_intent it = { .it_op = IT_READDIR };
225                 struct ptlrpc_request *request;
226                 struct mdc_op_data data;
227
228                 ll_prepare_mdc_op_data(&data, dir, NULL, NULL, 0, 0);
229
230                 rc = md_enqueue(ll_i2sbi(dir)->ll_mdc_exp, LDLM_IBITS, &it,
231                                 LCK_PR, &data, &lockh, NULL, 0,
232                                 ldlm_completion_ast, ll_mdc_blocking_ast, dir);
233
234                 request = (struct ptlrpc_request *)it.d.lustre.it_data;
235                 if (request)
236                         ptlrpc_req_finished(request);
237                 if (rc < 0) {
238                         CERROR("lock enqueue: rc: %d\n", rc);
239                         return ERR_PTR(rc);
240                 }
241         }
242         ldlm_lock_dump_handle(D_OTHER, &lockh);
243
244         page = read_cache_page(mapping, n,
245                                (filler_t*)mapping->a_ops->readpage, NULL);
246         if (!IS_ERR(page)) {
247                 wait_on_page(page);
248                 (void)kmap(page);
249                 if (!PageUptodate(page))
250                         goto fail;
251                 if (!PageChecked(page))
252                         ext2_check_page(page);
253                 if (PageError(page))
254                         goto fail;
255         }
256
257 out_unlock:
258         ldlm_lock_decref(&lockh, LCK_PR);
259         return page;
260
261 fail:
262         ext2_put_page(page);
263         page = ERR_PTR(-EIO);
264         goto out_unlock;
265 }
266
267 /*
268  * p is at least 6 bytes before the end of page
269  */
270 static inline ext2_dirent *ext2_next_entry(ext2_dirent *p)
271 {
272         return (ext2_dirent *)((char*)p + le16_to_cpu(p->rec_len));
273 }
274
275 static inline unsigned
276 ext2_validate_entry(char *base, unsigned offset, unsigned mask)
277 {
278         ext2_dirent *de = (ext2_dirent*)(base + offset);
279         ext2_dirent *p = (ext2_dirent*)(base + (offset&mask));
280         while ((char*)p < (char*)de)
281                 p = ext2_next_entry(p);
282         return (char *)p - base;
283 }
284
285 static unsigned char ext2_filetype_table[EXT2_FT_MAX] = {
286         [EXT2_FT_UNKNOWN]       DT_UNKNOWN,
287         [EXT2_FT_REG_FILE]      DT_REG,
288         [EXT2_FT_DIR]           DT_DIR,
289         [EXT2_FT_CHRDEV]        DT_CHR,
290         [EXT2_FT_BLKDEV]        DT_BLK,
291         [EXT2_FT_FIFO]          DT_FIFO,
292         [EXT2_FT_SOCK]          DT_SOCK,
293         [EXT2_FT_SYMLINK]       DT_LNK,
294 };
295
296
297 int ll_readdir(struct file * filp, void * dirent, filldir_t filldir)
298 {
299         struct inode *inode = filp->f_dentry->d_inode;
300         loff_t pos = filp->f_pos;
301         // XXX struct super_block *sb = inode->i_sb;
302         unsigned offset = pos & ~PAGE_CACHE_MASK;
303         unsigned long n = pos >> PAGE_CACHE_SHIFT;
304         unsigned long npages = dir_pages(inode);
305         unsigned chunk_mask = ~(ext2_chunk_size(inode)-1);
306         unsigned char *types = NULL;
307         int need_revalidate = (filp->f_version != inode->i_version);
308         int rc = 0;
309         ENTRY;
310
311         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %llu/%llu\n",
312                inode->i_ino, inode->i_generation, inode, pos, inode->i_size);
313
314         if (pos > inode->i_size - EXT2_DIR_REC_LEN(1))
315                 RETURN(0);
316
317         types = ext2_filetype_table;
318
319         for ( ; n < npages; n++, offset = 0) {
320                 char *kaddr, *limit;
321                 ext2_dirent *de;
322                 struct page *page;
323
324                 CDEBUG(D_EXT2,"read %lu of dir %lu/%u page %lu/%lu size %llu\n",
325                        PAGE_CACHE_SIZE, inode->i_ino, inode->i_generation,
326                        n, npages, inode->i_size);
327                 page = ll_get_dir_page(inode, n);
328
329                 /* size might have been updated by md_readpage() */
330                 npages = dir_pages(inode);
331
332                 if (IS_ERR(page)) {
333                         rc = PTR_ERR(page);
334                         CERROR("error reading dir %lu/%u page %lu: rc %d\n",
335                                inode->i_ino, inode->i_generation, n, rc);
336                         continue;
337                 }
338
339                 kaddr = page_address(page);
340                 if (need_revalidate) {
341                         offset = ext2_validate_entry(kaddr, offset, chunk_mask);
342                         need_revalidate = 0;
343                 }
344                 de = (ext2_dirent *)(kaddr+offset);
345                 limit = kaddr + PAGE_CACHE_SIZE - EXT2_DIR_REC_LEN(1);
346                 for ( ;(char*)de <= limit; de = ext2_next_entry(de)) {
347                         if (de->inode) {
348                                 int over;
349                                 unsigned char d_type = DT_UNKNOWN;
350                                 
351                                 
352                                 rc = 0; /* no error if we return something */
353                                 if (types && de->file_type < EXT2_FT_MAX)
354                                         d_type = types[de->file_type];
355
356                                 offset = (char *)de - kaddr;
357                                 over = filldir(dirent, de->name, de->name_len,
358                                                (n<<PAGE_CACHE_SHIFT) | offset,
359                                                le32_to_cpu(de->inode), d_type);
360                                 if (over) {
361                                         ext2_put_page(page);
362                                         GOTO(done, rc);
363                                 }
364                         }
365                 }
366                 ext2_put_page(page);
367         }
368
369 done:
370         filp->f_pos = (n << PAGE_CACHE_SHIFT) | offset;
371         filp->f_version = inode->i_version;
372         update_atime(inode);
373         RETURN(rc);
374 }
375
376 static int ll_mkdir_stripe(struct inode *inode, unsigned long arg)
377 {
378         char *name;
379         struct ll_user_mkdir_stripe lums;
380         struct ptlrpc_request *request = NULL;
381         struct ll_sb_info *sbi = ll_i2sbi(inode);
382         struct mdc_op_data op_data;
383         u16 nstripes;
384         mode_t mode;
385         int err = 0;
386         ENTRY;
387
388         if (copy_from_user(&lums, (void *)arg, sizeof(lums)))
389                 RETURN(-EFAULT);
390
391         if (lums.lums_namelen <= 0)
392                 RETURN(-EINVAL);
393         OBD_ALLOC(name, lums.lums_namelen);
394         if (!name)
395                 RETURN(-ENOMEM);
396
397         if (copy_from_user(name, lums.lums_name, lums.lums_namelen))
398                 GOTO(out, err=-EFAULT);
399
400         CDEBUG(D_VFSTRACE, "ioctl Op:name=%s,dir=%lu/%u(%p)\n",
401                name, inode->i_ino, inode->i_generation, inode);
402         nstripes = lums.lums_nstripes;
403
404         mode = lums.lums_mode;
405         mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
406         ll_prepare_mdc_op_data(&op_data, inode, NULL, name,lums.lums_namelen,0);
407         err = md_create(sbi->ll_mdc_exp, &op_data, &nstripes, sizeof(nstripes),
408                         mode, current->fsuid, current->fsgid, 0, &request);
409         ptlrpc_req_finished(request);
410
411 out:
412         OBD_FREE(name, lums.lums_namelen);
413         RETURN(err);
414 }
415
416 static int ll_dir_ioctl(struct inode *inode, struct file *file,
417                         unsigned int cmd, unsigned long arg)
418 {
419         struct ll_sb_info *sbi = ll_i2sbi(inode);
420         struct obd_ioctl_data *data;
421         ENTRY;
422
423         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
424                inode->i_ino, inode->i_generation, inode, cmd);
425
426         if (_IOC_TYPE(cmd) == 'T') /* tty ioctls */
427                 return -ENOTTY;
428
429         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_IOCTL);
430         switch(cmd) {
431         case EXT3_IOC_GETFLAGS:
432         case EXT3_IOC_SETFLAGS:
433                 RETURN(ll_iocontrol(inode, file, cmd, arg));
434         case IOC_MDC_LOOKUP: {
435                 struct ptlrpc_request *request = NULL;
436                 struct ll_fid fid;
437                 char *buf = NULL;
438                 char *filename;
439                 int namelen, rc, len = 0;
440                 unsigned long valid;
441
442                 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
443                 if (rc)
444                         RETURN(rc);
445                 data = (void *)buf;
446
447                 filename = data->ioc_inlbuf1;
448                 namelen = data->ioc_inllen1;
449
450                 if (namelen < 1) {
451                         CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
452                         GOTO(out, rc = -EINVAL);
453                 }
454
455                 valid = OBD_MD_FLID;
456                 ll_inode2fid(&fid, inode);
457                 rc = md_getattr_name(sbi->ll_mdc_exp, &fid,
458                                      filename, namelen, valid, 0, &request);
459                 if (rc < 0) {
460                         CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
461                         GOTO(out, rc);
462                 }
463
464                 ptlrpc_req_finished(request);
465
466                 EXIT;
467         out:
468                 obd_ioctl_freedata(buf, len);
469                 return rc;
470         }
471         case LL_IOC_MDC_MKDIRSTRIPE:
472                 RETURN(ll_mkdir_stripe(inode, arg));
473         case IOC_MDC_FINISH_GNS:
474                 RETURN(ll_finish_gns(sbi));
475         case LL_IOC_LOV_SETSTRIPE: {
476                 struct ptlrpc_request *request = NULL;
477                 struct mdc_op_data op_data;
478                 struct iattr attr = { 0 };
479                 struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
480                 int rc = 0;
481
482                 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
483
484                 LASSERT(sizeof(lum) == sizeof(*lump));
485                 LASSERT(sizeof(lum.lmm_objects[0]) ==
486                         sizeof(lump->lmm_objects[0]));
487                 rc = copy_from_user(&lum, lump, sizeof(lum));
488                 if (rc)
489                         return(-EFAULT);
490
491                 if (lum.lmm_magic != LOV_USER_MAGIC)
492                         RETURN(-EINVAL);
493
494                 rc = md_setattr(sbi->ll_mdc_exp, &op_data,
495                                 &attr, &lum, sizeof(lum), NULL, 0, &request);
496                 if (rc) {
497                         ptlrpc_req_finished(request);
498                         if (rc != -EPERM && rc != -EACCES)
499                                 CERROR("md_setattr fails: rc = %d\n", rc);
500                         return rc;
501                 }
502                 ptlrpc_req_finished(request);
503
504                 return rc;
505         }
506         case LL_IOC_LOV_GETSTRIPE: {
507                 struct ptlrpc_request *request = NULL;
508                 struct lov_user_md *lump = (struct lov_user_md *)arg;
509                 struct lov_mds_md *lmm;
510                 struct ll_fid fid;
511                 struct mds_body *body;
512                 unsigned long valid = 0;
513                 int rc, lmmsize;
514
515                 valid |= OBD_MD_FLDIREA;
516
517                 ll_inode2fid(&fid, inode);
518                 rc = md_getattr(sbi->ll_mdc_exp, &fid, valid,
519                                 obd_size_diskmd(sbi->ll_osc_exp, NULL),
520                                 &request);
521                 if (rc < 0) {
522                         CDEBUG(D_INFO, "md_getattr failed: rc = %d\n", rc);
523                         RETURN(rc);
524                 }
525
526                 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body));
527                 LASSERT(body != NULL);         /* checked by md_getattr_name */
528                 LASSERT_REPSWABBED(request, 0);/* swabbed by md_getattr_name */
529
530                 lmmsize = body->eadatasize;
531                 if (lmmsize == 0)
532                         GOTO(out_get, rc = -ENODATA);
533
534                 lmm = lustre_msg_buf(request->rq_repmsg, 1, lmmsize);
535                 LASSERT(lmm != NULL);
536                 LASSERT_REPSWABBED(request, 1);
537                 rc = copy_to_user(lump, lmm, lmmsize);
538                 if (rc)
539                         GOTO(out_get, rc = -EFAULT);
540
541                 EXIT;
542         out_get:
543                 ptlrpc_req_finished(request);
544                 RETURN(rc);
545         }
546         case IOC_MDC_GETSTRIPE: {
547                 struct ptlrpc_request *request = NULL;
548                 struct ll_fid fid;
549                 struct mds_body *body;
550                 struct lov_user_md *lump = (struct lov_user_md *)arg;
551                 struct lov_mds_md *lmm;
552                 char *filename;
553                 int rc, lmmsize;
554
555                 filename = getname((const char *)arg);
556                 if (IS_ERR(filename))
557                         RETURN(PTR_ERR(filename));
558
559                 ll_inode2fid(&fid, inode);
560                 rc = md_getattr_name(sbi->ll_mdc_exp, &fid, filename,
561                                      strlen(filename) + 1, OBD_MD_FLEASIZE,
562                                      obd_size_diskmd(sbi->ll_osc_exp, NULL),
563                                      &request);
564                 if (rc < 0) {
565                         CDEBUG(D_INFO, "md_getattr_name failed on %s: rc %d\n",
566                                filename, rc);
567                         GOTO(out_name, rc);
568                 }
569
570                 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof (*body));
571                 LASSERT(body != NULL);         /* checked by md_getattr_name */
572                 LASSERT_REPSWABBED(request, 0);/* swabbed by md_getattr_name */
573
574                 lmmsize = body->eadatasize;
575
576                 if (!(body->valid & OBD_MD_FLEASIZE) || lmmsize == 0)
577                         GOTO(out_req, rc = -ENODATA);
578
579                 if (lmmsize > 4096)
580                         GOTO(out_req, rc = -EFBIG);
581
582                 lmm = lustre_msg_buf(request->rq_repmsg, 1, lmmsize);
583                 LASSERT(lmm != NULL);
584                 LASSERT_REPSWABBED(request, 1);
585
586                 rc = copy_to_user(lump, lmm, lmmsize);
587                 if (rc)
588                         GOTO(out_req, rc = -EFAULT);
589
590                 EXIT;
591         out_req:
592                 ptlrpc_req_finished(request);
593         out_name:
594                 putname(filename);
595                 return rc;
596         }
597         case OBD_IOC_PING: {
598                 struct ptlrpc_request *req = NULL;
599                 char *buf = NULL;
600                 int rc, len=0;
601                 struct client_obd *cli;
602                 struct obd_device *obd;
603
604                 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
605                 if (rc)
606                         RETURN(rc);
607                 data = (void *)buf;
608
609                 obd = class_name2obd(data->ioc_inlbuf1);
610
611                 if (!obd )
612                         GOTO(out_ping, rc = -ENODEV);
613
614                 if (!obd->obd_attached) {
615                         CERROR("Device %d not attached\n", obd->obd_minor);
616                         GOTO(out_ping, rc = -ENODEV);
617                 }
618                 if (!obd->obd_set_up) {
619                         CERROR("Device %d still not setup\n", obd->obd_minor);
620                         GOTO(out_ping, rc = -ENODEV);
621                 }
622                 cli = &obd->u.cli;
623                 req = ptlrpc_prep_req(cli->cl_import, OBD_PING, 0, NULL, NULL);
624                 if (!req)
625                         GOTO(out_ping, rc = -ENOMEM);
626
627                 req->rq_replen = lustre_msg_size(0, NULL);
628                 req->rq_send_state = LUSTRE_IMP_FULL;
629
630                 rc = ptlrpc_queue_wait(req);
631
632                 ptlrpc_req_finished(req);
633         out_ping:
634                 obd_ioctl_freedata(buf, len);
635                 return rc;
636         }
637         case OBD_IOC_LLOG_CATINFO: {
638                 struct ptlrpc_request *req = NULL;
639                 char *buf = NULL;
640                 int rc, len = 0;
641                 char *bufs[2], *str;
642                 int lens[2], size;
643
644                 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
645                 if (rc)
646                         RETURN(rc);
647                 data = (void *)buf;
648
649                 if (!data->ioc_inlbuf1) {
650                         obd_ioctl_freedata(buf, len);
651                         RETURN(-EINVAL);
652                 }
653
654                 lens[0] = data->ioc_inllen1;
655                 bufs[0] = data->ioc_inlbuf1;
656                 if (data->ioc_inllen2) {
657                         lens[1] = data->ioc_inllen2;
658                         bufs[1] = data->ioc_inlbuf2;
659                 } else {
660                         lens[1] = 0;
661                         bufs[1] = NULL;
662                 }
663                 size = data->ioc_plen1;
664                 req = ptlrpc_prep_req(sbi2mdc(sbi)->cl_import, LLOG_CATINFO,
665                                       2, lens, bufs);
666                 if (!req)
667                         GOTO(out_catinfo, rc = -ENOMEM);
668                 req->rq_replen = lustre_msg_size(1, &size);
669
670                 rc = ptlrpc_queue_wait(req);
671                 str = lustre_msg_string(req->rq_repmsg, 0, data->ioc_plen1);
672                 if (!rc)
673                         rc = copy_to_user(data->ioc_pbuf1, str,
674                                           data->ioc_plen1);
675                 ptlrpc_req_finished(req);
676         out_catinfo:
677                 obd_ioctl_freedata(buf, len);
678                 RETURN(rc);
679         }
680         default:
681                 return obd_iocontrol(cmd, sbi->ll_osc_exp,0,NULL,(void *)arg);
682         }
683 }
684
685 int ll_dir_open(struct inode *inode, struct file *file)
686 {
687         ENTRY;
688         RETURN(ll_file_open(inode, file));
689 }
690
691 int ll_dir_release(struct inode *inode, struct file *file)
692 {
693         ENTRY;
694         RETURN(ll_file_release(inode, file));
695 }
696
697 struct file_operations ll_dir_operations = {
698         .open     = ll_dir_open,
699         .release  = ll_dir_release,
700         .read     = generic_read_dir,
701         .readdir  = ll_readdir,
702         .ioctl    = ll_dir_ioctl
703 };
704