Whamcloud - gitweb
LU-10698 obdclass: allow specifying complex jobids
[fs/lustre-release.git] / lustre / obdclass / linux / linux-module.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/obdclass/linux/linux-module.c
33  *
34  * Object Devices Class Driver
35  * These are the only exported functions, they provide some generic
36  * infrastructure for managing object devices
37  */
38
39 #define DEBUG_SUBSYSTEM S_CLASS
40
41 #include <linux/module.h>
42 #include <linux/errno.h>
43 #include <linux/kernel.h>
44 #include <linux/sched.h>
45 #include <linux/lp.h>
46 #include <linux/slab.h>
47 #include <linux/ioport.h>
48 #include <linux/fcntl.h>
49 #include <linux/delay.h>
50 #include <linux/skbuff.h>
51 #include <linux/proc_fs.h>
52 #include <linux/fs.h>
53 #include <linux/poll.h>
54 #include <linux/init.h>
55 #include <linux/list.h>
56 #include <linux/highmem.h>
57 #include <asm/io.h>
58 #include <asm/ioctls.h>
59 #include <asm/poll.h>
60 #include <asm/uaccess.h>
61 #include <linux/miscdevice.h>
62 #include <linux/seq_file.h>
63 #include <linux/kobject.h>
64
65 #include <libcfs/libcfs.h>
66 #include <obd_support.h>
67 #include <obd_class.h>
68 #include <lprocfs_status.h>
69 #include <uapi/linux/lnet/lnetctl.h>
70 #include <uapi/linux/lustre/lustre_ioctl.h>
71 #include <uapi/linux/lustre/lustre_ver.h>
72
73 #define OBD_MAX_IOCTL_BUFFER    8192
74
75 static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
76 {
77         if (data->ioc_len > BIT(30)) {
78                 CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
79                 return 1;
80         }
81
82         if (data->ioc_inllen1 > BIT(30)) {
83                 CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
84                 return 1;
85         }
86
87         if (data->ioc_inllen2 > BIT(30)) {
88                 CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
89                 return 1;
90         }
91
92         if (data->ioc_inllen3 > BIT(30)) {
93                 CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
94                 return 1;
95         }
96
97         if (data->ioc_inllen4 > BIT(30)) {
98                 CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
99                 return 1;
100         }
101
102         if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) {
103                 CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
104                 return 1;
105         }
106
107         if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) {
108                 CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
109                 return 1;
110         }
111
112         if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) {
113                 CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
114                 return 1;
115         }
116
117         if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) {
118                 CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
119                 return 1;
120         }
121
122         if (data->ioc_pbuf1 && data->ioc_plen1 == 0) {
123                 CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
124                 return 1;
125         }
126
127         if (data->ioc_pbuf2 && data->ioc_plen2 == 0) {
128                 CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
129                 return 1;
130         }
131
132         if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) {
133                 CERROR("OBD ioctl: plen1 set but NULL pointer\n");
134                 return 1;
135         }
136
137         if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) {
138                 CERROR("OBD ioctl: plen2 set but NULL pointer\n");
139                 return 1;
140         }
141
142         if (obd_ioctl_packlen(data) > data->ioc_len) {
143                 CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
144                        obd_ioctl_packlen(data), data->ioc_len);
145                 return 1;
146         }
147
148         return 0;
149 }
150
151 /* buffer MUST be at least the size of obd_ioctl_hdr */
152 int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
153 {
154         struct obd_ioctl_hdr hdr;
155         struct obd_ioctl_data *data;
156         int offset = 0;
157         ENTRY;
158
159         if (copy_from_user(&hdr, arg, sizeof(hdr)))
160                 RETURN(-EFAULT);
161
162         if (hdr.ioc_version != OBD_IOCTL_VERSION) {
163                 CERROR("Version mismatch kernel (%x) vs application (%x)\n",
164                        OBD_IOCTL_VERSION, hdr.ioc_version);
165                 RETURN(-EINVAL);
166         }
167
168         if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
169                 CERROR("User buffer len %d exceeds %d max buffer\n",
170                        hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
171                 RETURN(-EINVAL);
172         }
173
174         if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
175                 CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len);
176                 RETURN(-EINVAL);
177         }
178
179         /* When there are lots of processes calling vmalloc on multi-core
180          * system, the high lock contention will hurt performance badly,
181          * obdfilter-survey is an example, which relies on ioctl. So we'd
182          * better avoid vmalloc on ioctl path. LU-66 */
183         OBD_ALLOC_LARGE(*buf, hdr.ioc_len);
184         if (*buf == NULL) {
185                 CERROR("Cannot allocate control buffer of len %d\n",
186                        hdr.ioc_len);
187                 RETURN(-EINVAL);
188         }
189         *len = hdr.ioc_len;
190         data = (struct obd_ioctl_data *)*buf;
191
192         if (copy_from_user(*buf, arg, hdr.ioc_len)) {
193                 OBD_FREE_LARGE(*buf, hdr.ioc_len);
194                 RETURN(-EFAULT);
195         }
196
197         if (obd_ioctl_is_invalid(data)) {
198                 CERROR("ioctl not correctly formatted\n");
199                 OBD_FREE_LARGE(*buf, hdr.ioc_len);
200                 RETURN(-EINVAL);
201         }
202
203         if (data->ioc_inllen1) {
204                 data->ioc_inlbuf1 = &data->ioc_bulk[0];
205                 offset += cfs_size_round(data->ioc_inllen1);
206         }
207
208         if (data->ioc_inllen2) {
209                 data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
210                 offset += cfs_size_round(data->ioc_inllen2);
211         }
212
213         if (data->ioc_inllen3) {
214                 data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
215                 offset += cfs_size_round(data->ioc_inllen3);
216         }
217
218         if (data->ioc_inllen4)
219                 data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
220
221         RETURN(0);
222 }
223 EXPORT_SYMBOL(obd_ioctl_getdata);
224
225 /*  opening /dev/obd */
226 static int obd_class_open(struct inode * inode, struct file * file)
227 {
228         ENTRY;
229
230         try_module_get(THIS_MODULE);
231         RETURN(0);
232 }
233
234 /*  closing /dev/obd */
235 static int obd_class_release(struct inode * inode, struct file * file)
236 {
237         ENTRY;
238
239         module_put(THIS_MODULE);
240         RETURN(0);
241 }
242
243 /* to control /dev/obd */
244 static long obd_class_ioctl(struct file *filp, unsigned int cmd,
245                             unsigned long arg)
246 {
247         int err = 0;
248         ENTRY;
249
250         /* Allow non-root access for OBD_IOC_PING_TARGET - used by lfs check */
251         if (!cfs_capable(CFS_CAP_SYS_ADMIN) && (cmd != OBD_IOC_PING_TARGET))
252                 RETURN(err = -EACCES);
253         if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
254                 RETURN(err = -ENOTTY);
255
256         err = class_handle_ioctl(cmd, (unsigned long)arg);
257
258         RETURN(err);
259 }
260
261 /* declare character device */
262 static struct file_operations obd_psdev_fops = {
263         .owner          = THIS_MODULE,
264         .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */
265         .open           = obd_class_open,      /* open */
266         .release        = obd_class_release,   /* release */
267 };
268
269 /* modules setup */
270 struct miscdevice obd_psdev = {
271         .minor  = MISC_DYNAMIC_MINOR,
272         .name   = OBD_DEV_NAME,
273         .fops   = &obd_psdev_fops,
274 };
275
276 struct static_lustre_uintvalue_attr {
277         struct {
278                 struct attribute attr;
279                 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
280                                 char *buf);
281                 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
282                                  const char *buf, size_t len);
283         } u;
284         int *value;
285 };
286
287 static ssize_t static_uintvalue_show(struct kobject *kobj,
288                                      struct attribute *attr,
289                                      char *buf)
290 {
291         struct static_lustre_uintvalue_attr *lattr = (void *)attr;
292
293         return sprintf(buf, "%d\n", *lattr->value);
294 }
295
296 static ssize_t static_uintvalue_store(struct kobject *kobj,
297                                       struct attribute *attr,
298                                       const char *buffer, size_t count)
299 {
300         struct static_lustre_uintvalue_attr *lattr = (void *)attr;
301         unsigned int val;
302         int rc;
303
304         rc = kstrtouint(buffer, 10, &val);
305         if (rc)
306                 return rc;
307
308         *lattr->value = val;
309
310         return count;
311 }
312
313 #define LUSTRE_STATIC_UINT_ATTR(name, value)                            \
314 static struct static_lustre_uintvalue_attr lustre_sattr_##name =        \
315         { __ATTR(name, 0644, static_uintvalue_show,                     \
316                  static_uintvalue_store), value }
317
318 LUSTRE_STATIC_UINT_ATTR(timeout, &obd_timeout);
319 LUSTRE_STATIC_UINT_ATTR(debug_peer_on_timeout, &obd_debug_peer_on_timeout);
320 LUSTRE_STATIC_UINT_ATTR(dump_on_timeout, &obd_dump_on_timeout);
321 LUSTRE_STATIC_UINT_ATTR(dump_on_eviction, &obd_dump_on_eviction);
322 LUSTRE_STATIC_UINT_ATTR(at_min, &at_min);
323 LUSTRE_STATIC_UINT_ATTR(at_max, &at_max);
324 LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra);
325 LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin);
326 LUSTRE_STATIC_UINT_ATTR(at_history, &at_history);
327
328 #ifdef HAVE_SERVER_SUPPORT
329 LUSTRE_STATIC_UINT_ATTR(ldlm_timeout, &ldlm_timeout);
330 LUSTRE_STATIC_UINT_ATTR(bulk_timeout, &bulk_timeout);
331 #endif
332
333 static ssize_t memused_show(struct kobject *kobj, struct attribute *attr,
334                             char *buf)
335 {
336         return sprintf(buf, "%llu\n", obd_memory_sum());
337 }
338 LUSTRE_RO_ATTR(memused);
339
340 static ssize_t memused_max_show(struct kobject *kobj, struct attribute *attr,
341                                 char *buf)
342 {
343         return sprintf(buf, "%llu\n", obd_memory_max());
344 }
345 LUSTRE_RO_ATTR(memused_max);
346
347 static ssize_t max_dirty_mb_show(struct kobject *kobj, struct attribute *attr,
348                                  char *buf)
349 {
350         return sprintf(buf, "%lu\n",
351                        obd_max_dirty_pages / (1 << (20 - PAGE_SHIFT)));
352 }
353
354 static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
355                                   const char *buffer, size_t count)
356 {
357         unsigned long val;
358         int rc;
359
360         rc = kstrtoul(buffer, 10, &val);
361         if (rc)
362                 return rc;
363
364         val *= 1 << (20 - PAGE_SHIFT); /* convert to pages */
365
366         if (val > ((totalram_pages / 10) * 9)) {
367                 /* Somebody wants to assign too much memory to dirty pages */
368                 return -EINVAL;
369         }
370
371         if (val < 4 << (20 - PAGE_SHIFT)) {
372                 /* Less than 4 Mb for dirty cache is also bad */
373                 return -EINVAL;
374         }
375
376         obd_max_dirty_pages = val;
377
378         return count;
379 }
380 LUSTRE_RW_ATTR(max_dirty_mb);
381
382 static ssize_t version_show(struct kobject *kobj, struct attribute *attr,
383                             char *buf)
384 {
385         return sprintf(buf, "%s\n", LUSTRE_VERSION_STRING);
386 }
387
388 static ssize_t pinger_show(struct kobject *kobj, struct attribute *attr,
389                            char *buf)
390 {
391 #ifdef ENABLE_PINGER
392         const char *state = "on";
393 #else
394         const char *state = "off";
395 #endif
396         return sprintf(buf, "%s\n", state);
397 }
398
399 /**
400  * Check all obd devices health
401  *
402  * \param kobj
403  * \param buf [in]
404  *
405  * \retval number of characters printed if healthy
406  */
407 static ssize_t
408 health_check_show(struct kobject *kobj, struct attribute *attr, char *buf)
409 {
410         bool healthy = true;
411         size_t len = 0;
412         int i;
413
414         if (libcfs_catastrophe) {
415                 len = sprintf(buf, "LBUG\n");
416                 healthy = false;
417         }
418
419         read_lock(&obd_dev_lock);
420         for (i = 0; i < class_devno_max(); i++) {
421                 struct obd_device *obd;
422
423                 obd = class_num2obd(i);
424                 if (obd == NULL || !obd->obd_attached || !obd->obd_set_up)
425                         continue;
426
427                 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
428                 if (obd->obd_stopping)
429                         continue;
430
431                 class_incref(obd, __FUNCTION__, current);
432                 read_unlock(&obd_dev_lock);
433
434                 if (obd_health_check(NULL, obd)) {
435                         len = sprintf(buf, "device %s reported unhealthy\n",
436                                       obd->obd_name);
437                         healthy = false;
438                 }
439                 class_decref(obd, __FUNCTION__, current);
440                 read_lock(&obd_dev_lock);
441         }
442         read_unlock(&obd_dev_lock);
443
444         if (healthy)
445                 len = sprintf(buf, "healthy\n");
446         else
447                 len = sprintf(buf, "NOT HEALTHY\n");
448
449         return len;
450 }
451
452 static ssize_t jobid_var_show(struct kobject *kobj, struct attribute *attr,
453                               char *buf)
454 {
455         int rc = 0;
456
457         if (strlen(obd_jobid_var))
458                 rc = snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_var);
459         return rc;
460 }
461
462 static ssize_t jobid_var_store(struct kobject *kobj, struct attribute *attr,
463                                const char *buffer, size_t count)
464 {
465         if (!count || count > JOBSTATS_JOBID_VAR_MAX_LEN)
466                 return -EINVAL;
467
468         memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1);
469
470         memcpy(obd_jobid_var, buffer, count);
471
472         /* Trim the trailing '\n' if any */
473         if (obd_jobid_var[count - 1] == '\n')
474                 obd_jobid_var[count - 1] = 0;
475
476         return count;
477 }
478
479 static ssize_t jobid_name_show(struct kobject *kobj, struct attribute *attr,
480                                char *buf)
481 {
482         int rc = 0;
483
484         if (strlen(obd_jobid_name))
485                 rc = snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_name);
486         return rc;
487 }
488
489 static ssize_t jobid_name_store(struct kobject *kobj, struct attribute *attr,
490                                 const char *buffer, size_t count)
491 {
492         if (!count || count > LUSTRE_JOBID_SIZE)
493                 return -EINVAL;
494
495         if (strcmp(obd_jobid_var, JOBSTATS_NODELOCAL) != 0 &&
496             !strchr(buffer, '%')) {
497                 lustre_jobid_clear(buffer);
498                 return count;
499         }
500
501         /* clear previous value */
502         memset(obd_jobid_name, 0, LUSTRE_JOBID_SIZE);
503
504         memcpy(obd_jobid_name, buffer, count);
505
506         /* Trim the trailing '\n' if any */
507         if (obd_jobid_name[count - 1] == '\n') {
508                 /* Don't echo just a newline */
509                 if (count == 1)
510                         return -EINVAL;
511                 obd_jobid_name[count - 1] = 0;
512         }
513
514         return count;
515 }
516
517 /* Root for /sys/kernel/debug/lustre */
518 struct dentry *debugfs_lustre_root;
519 EXPORT_SYMBOL_GPL(debugfs_lustre_root);
520
521 #ifdef CONFIG_PROC_FS
522 /* Root for /proc/fs/lustre */
523 struct proc_dir_entry *proc_lustre_root = NULL;
524 EXPORT_SYMBOL(proc_lustre_root);
525 #else
526 #define lprocfs_base NULL
527 #endif /* CONFIG_PROC_FS */
528
529 LUSTRE_RO_ATTR(version);
530 LUSTRE_RO_ATTR(pinger);
531 LUSTRE_RO_ATTR(health_check);
532 LUSTRE_RW_ATTR(jobid_var);
533 LUSTRE_RW_ATTR(jobid_name);
534
535 static struct attribute *lustre_attrs[] = {
536         &lustre_attr_version.attr,
537         &lustre_attr_pinger.attr,
538         &lustre_attr_health_check.attr,
539         &lustre_attr_jobid_name.attr,
540         &lustre_attr_jobid_var.attr,
541         &lustre_sattr_timeout.u.attr,
542         &lustre_attr_max_dirty_mb.attr,
543         &lustre_sattr_debug_peer_on_timeout.u.attr,
544         &lustre_sattr_dump_on_timeout.u.attr,
545         &lustre_sattr_dump_on_eviction.u.attr,
546         &lustre_sattr_at_min.u.attr,
547         &lustre_sattr_at_max.u.attr,
548         &lustre_sattr_at_extra.u.attr,
549         &lustre_sattr_at_early_margin.u.attr,
550         &lustre_sattr_at_history.u.attr,
551         &lustre_attr_memused_max.attr,
552         &lustre_attr_memused.attr,
553 #ifdef HAVE_SERVER_SUPPORT
554         &lustre_sattr_ldlm_timeout.u.attr,
555         &lustre_sattr_bulk_timeout.u.attr,
556 #endif
557         NULL,
558 };
559
560 static void *obd_device_list_seq_start(struct seq_file *p, loff_t *pos)
561 {
562         if (*pos >= class_devno_max())
563                 return NULL;
564
565         return pos;
566 }
567
568 static void obd_device_list_seq_stop(struct seq_file *p, void *v)
569 {
570 }
571
572 static void *obd_device_list_seq_next(struct seq_file *p, void *v, loff_t *pos)
573 {
574         ++*pos;
575         if (*pos >= class_devno_max())
576                 return NULL;
577
578         return pos;
579 }
580
581 static int obd_device_list_seq_show(struct seq_file *p, void *v)
582 {
583         loff_t index = *(loff_t *)v;
584         struct obd_device *obd = class_num2obd((int)index);
585         char *status;
586
587         if (obd == NULL)
588                 return 0;
589
590         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
591         if (obd->obd_stopping)
592                 status = "ST";
593         else if (obd->obd_inactive)
594                 status = "IN";
595         else if (obd->obd_set_up)
596                 status = "UP";
597         else if (obd->obd_attached)
598                 status = "AT";
599         else
600                 status = "--";
601
602         seq_printf(p, "%3d %s %s %s %s %d\n",
603                    (int)index, status, obd->obd_type->typ_name,
604                    obd->obd_name, obd->obd_uuid.uuid,
605                    atomic_read(&obd->obd_refcount));
606         return 0;
607 }
608
609 static const struct seq_operations obd_device_list_sops = {
610         .start = obd_device_list_seq_start,
611         .stop = obd_device_list_seq_stop,
612         .next = obd_device_list_seq_next,
613         .show = obd_device_list_seq_show,
614 };
615
616 static int obd_device_list_open(struct inode *inode, struct file *file)
617 {
618         struct seq_file *seq;
619         int rc = seq_open(file, &obd_device_list_sops);
620
621         if (rc)
622                 return rc;
623
624         seq = file->private_data;
625         seq->private = inode->i_private;
626         return 0;
627 }
628
629 static const struct file_operations obd_device_list_fops = {
630         .owner   = THIS_MODULE,
631         .open    = obd_device_list_open,
632         .read    = seq_read,
633         .llseek  = seq_lseek,
634         .release = seq_release,
635 };
636
637 struct kset *lustre_kset;
638 EXPORT_SYMBOL_GPL(lustre_kset);
639
640 static struct attribute_group lustre_attr_group = {
641         .attrs = lustre_attrs,
642 };
643
644 ssize_t class_set_global(const char *param)
645 {
646         const char *value = strchr(param, '=') + 1;
647         size_t off = value - param - 1;
648         ssize_t count = -ENOENT;
649         int i;
650
651         for (i = 0; lustre_attrs[i]; i++) {
652                 if (!strncmp(lustre_attrs[i]->name, param, off)) {
653                         count = lustre_attr_store(&lustre_kset->kobj,
654                                                   lustre_attrs[i], value,
655                                                   strlen(value));
656                         break;
657                 }
658         }
659         return count;
660 }
661
662 int class_procfs_init(void)
663 {
664         struct proc_dir_entry *entry;
665         struct dentry *file;
666         int rc = -ENOMEM;
667         ENTRY;
668
669         lustre_kset = kset_create_and_add("lustre", NULL, fs_kobj);
670         if (!lustre_kset)
671                 goto out;
672
673         /* Create the files associated with this kobject */
674         rc = sysfs_create_group(&lustre_kset->kobj, &lustre_attr_group);
675         if (rc) {
676                 kset_unregister(lustre_kset);
677                 goto out;
678         }
679
680         rc = jobid_cache_init();
681         if (rc) {
682                 kset_unregister(lustre_kset);
683                 goto out;
684         }
685
686         debugfs_lustre_root = debugfs_create_dir("lustre", NULL);
687         if (IS_ERR_OR_NULL(debugfs_lustre_root)) {
688                 rc = debugfs_lustre_root ? PTR_ERR(debugfs_lustre_root)
689                                          : -ENOMEM;
690                 debugfs_lustre_root = NULL;
691                 kset_unregister(lustre_kset);
692                 goto out;
693         }
694
695         file = debugfs_create_file("devices", 0444, debugfs_lustre_root, NULL,
696                                    &obd_device_list_fops);
697         if (IS_ERR_OR_NULL(file)) {
698                 rc = file ? PTR_ERR(file) : -ENOMEM;
699                 debugfs_remove(debugfs_lustre_root);
700                 kset_unregister(lustre_kset);
701                 goto out;
702         }
703
704         entry = lprocfs_register("fs/lustre", NULL, NULL, NULL);
705         if (IS_ERR(entry)) {
706                 rc = PTR_ERR(entry);
707                 CERROR("cannot create '/proc/fs/lustre': rc = %d\n", rc);
708                 debugfs_remove_recursive(debugfs_lustre_root);
709                 kset_unregister(lustre_kset);
710                 goto out;
711         }
712
713         proc_lustre_root = entry;
714 out:
715         RETURN(rc);
716 }
717
718 int class_procfs_clean(void)
719 {
720         ENTRY;
721
722         debugfs_remove_recursive(debugfs_lustre_root);
723
724         debugfs_lustre_root = NULL;
725         jobid_cache_fini();
726
727         if (proc_lustre_root)
728                 lprocfs_remove(&proc_lustre_root);
729
730         sysfs_remove_group(&lustre_kset->kobj, &lustre_attr_group);
731
732         kset_unregister(lustre_kset);
733
734         RETURN(0);
735 }