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