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