Whamcloud - gitweb
d7e96f5564d8376b8b988ce380facc0aa763a478
[fs/lustre-release.git] / lustre / ofd / ofd_access_log.c
1 #include <linux/cdev.h>
2 #include <linux/circ_buf.h>
3 #include <linux/device.h>
4 #include <linux/fs.h>
5 #include <linux/kernel.h>
6 #include <linux/miscdevice.h>
7 #include <linux/module.h>
8 #include <linux/poll.h>
9 #include <linux/slab.h>
10 #include <linux/types.h>
11 #include <linux/uaccess.h>
12 #include <uapi/linux/lustre/lustre_idl.h>
13 #include <uapi/linux/lustre/lustre_access_log.h>
14 #include "ofd_internal.h"
15
16 /* OFD access logs: OST (OFD) RPC handlers log accesses by FID and
17  * PFID which are read from userspace through character device files
18  * (/dev/lustre-access-log/scratch-OST0000). Accesses are described by
19  * struct ofd_access_entry_v1. The char device implements read()
20  * (blocking and nonblocking) and poll(), along with an ioctl that
21  * returns diagnostic information on an oal device.
22  *
23  * A control device (/dev/lustre-access-log/control) supports an ioctl()
24  * plus poll() method to for oal discovery. See uses of
25  * oal_control_event_count and oal_control_wait_queue for details.
26  *
27  * oal log size and entry size are restricted to powers of 2 to
28  * support circ_buf methods. See Documentation/core-api/circular-buffers.rst
29  * in the linux tree for more information.
30  *
31  * The associated struct device (*oal_device) owns the oal. The
32  * release() method of oal_device frees the oal and releases its
33  * minor. This may seem slightly more complicated than necessary but
34  * it allows the OST to be unmounted while the oal still has open file
35  * descriptors.
36  */
37
38 enum {
39         OAL_DEV_COUNT = 1 << MINORBITS,
40 };
41
42 struct ofd_access_log {
43         char oal_name[128]; /* lustre-OST0000 */
44         struct device oal_device;
45         struct cdev oal_cdev;
46         struct rw_semaphore oal_buf_list_sem;
47         struct list_head oal_circ_buf_list;
48         unsigned int oal_is_closed;
49         unsigned int oal_log_size;
50         unsigned int oal_entry_size;
51 };
52
53 struct oal_circ_buf {
54         struct list_head ocb_list;
55         spinlock_t ocb_write_lock;
56         spinlock_t ocb_read_lock;
57         struct ofd_access_log *ocb_access_log;
58         __u32 ocb_filter;
59         wait_queue_head_t ocb_read_wait_queue;
60         unsigned int ocb_drop_count;
61         struct circ_buf ocb_circ;
62 };
63
64 static atomic_t oal_control_event_count = ATOMIC_INIT(0);
65 static DECLARE_WAIT_QUEUE_HEAD(oal_control_wait_queue);
66
67 static struct class *oal_log_class;
68 static unsigned int oal_log_major;
69 static DEFINE_IDR(oal_log_minor_idr); /* TODO Use ida instead. */
70 static DEFINE_SPINLOCK(oal_log_minor_lock);
71
72 bool ofd_access_log_size_is_valid(unsigned int size)
73 {
74         const unsigned int size_min = 2 * sizeof(struct ofd_access_entry_v1);
75         const unsigned int size_max = 1U << 30;
76
77         if (size == 0)
78                 return true;
79
80         return is_power_of_2(size) && size_min <= size && size <= size_max;
81 }
82
83 static void oal_control_event_inc(void)
84 {
85         atomic_inc(&oal_control_event_count);
86         wake_up(&oal_control_wait_queue);
87 }
88
89 static int oal_log_minor_alloc(int *pminor)
90 {
91         void *OAL_LOG_MINOR_ALLOCED = (void *)-1;
92         int minor;
93
94         idr_preload(GFP_KERNEL);
95         spin_lock(&oal_log_minor_lock);
96         minor = idr_alloc(&oal_log_minor_idr, OAL_LOG_MINOR_ALLOCED, 0,
97                         OAL_DEV_COUNT, GFP_NOWAIT);
98         spin_unlock(&oal_log_minor_lock);
99         idr_preload_end();
100
101         if (minor < 0)
102                 return minor;
103
104         *pminor = minor;
105
106         return 0;
107 }
108
109 static void oal_log_minor_free(int minor)
110 {
111         spin_lock(&oal_log_minor_lock);
112         idr_remove(&oal_log_minor_idr, minor);
113         spin_unlock(&oal_log_minor_lock);
114 }
115
116 static bool oal_is_empty(struct oal_circ_buf *ocb)
117 {
118         struct ofd_access_log *oal = ocb->ocb_access_log;
119
120         return CIRC_CNT(ocb->ocb_circ.head,
121                         ocb->ocb_circ.tail,
122                         oal->oal_log_size) < oal->oal_entry_size;
123 }
124
125 static ssize_t oal_write_entry(struct oal_circ_buf *ocb,
126                         const void *entry, size_t entry_size)
127 {
128         struct ofd_access_log *oal = ocb->ocb_access_log;
129         struct circ_buf *circ = &ocb->ocb_circ;
130         unsigned int head;
131         unsigned int tail;
132         ssize_t rc;
133
134         if (entry_size != oal->oal_entry_size)
135                 return -EINVAL;
136
137         spin_lock(&ocb->ocb_write_lock);
138         head = circ->head;
139         tail = READ_ONCE(circ->tail);
140
141         /* CIRC_SPACE() return space available, 0..oal_log_size -
142          * 1. It always leaves one free char, since a completely full
143          * buffer would have head == tail, which is the same as empty. */
144         if (CIRC_SPACE(head, tail, oal->oal_log_size) < oal->oal_entry_size) {
145                 ocb->ocb_drop_count++;
146                 rc = -EAGAIN;
147                 goto out_write_lock;
148         }
149
150         memcpy(&circ->buf[head], entry, entry_size);
151         rc = entry_size;
152
153         /* Ensure the entry is stored before we update the head. */
154         smp_store_release(&circ->head,
155                         (head + oal->oal_entry_size) & (oal->oal_log_size - 1));
156
157         wake_up(&ocb->ocb_read_wait_queue);
158 out_write_lock:
159         spin_unlock(&ocb->ocb_write_lock);
160
161         return rc;
162 }
163
164 /* Read one entry from the log and return its size. Non-blocking.
165  * When the log is empty we return -EAGAIN if the OST is still mounted
166  * and 0 otherwise.
167  */
168 static ssize_t oal_read_entry(struct oal_circ_buf *ocb,
169                         void *entry_buf, size_t entry_buf_size)
170 {
171         struct ofd_access_log *oal = ocb->ocb_access_log;
172         struct circ_buf *circ = &ocb->ocb_circ;
173         unsigned int head;
174         unsigned int tail;
175         ssize_t rc;
176
177         /* XXX This method may silently truncate entries when
178          * entry_buf_size is less than oal_entry_size. But that's OK
179          * because you know what you are doing. */
180         spin_lock(&ocb->ocb_read_lock);
181
182         /* Memory barrier usage follows circular-buffers.txt. */
183         head = smp_load_acquire(&circ->head);
184         tail = circ->tail;
185
186         if (!CIRC_CNT(head, tail, oal->oal_log_size)) {
187                 rc = oal->oal_is_closed ? 0 : -EAGAIN;
188                 goto out_read_lock;
189         }
190
191         BUG_ON(CIRC_CNT(head, tail, oal->oal_log_size) < oal->oal_entry_size);
192
193         /* Read index before reading contents at that index. */
194         smp_read_barrier_depends();
195
196         /* Extract one entry from the buffer. */
197         rc = min_t(size_t, oal->oal_entry_size, entry_buf_size);
198         memcpy(entry_buf, &circ->buf[tail], rc);
199
200         /* Memory barrier usage follows circular-buffers.txt. */
201         smp_store_release(&circ->tail,
202                         (tail + oal->oal_entry_size) & (oal->oal_log_size - 1));
203
204 out_read_lock:
205         spin_unlock(&ocb->ocb_read_lock);
206
207         return rc;
208 }
209
210 static int oal_file_open(struct inode *inode, struct file *filp)
211 {
212         struct ofd_access_log *oal;
213         struct oal_circ_buf *ocb;
214
215         oal = container_of(inode->i_cdev, struct ofd_access_log, oal_cdev);
216
217         ocb = kzalloc(sizeof(*ocb), GFP_KERNEL);
218         if (!ocb)
219                 return -ENOMEM;
220         ocb->ocb_circ.buf = vmalloc(oal->oal_log_size);
221         if (!ocb->ocb_circ.buf) {
222                 kfree(ocb);
223                 return -ENOMEM;
224         }
225
226         spin_lock_init(&ocb->ocb_write_lock);
227         spin_lock_init(&ocb->ocb_read_lock);
228         ocb->ocb_access_log = oal;
229         init_waitqueue_head(&ocb->ocb_read_wait_queue);
230
231         down_write(&oal->oal_buf_list_sem);
232         list_add(&ocb->ocb_list, &oal->oal_circ_buf_list);
233         up_write(&oal->oal_buf_list_sem);
234
235         filp->private_data = ocb;
236
237         return nonseekable_open(inode, filp);
238 }
239
240 /* User buffer size must be a multiple of ofd access entry size. */
241 static ssize_t oal_file_read(struct file *filp, char __user *buf, size_t count,
242                         loff_t *ppos)
243 {
244         struct oal_circ_buf *ocb = filp->private_data;
245         struct ofd_access_log *oal = ocb->ocb_access_log;
246         void *entry;
247         size_t size = 0;
248         int rc = 0;
249
250         if (!count)
251                 return 0;
252
253         if (count & (oal->oal_entry_size - 1))
254                 return -EINVAL;
255
256         entry = kzalloc(oal->oal_entry_size, GFP_KERNEL);
257         if (!entry)
258                 return -ENOMEM;
259
260         while (size < count) {
261                 rc = oal_read_entry(ocb, entry, oal->oal_entry_size);
262                 if (rc == -EAGAIN) {
263                         if (filp->f_flags & O_NONBLOCK)
264                                 break;
265
266                         rc = wait_event_interruptible(ocb->ocb_read_wait_queue,
267                                 !oal_is_empty(ocb) || oal->oal_is_closed);
268                         if (rc)
269                                 break;
270                 } else if (rc <= 0) {
271                         break; /* cloed or error */
272                 } else {
273                         if (copy_to_user(buf, entry, oal->oal_entry_size)) {
274                                 rc = -EFAULT;
275                                 break;
276                         }
277
278                         buf += oal->oal_entry_size;
279                         size += oal->oal_entry_size;
280                 }
281         }
282
283         kfree(entry);
284
285         return size ? size : rc;
286 }
287
288 /* Included for test purposes. User buffer size must be a multiple of
289  * ofd access entry size. */
290 static ssize_t oal_file_write(struct file *filp, const char __user *buf,
291                         size_t count, loff_t *ppos)
292 {
293         struct oal_circ_buf *ocb = filp->private_data;
294         struct ofd_access_log *oal = ocb->ocb_access_log;
295         void *entry;
296         size_t size = 0;
297         ssize_t rc = 0;
298
299         if (!count)
300                 return 0;
301
302         if (count & (oal->oal_entry_size - 1))
303                 return -EINVAL;
304
305         entry = kzalloc(oal->oal_entry_size, GFP_KERNEL);
306         if (!entry)
307                 return -ENOMEM;
308
309         while (size < count) {
310                 if (copy_from_user(entry, buf, oal->oal_entry_size)) {
311                         rc = -EFAULT;
312                         break;
313                 }
314
315                 rc = oal_write_entry(ocb, entry, oal->oal_entry_size);
316                 if (rc <= 0)
317                         break;
318
319                 buf += oal->oal_entry_size;
320                 size += oal->oal_entry_size;
321         }
322
323         kfree(entry);
324
325         return size > 0 ? size : rc;
326 }
327
328 unsigned int oal_file_poll(struct file *filp, struct poll_table_struct *wait)
329 {
330         struct oal_circ_buf *ocb = filp->private_data;
331         struct ofd_access_log *oal = ocb->ocb_access_log;
332         unsigned int mask = 0;
333
334         poll_wait(filp, &ocb->ocb_read_wait_queue, wait);
335
336         spin_lock(&ocb->ocb_read_lock);
337
338         if (!oal_is_empty(ocb) || oal->oal_is_closed)
339                 mask |= POLLIN;
340
341         spin_unlock(&ocb->ocb_read_lock);
342
343         return mask;
344 }
345
346 static long oal_ioctl_info(struct oal_circ_buf *ocb, unsigned long arg)
347 {
348         struct ofd_access_log *oal = ocb->ocb_access_log;
349
350         struct lustre_access_log_info_v1 __user *lali;
351         u32 entry_count = CIRC_CNT(ocb->ocb_circ.head,
352                                 ocb->ocb_circ.tail,
353                                 oal->oal_log_size) / oal->oal_entry_size;
354         u32 entry_space = CIRC_SPACE(ocb->ocb_circ.head,
355                                 ocb->ocb_circ.tail,
356                                 oal->oal_log_size) / oal->oal_entry_size;
357
358         lali = (struct lustre_access_log_info_v1 __user *)arg;
359         BUILD_BUG_ON(sizeof(lali->lali_name) != sizeof(oal->oal_name));
360
361         if (put_user(LUSTRE_ACCESS_LOG_VERSION_1, &lali->lali_version))
362                 return -EFAULT;
363
364         if (put_user(LUSTRE_ACCESS_LOG_TYPE_OFD, &lali->lali_type))
365                 return -EFAULT;
366
367         if (copy_to_user(lali->lali_name, oal->oal_name, sizeof(oal->oal_name)))
368                 return -EFAULT;
369
370         if (put_user(oal->oal_log_size, &lali->lali_log_size))
371                 return -EFAULT;
372
373         if (put_user(oal->oal_entry_size, &lali->lali_entry_size))
374                 return -EFAULT;
375
376         if (put_user(ocb->ocb_circ.head, &lali->_lali_head))
377                 return -EFAULT;
378
379         if (put_user(ocb->ocb_circ.tail, &lali->_lali_tail))
380                 return -EFAULT;
381
382         if (put_user(entry_space, &lali->_lali_entry_space))
383                 return -EFAULT;
384
385         if (put_user(entry_count, &lali->_lali_entry_count))
386                 return -EFAULT;
387
388         if (put_user(ocb->ocb_drop_count, &lali->_lali_drop_count))
389                 return -EFAULT;
390
391         if (put_user(oal->oal_is_closed, &lali->_lali_is_closed))
392                 return -EFAULT;
393
394         return 0;
395 }
396
397 static long oal_file_ioctl(struct file *filp, unsigned int cmd,
398                         unsigned long arg)
399 {
400         struct oal_circ_buf *ocb = filp->private_data;
401
402         switch (cmd) {
403         case LUSTRE_ACCESS_LOG_IOCTL_VERSION:
404                 return LUSTRE_ACCESS_LOG_VERSION_1;
405         case LUSTRE_ACCESS_LOG_IOCTL_INFO:
406                 return oal_ioctl_info(ocb, arg);
407         case LUSTRE_ACCESS_LOG_IOCTL_FILTER:
408                 ocb->ocb_filter = arg;
409                 return 0;
410         default:
411                 return -ENOTTY;
412         }
413 }
414
415 static int oal_file_release(struct inode *inode, struct file *filp)
416 {
417         struct oal_circ_buf *ocb = filp->private_data;
418         struct ofd_access_log *oal = ocb->ocb_access_log;
419
420         down_write(&oal->oal_buf_list_sem);
421         list_del(&ocb->ocb_list);
422         up_write(&oal->oal_buf_list_sem);
423
424         vfree(ocb->ocb_circ.buf);
425         kfree(ocb);
426
427         return 0;
428 }
429
430 static const struct file_operations oal_fops = {
431         .owner = THIS_MODULE,
432         .open = &oal_file_open,
433         .release = &oal_file_release,
434         .unlocked_ioctl = &oal_file_ioctl,
435         .read = &oal_file_read,
436         .write = &oal_file_write,
437         .poll = &oal_file_poll,
438         .llseek = &no_llseek,
439 };
440
441 static void oal_device_release(struct device *dev)
442 {
443         struct ofd_access_log *oal = dev_get_drvdata(dev);
444
445         oal_log_minor_free(MINOR(oal->oal_device.devt));
446         BUG_ON(!list_empty(&oal->oal_circ_buf_list));
447         kfree(oal);
448 }
449
450 struct ofd_access_log *ofd_access_log_create(const char *ofd_name, size_t size)
451 {
452         const size_t entry_size = sizeof(struct ofd_access_entry_v1);
453         struct ofd_access_log *oal;
454         int minor;
455         int rc;
456
457         BUILD_BUG_ON(sizeof(oal->oal_name) != MAX_OBD_NAME);
458         BUILD_BUG_ON(!is_power_of_2(entry_size));
459
460         if (!size)
461                 return NULL;
462
463         if (!is_power_of_2(size) || (size & (entry_size - 1)) ||
464             (unsigned int)size != size)
465                 return ERR_PTR(-EINVAL);
466
467         oal = kzalloc(sizeof(*oal), GFP_KERNEL);
468         if (!oal)
469                 return ERR_PTR(-ENOMEM);
470
471         strlcpy(oal->oal_name, ofd_name, sizeof(oal->oal_name));
472         oal->oal_log_size = size;
473         oal->oal_entry_size = entry_size;
474         INIT_LIST_HEAD(&oal->oal_circ_buf_list);
475         init_rwsem(&oal->oal_buf_list_sem);
476
477         rc = oal_log_minor_alloc(&minor);
478         if (rc < 0)
479                 goto out_free;
480
481         device_initialize(&oal->oal_device);
482         oal->oal_device.devt = MKDEV(oal_log_major, minor);
483         oal->oal_device.class = oal_log_class;
484         oal->oal_device.release = &oal_device_release;
485         dev_set_drvdata(&oal->oal_device, oal);
486         rc = dev_set_name(&oal->oal_device,
487                         "%s!%s", LUSTRE_ACCESS_LOG_DIR_NAME, oal->oal_name);
488         if (rc < 0)
489                 goto out_minor;
490
491         cdev_init(&oal->oal_cdev, &oal_fops);
492         oal->oal_cdev.owner = THIS_MODULE;
493         rc = cdev_device_add(&oal->oal_cdev, &oal->oal_device);
494         if (rc < 0)
495                 goto out_device_name;
496
497         oal_control_event_inc();
498
499         return oal;
500
501 out_device_name:
502         kfree_const(oal->oal_device.kobj.name);
503 out_minor:
504         oal_log_minor_free(minor);
505 out_free:
506         kfree(oal);
507
508         return ERR_PTR(rc);
509 }
510
511 void ofd_access(const struct lu_env *env,
512                 struct ofd_device *m,
513                 const struct lu_fid *parent_fid,
514                 __u64 begin, __u64 end,
515                 unsigned int size,
516                 unsigned int segment_count,
517                 int rw)
518 {
519         unsigned int flags = (rw == READ) ? OFD_ACCESS_READ : OFD_ACCESS_WRITE;
520         struct ofd_access_log *oal = m->ofd_access_log;
521
522         if (oal && (flags & m->ofd_access_log_mask)) {
523                 struct ofd_access_entry_v1 oae = {
524                         .oae_parent_fid = *parent_fid,
525                         .oae_begin = begin,
526                         .oae_end = end,
527                         .oae_time = ktime_get_real_seconds(),
528                         .oae_size = size,
529                         .oae_segment_count = segment_count,
530                         .oae_flags = flags,
531                 };
532                 struct oal_circ_buf *ocb;
533                 struct lu_seq_range range;
534                 int rc;
535
536                 /* learn target MDT from FID's sequence */
537                 range.lsr_flags = LU_SEQ_RANGE_ANY;
538                 rc = fld_server_lookup(env, m->ofd_seq_site.ss_server_fld,
539                                        fid_seq(parent_fid), &range);
540                 if (unlikely(rc))
541                         CERROR("%s: can't resolve "DFID": rc=%d\n",
542                                ofd_name(m), PFID(parent_fid), rc);
543
544                 down_read(&oal->oal_buf_list_sem);
545                 list_for_each_entry(ocb, &oal->oal_circ_buf_list, ocb_list) {
546                         /* filter by MDT index if requested */
547                         if (ocb->ocb_filter == 0xffffffff ||
548                             range.lsr_index == ocb->ocb_filter)
549                                 oal_write_entry(ocb, &oae, sizeof(oae));
550                 }
551                 up_read(&oal->oal_buf_list_sem);
552         }
553 }
554
555 /* Called on OST umount to:
556  * - Close the write end of the oal. The wakes any tasks sleeping in
557  *   read or poll and makes all reads return zero once the log
558  *   becomes empty.
559  * - Delete the associated stuct device and cdev, preventing new
560  *   opens. Existing opens retain a reference on the oal through
561  *   their reference on oal_device.
562  * The oal will be freed when the last open file handle is closed. */
563 void ofd_access_log_delete(struct ofd_access_log *oal)
564 {
565         struct oal_circ_buf *ocb;
566
567         if (!oal)
568                 return;
569
570         oal->oal_is_closed = 1;
571         down_read(&oal->oal_buf_list_sem);
572         list_for_each_entry(ocb, &oal->oal_circ_buf_list, ocb_list) {
573                 wake_up_all(&ocb->ocb_read_wait_queue);
574         }
575         up_read(&oal->oal_buf_list_sem);
576         cdev_device_del(&oal->oal_cdev, &oal->oal_device);
577 }
578
579 /* private_data for control device file. */
580 struct oal_control_file {
581         int ccf_event_count;
582 };
583
584 /* Control file usage:
585  * Open /dev/lustre-access-log/control.
586  * while (1)
587  *   Poll for readable on control FD.
588  *   Call ioctl(FD, LUSTRE_ACCESS_LOG_IOCTL_PRESCAN) to fetch event count.
589  *   Scan /dev/ or /sys/class/... for new devices.
590  */
591 static int oal_control_file_open(struct inode *inode, struct file *filp)
592 {
593         struct oal_control_file *ccf;
594         int rc;
595
596         rc = nonseekable_open(inode, filp);
597         if (rc)
598                 return rc;
599
600         /* ccf->ccf_event_count = 0 on open */
601         ccf = kzalloc(sizeof(*ccf), GFP_KERNEL);
602         if (!ccf)
603                 return -ENOMEM;
604
605         filp->private_data = ccf;
606
607         return 0;
608 }
609
610 static int oal_control_file_release(struct inode *inode, struct file *filp)
611 {
612         kfree(filp->private_data);
613         return 0;
614 }
615
616 static unsigned int oal_control_file_poll(struct file *filp, poll_table *wait)
617 {
618         struct oal_control_file *ccf = filp->private_data;
619         unsigned int mask = 0;
620
621         poll_wait(filp, &oal_control_wait_queue, wait);
622
623         if (atomic_read(&oal_control_event_count) != ccf->ccf_event_count)
624                 mask |= POLLIN;
625
626         return mask;
627 }
628
629 static long oal_control_file_ioctl(struct file *filp, unsigned int cmd,
630                                 unsigned long arg)
631 {
632         struct oal_control_file *ccf = filp->private_data;
633
634         switch (cmd) {
635         case LUSTRE_ACCESS_LOG_IOCTL_VERSION:
636                 return LUSTRE_ACCESS_LOG_VERSION_1;
637         case LUSTRE_ACCESS_LOG_IOCTL_MAJOR:
638                 return oal_log_major;
639         case LUSTRE_ACCESS_LOG_IOCTL_PRESCAN:
640                 ccf->ccf_event_count = atomic_read(&oal_control_event_count);
641                 return 0;
642         default:
643                 return -ENOTTY;
644         }
645 }
646
647 static const struct file_operations oal_control_fops = {
648         .owner = THIS_MODULE,
649         .open = &oal_control_file_open,
650         .release = &oal_control_file_release,
651         .poll = &oal_control_file_poll,
652         .unlocked_ioctl = &oal_control_file_ioctl,
653         .llseek = &noop_llseek,
654 };
655
656 static struct miscdevice oal_control_misc = {
657         .minor = MISC_DYNAMIC_MINOR,
658         .name = LUSTRE_ACCESS_LOG_DIR_NAME"!control",
659         .fops = &oal_control_fops,
660 };
661
662 int ofd_access_log_module_init(void)
663 {
664         dev_t dev;
665         int rc;
666
667         BUILD_BUG_ON(!is_power_of_2(sizeof(struct ofd_access_entry_v1)));
668
669         rc = misc_register(&oal_control_misc);
670         if (rc)
671                 return rc;
672
673         rc = alloc_chrdev_region(&dev, 0, OAL_DEV_COUNT,
674                                 LUSTRE_ACCESS_LOG_DIR_NAME);
675         if (rc)
676                 goto out_oal_control_misc;
677
678         oal_log_major = MAJOR(dev);
679
680         oal_log_class = class_create(THIS_MODULE, LUSTRE_ACCESS_LOG_DIR_NAME);
681         if (IS_ERR(oal_log_class)) {
682                 rc = PTR_ERR(oal_log_class);
683                 goto out_dev;
684         }
685
686         return 0;
687 out_dev:
688         unregister_chrdev_region(dev, OAL_DEV_COUNT);
689 out_oal_control_misc:
690         misc_deregister(&oal_control_misc);
691
692         return rc;
693 }
694
695 void ofd_access_log_module_exit(void)
696 {
697         class_destroy(oal_log_class);
698         unregister_chrdev_region(MKDEV(oal_log_major, 0), OAL_DEV_COUNT);
699         idr_destroy(&oal_log_minor_idr);
700         misc_deregister(&oal_control_misc);
701 }