Whamcloud - gitweb
LU-10166 mdc: invalid free in changelog reader
[fs/lustre-release.git] / lustre / mdc / mdc_changelog.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) 2017, Commissariat a l'Energie Atomique et aux Energies
24  *                     Alternatives.
25  *
26  * Author: Henri Doreau <henri.doreau@cea.fr>
27  */
28
29 #define DEBUG_SUBSYSTEM S_MDC
30
31 #include <linux/init.h>
32 #include <linux/kthread.h>
33 #include <linux/poll.h>
34 #include <linux/miscdevice.h>
35
36 #include <lustre_log.h>
37
38 #include "mdc_internal.h"
39
40
41 /*
42  * -- Changelog delivery through character device --
43  */
44
45 /**
46  * Mutex to protect chlg_registered_devices below
47  */
48 static DEFINE_MUTEX(chlg_registered_dev_lock);
49
50 /**
51  * Global linked list of all registered devices (one per MDT).
52  */
53 static LIST_HEAD(chlg_registered_devices);
54
55
56 struct chlg_registered_dev {
57         /* Device name of the form "changelog-{MDTNAME}" */
58         char                    ced_name[32];
59         /* Misc device descriptor */
60         struct miscdevice       ced_misc;
61         /* OBDs referencing this device (multiple mount point) */
62         struct list_head        ced_obds;
63         /* Reference counter for proper deregistration */
64         struct kref             ced_refs;
65         /* Link within the global chlg_registered_devices */
66         struct list_head        ced_link;
67 };
68
69 struct chlg_reader_state {
70         /* Shortcut to the corresponding OBD device */
71         struct obd_device       *crs_obd;
72         /* Producer thread (if any) */
73         struct task_struct      *crs_prod_task;
74         /* An error occurred that prevents from reading further */
75         bool                     crs_err;
76         /* EOF, no more records available */
77         bool                     crs_eof;
78         /* Desired start position */
79         __u64                    crs_start_offset;
80         /* Wait queue for the catalog processing thread */
81         wait_queue_head_t        crs_waitq_prod;
82         /* Wait queue for the record copy threads */
83         wait_queue_head_t        crs_waitq_cons;
84         /* Mutex protecting crs_rec_count and crs_rec_queue */
85         struct mutex             crs_lock;
86         /* Number of item in the list */
87         __u64                    crs_rec_count;
88         /* List of prefetched enqueued_record::enq_linkage_items */
89         struct list_head         crs_rec_queue;
90 };
91
92 struct chlg_rec_entry {
93         /* Link within the chlg_reader_state::crs_rec_queue list */
94         struct list_head        enq_linkage;
95         /* Data (enq_record) field length */
96         __u64                   enq_length;
97         /* Copy of a changelog record (see struct llog_changelog_rec) */
98         struct changelog_rec    enq_record[];
99 };
100
101 enum {
102         /* Number of records to prefetch locally. */
103         CDEV_CHLG_MAX_PREFETCH = 1024,
104 };
105
106 /**
107  * ChangeLog catalog processing callback invoked on each record.
108  * If the current record is eligible to userland delivery, push
109  * it into the crs_rec_queue where the consumer code will fetch it.
110  *
111  * @param[in]     env  (unused)
112  * @param[in]     llh  Client-side handle used to identify the llog
113  * @param[in]     hdr  Header of the current llog record
114  * @param[in,out] data chlg_reader_state passed from caller
115  *
116  * @return 0 or LLOG_PROC_* control code on success, negated error on failure.
117  */
118 static int chlg_read_cat_process_cb(const struct lu_env *env,
119                                     struct llog_handle *llh,
120                                     struct llog_rec_hdr *hdr, void *data)
121 {
122         struct llog_changelog_rec *rec;
123         struct chlg_reader_state *crs = data;
124         struct chlg_rec_entry *enq;
125         struct l_wait_info lwi = { 0 };
126         size_t len;
127         int rc;
128         ENTRY;
129
130         LASSERT(crs != NULL);
131         LASSERT(hdr != NULL);
132
133         rec = container_of(hdr, struct llog_changelog_rec, cr_hdr);
134
135         if (rec->cr_hdr.lrh_type != CHANGELOG_REC) {
136                 rc = -EINVAL;
137                 CERROR("%s: not a changelog rec %x/%d in llog "DFID" rc = %d\n",
138                        crs->crs_obd->obd_name, rec->cr_hdr.lrh_type,
139                        rec->cr.cr_type,
140                        PFID(lu_object_fid(&llh->lgh_obj->do_lu)), rc);
141                 RETURN(rc);
142         }
143
144         /* Skip undesired records */
145         if (rec->cr.cr_index < crs->crs_start_offset)
146                 RETURN(0);
147
148         CDEBUG(D_HSM, "%llu %02d%-5s %llu 0x%x t="DFID" p="DFID" %.*s\n",
149                rec->cr.cr_index, rec->cr.cr_type,
150                changelog_type2str(rec->cr.cr_type), rec->cr.cr_time,
151                rec->cr.cr_flags & CLF_FLAGMASK,
152                PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid),
153                rec->cr.cr_namelen, changelog_rec_name(&rec->cr));
154
155         l_wait_event(crs->crs_waitq_prod,
156                      (crs->crs_rec_count < CDEV_CHLG_MAX_PREFETCH ||
157                       kthread_should_stop()), &lwi);
158
159         if (kthread_should_stop())
160                 RETURN(LLOG_PROC_BREAK);
161
162         len = changelog_rec_size(&rec->cr) + rec->cr.cr_namelen;
163         OBD_ALLOC(enq, sizeof(*enq) + len);
164         if (enq == NULL)
165                 RETURN(-ENOMEM);
166
167         INIT_LIST_HEAD(&enq->enq_linkage);
168         enq->enq_length = len;
169         memcpy(enq->enq_record, &rec->cr, len);
170
171         mutex_lock(&crs->crs_lock);
172         list_add_tail(&enq->enq_linkage, &crs->crs_rec_queue);
173         crs->crs_rec_count++;
174         mutex_unlock(&crs->crs_lock);
175
176         wake_up_all(&crs->crs_waitq_cons);
177
178         RETURN(0);
179 }
180
181 /**
182  * Remove record from the list it is attached to and free it.
183  */
184 static void enq_record_delete(struct chlg_rec_entry *rec)
185 {
186         list_del(&rec->enq_linkage);
187         OBD_FREE(rec, sizeof(*rec) + rec->enq_length);
188 }
189
190 /**
191  * Record prefetch thread entry point. Opens the changelog catalog and starts
192  * reading records.
193  *
194  * @param[in,out]  args  chlg_reader_state passed from caller.
195  * @return 0 on success, negated error code on failure.
196  */
197 static int chlg_load(void *args)
198 {
199         struct chlg_reader_state *crs = args;
200         struct obd_device *obd = crs->crs_obd;
201         struct llog_ctxt *ctx = NULL;
202         struct llog_handle *llh = NULL;
203         struct l_wait_info lwi = { 0 };
204         int rc;
205         ENTRY;
206
207         ctx = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
208         if (ctx == NULL)
209                 GOTO(err_out, rc = -ENOENT);
210
211         rc = llog_open(NULL, ctx, &llh, NULL, CHANGELOG_CATALOG,
212                        LLOG_OPEN_EXISTS);
213         if (rc) {
214                 CERROR("%s: fail to open changelog catalog: rc = %d\n",
215                        obd->obd_name, rc);
216                 GOTO(err_out, rc);
217         }
218
219         rc = llog_init_handle(NULL, llh, LLOG_F_IS_CAT|LLOG_F_EXT_JOBID, NULL);
220         if (rc) {
221                 CERROR("%s: fail to init llog handle: rc = %d\n",
222                        obd->obd_name, rc);
223                 GOTO(err_out, rc);
224         }
225
226         rc = llog_cat_process(NULL, llh, chlg_read_cat_process_cb, crs, 0, 0);
227         if (rc < 0) {
228                 CERROR("%s: fail to process llog: rc = %d\n", obd->obd_name, rc);
229                 GOTO(err_out, rc);
230         }
231
232         crs->crs_eof = true;
233
234 err_out:
235         if (rc < 0)
236                 crs->crs_err = true;
237
238         wake_up_all(&crs->crs_waitq_cons);
239
240         if (llh != NULL)
241                 llog_cat_close(NULL, llh);
242
243         if (ctx != NULL)
244                 llog_ctxt_put(ctx);
245
246         l_wait_event(crs->crs_waitq_prod, kthread_should_stop(), &lwi);
247
248         RETURN(rc);
249 }
250
251 /**
252  * Read handler, dequeues records from the chlg_reader_state if any.
253  * No partial records are copied to userland so this function can return less
254  * data than required (short read).
255  *
256  * @param[in]   file   File pointer to the character device.
257  * @param[out]  buff   Userland buffer where to copy the records.
258  * @param[in]   count  Userland buffer size.
259  * @param[out]  ppos   File position, updated with the index number of the next
260  *                     record to read.
261  * @return number of copied bytes on success, negated error code on failure.
262  */
263 static ssize_t chlg_read(struct file *file, char __user *buff, size_t count,
264                          loff_t *ppos)
265 {
266         struct chlg_reader_state *crs = file->private_data;
267         struct chlg_rec_entry *rec;
268         struct chlg_rec_entry *tmp;
269         struct l_wait_info lwi = { 0 };
270         ssize_t  written_total = 0;
271         LIST_HEAD(consumed);
272         ENTRY;
273
274         if (file->f_flags & O_NONBLOCK && crs->crs_rec_count == 0)
275                 RETURN(-EAGAIN);
276
277         l_wait_event(crs->crs_waitq_cons,
278                      crs->crs_rec_count > 0 || crs->crs_eof || crs->crs_err,
279                      &lwi);
280
281         mutex_lock(&crs->crs_lock);
282         list_for_each_entry_safe(rec, tmp, &crs->crs_rec_queue, enq_linkage) {
283                 if (written_total + rec->enq_length > count)
284                         break;
285
286                 if (copy_to_user(buff, rec->enq_record, rec->enq_length)) {
287                         if (written_total == 0)
288                                 written_total = -EFAULT;
289                         break;
290                 }
291
292                 buff += rec->enq_length;
293                 written_total += rec->enq_length;
294
295                 crs->crs_rec_count--;
296                 list_move_tail(&rec->enq_linkage, &consumed);
297
298                 crs->crs_start_offset = rec->enq_record->cr_index + 1;
299         }
300         mutex_unlock(&crs->crs_lock);
301
302         if (written_total > 0)
303                 wake_up_all(&crs->crs_waitq_prod);
304
305         list_for_each_entry_safe(rec, tmp, &consumed, enq_linkage)
306                 enq_record_delete(rec);
307
308         *ppos = crs->crs_start_offset;
309
310         RETURN(written_total);
311 }
312
313 /**
314  * Jump to a given record index. Helper for chlg_llseek().
315  *
316  * @param[in,out]  crs     Internal reader state.
317  * @param[in]      offset  Desired offset (index record).
318  * @return 0 on success, negated error code on failure.
319  */
320 static int chlg_set_start_offset(struct chlg_reader_state *crs, __u64 offset)
321 {
322         struct chlg_rec_entry *rec;
323         struct chlg_rec_entry *tmp;
324
325         mutex_lock(&crs->crs_lock);
326         if (offset < crs->crs_start_offset) {
327                 mutex_unlock(&crs->crs_lock);
328                 return -ERANGE;
329         }
330
331         crs->crs_start_offset = offset;
332         list_for_each_entry_safe(rec, tmp, &crs->crs_rec_queue, enq_linkage) {
333                 struct changelog_rec *cr = rec->enq_record;
334
335                 if (cr->cr_index >= crs->crs_start_offset)
336                         break;
337
338                 crs->crs_rec_count--;
339                 enq_record_delete(rec);
340         }
341
342         mutex_unlock(&crs->crs_lock);
343         wake_up_all(&crs->crs_waitq_prod);
344         return 0;
345 }
346
347 /**
348  * Move read pointer to a certain record index, encoded as an offset.
349  *
350  * @param[in,out] file   File pointer to the changelog character device
351  * @param[in]     off    Offset to skip, actually a record index, not byte count
352  * @param[in]     whence Relative/Absolute interpretation of the offset
353  * @return the resulting position on success or negated error code on failure.
354  */
355 static loff_t chlg_llseek(struct file *file, loff_t off, int whence)
356 {
357         struct chlg_reader_state *crs = file->private_data;
358         loff_t pos;
359         int rc;
360
361         switch (whence) {
362         case SEEK_SET:
363                 pos = off;
364                 break;
365         case SEEK_CUR:
366                 pos = file->f_pos + off;
367                 break;
368         case SEEK_END:
369         default:
370                 return -EINVAL;
371         }
372
373         /* We cannot go backward */
374         if (pos < file->f_pos)
375                 return -EINVAL;
376
377         rc = chlg_set_start_offset(crs, pos);
378         if (rc != 0)
379                 return rc;
380
381         file->f_pos = pos;
382         return pos;
383 }
384
385 /**
386  * Clear record range for a given changelog reader.
387  *
388  * @param[in]  crs     Current internal state.
389  * @param[in]  reader  Changelog reader ID (cl1, cl2...)
390  * @param[in]  record  Record index up which to clear
391  * @return 0 on success, negated error code on failure.
392  */
393 static int chlg_clear(struct chlg_reader_state *crs, __u32 reader, __u64 record)
394 {
395         struct obd_device *obd = crs->crs_obd;
396         struct changelog_setinfo cs  = {
397                 .cs_recno = record,
398                 .cs_id    = reader
399         };
400
401         return obd_set_info_async(NULL, obd->obd_self_export,
402                                   strlen(KEY_CHANGELOG_CLEAR),
403                                   KEY_CHANGELOG_CLEAR, sizeof(cs), &cs, NULL);
404 }
405
406 /** Maximum changelog control command size */
407 #define CHLG_CONTROL_CMD_MAX    64
408
409 /**
410  * Handle writes() into the changelog character device. Write() can be used
411  * to request special control operations.
412  *
413  * @param[in]  file  File pointer to the changelog character device
414  * @param[in]  buff  User supplied data (written data)
415  * @param[in]  count Number of written bytes
416  * @param[in]  off   (unused)
417  * @return number of written bytes on success, negated error code on failure.
418  */
419 static ssize_t chlg_write(struct file *file, const char __user *buff,
420                           size_t count, loff_t *off)
421 {
422         struct chlg_reader_state *crs = file->private_data;
423         char *kbuf;
424         __u64 record;
425         __u32 reader;
426         int rc = 0;
427         ENTRY;
428
429         if (count > CHLG_CONTROL_CMD_MAX)
430                 RETURN(-EINVAL);
431
432         OBD_ALLOC(kbuf, CHLG_CONTROL_CMD_MAX);
433         if (kbuf == NULL)
434                 RETURN(-ENOMEM);
435
436         if (copy_from_user(kbuf, buff, count))
437                 GOTO(out_kbuf, rc = -EFAULT);
438
439         kbuf[CHLG_CONTROL_CMD_MAX - 1] = '\0';
440
441         if (sscanf(kbuf, "clear:cl%u:%llu", &reader, &record) == 2)
442                 rc = chlg_clear(crs, reader, record);
443         else
444                 rc = -EINVAL;
445
446         EXIT;
447 out_kbuf:
448         OBD_FREE(kbuf, CHLG_CONTROL_CMD_MAX);
449         return rc < 0 ? rc : count;
450 }
451
452 /**
453  * Find the OBD device associated to a changelog character device.
454  * @param[in]  cdev  character device instance descriptor
455  * @return corresponding OBD device or NULL if none was found.
456  */
457 static struct obd_device *chlg_obd_get(dev_t cdev)
458 {
459         int minor = MINOR(cdev);
460         struct obd_device *obd = NULL;
461         struct chlg_registered_dev *curr;
462
463         mutex_lock(&chlg_registered_dev_lock);
464         list_for_each_entry(curr, &chlg_registered_devices, ced_link) {
465                 if (curr->ced_misc.minor == minor) {
466                         /* take the first available OBD device attached */
467                         obd = list_first_entry(&curr->ced_obds,
468                                                struct obd_device,
469                                                u.cli.cl_chg_dev_linkage);
470                         break;
471                 }
472         }
473         mutex_unlock(&chlg_registered_dev_lock);
474         return obd;
475 }
476
477 /**
478  * Open handler, initialize internal CRS state and spawn prefetch thread if
479  * needed.
480  * @param[in]  inode  Inode struct for the open character device.
481  * @param[in]  file   Corresponding file pointer.
482  * @return 0 on success, negated error code on failure.
483  */
484 static int chlg_open(struct inode *inode, struct file *file)
485 {
486         struct chlg_reader_state *crs;
487         struct obd_device *obd = chlg_obd_get(inode->i_rdev);
488         struct task_struct *task;
489         int rc;
490         ENTRY;
491
492         if (!obd)
493                 RETURN(-ENODEV);
494
495         OBD_ALLOC_PTR(crs);
496         if (!crs)
497                 RETURN(-ENOMEM);
498
499         crs->crs_obd = obd;
500         crs->crs_err = false;
501         crs->crs_eof = false;
502
503         mutex_init(&crs->crs_lock);
504         INIT_LIST_HEAD(&crs->crs_rec_queue);
505         init_waitqueue_head(&crs->crs_waitq_prod);
506         init_waitqueue_head(&crs->crs_waitq_cons);
507
508         if (file->f_mode & FMODE_READ) {
509                 task = kthread_run(chlg_load, crs, "chlg_load_thread");
510                 if (IS_ERR(task)) {
511                         rc = PTR_ERR(task);
512                         CERROR("%s: cannot start changelog thread: rc = %d\n",
513                                obd->obd_name, rc);
514                         GOTO(err_crs, rc);
515                 }
516                 crs->crs_prod_task = task;
517         }
518
519         file->private_data = crs;
520         RETURN(0);
521
522 err_crs:
523         OBD_FREE_PTR(crs);
524         return rc;
525 }
526
527 /**
528  * Close handler, release resources.
529  *
530  * @param[in]  inode  Inode struct for the open character device.
531  * @param[in]  file   Corresponding file pointer.
532  * @return 0 on success, negated error code on failure.
533  */
534 static int chlg_release(struct inode *inode, struct file *file)
535 {
536         struct chlg_reader_state *crs = file->private_data;
537         struct chlg_rec_entry *rec;
538         struct chlg_rec_entry *tmp;
539
540         if (crs->crs_prod_task)
541                 kthread_stop(crs->crs_prod_task);
542
543         list_for_each_entry_safe(rec, tmp, &crs->crs_rec_queue, enq_linkage)
544                 enq_record_delete(rec);
545
546         OBD_FREE_PTR(crs);
547         return 0;
548 }
549
550 /**
551  * Poll handler, indicates whether the device is readable (new records) and
552  * writable (always).
553  *
554  * @param[in]  file   Device file pointer.
555  * @param[in]  wait   (opaque)
556  * @return combination of the poll status flags.
557  */
558 static unsigned int chlg_poll(struct file *file, poll_table *wait)
559 {
560         struct chlg_reader_state *crs = file->private_data;
561         unsigned int mask = 0;
562
563         mutex_lock(&crs->crs_lock);
564         poll_wait(file, &crs->crs_waitq_cons, wait);
565         if (crs->crs_rec_count > 0)
566                 mask |= POLLIN | POLLRDNORM;
567         if (crs->crs_err)
568                 mask |= POLLERR;
569         if (crs->crs_eof)
570                 mask |= POLLHUP;
571         mutex_unlock(&crs->crs_lock);
572         return mask;
573 }
574
575 static const struct file_operations chlg_fops = {
576         .owner          = THIS_MODULE,
577         .llseek         = chlg_llseek,
578         .read           = chlg_read,
579         .write          = chlg_write,
580         .open           = chlg_open,
581         .release        = chlg_release,
582         .poll           = chlg_poll,
583 };
584
585 /**
586  * This uses obd_name of the form: "testfs-MDT0000-mdc-ffff88006501600"
587  * and returns a name of the form: "changelog-testfs-MDT0000".
588  */
589 static void get_chlg_name(char *name, size_t name_len, struct obd_device *obd)
590 {
591         int i;
592
593         snprintf(name, name_len, "changelog-%s", obd->obd_name);
594
595         /* Find the 2nd '-' from the end and truncate on it */
596         for (i = 0; i < 2; i++) {
597                 char *p = strrchr(name, '-');
598
599                 if (p == NULL)
600                         return;
601                 *p = '\0';
602         }
603 }
604
605 /**
606  * Find a changelog character device by name.
607  * All devices registered during MDC setup are listed in a global list with
608  * their names attached.
609  */
610 static struct chlg_registered_dev *
611 chlg_registered_dev_find_by_name(const char *name)
612 {
613         struct chlg_registered_dev *dit;
614
615         list_for_each_entry(dit, &chlg_registered_devices, ced_link)
616                 if (strcmp(name, dit->ced_name) == 0)
617                         return dit;
618         return NULL;
619 }
620
621 /**
622  * Find chlg_registered_dev structure for a given OBD device.
623  * This is bad O(n^2) but for each filesystem:
624  *   - N is # of MDTs times # of mount points
625  *   - this only runs at shutdown
626  */
627 static struct chlg_registered_dev *
628 chlg_registered_dev_find_by_obd(const struct obd_device *obd)
629 {
630         struct chlg_registered_dev *dit;
631         struct obd_device *oit;
632
633         list_for_each_entry(dit, &chlg_registered_devices, ced_link)
634                 list_for_each_entry(oit, &dit->ced_obds,
635                                     u.cli.cl_chg_dev_linkage)
636                         if (oit == obd)
637                                 return dit;
638         return NULL;
639 }
640
641 /**
642  * Changelog character device initialization.
643  * Register a misc character device with a dynamic minor number, under a name
644  * of the form: 'changelog-fsname-MDTxxxx'. Reference this OBD device with it.
645  *
646  * @param[in] obd  This MDC obd_device.
647  * @return 0 on success, negated error code on failure.
648  */
649 int mdc_changelog_cdev_init(struct obd_device *obd)
650 {
651         struct chlg_registered_dev *exist;
652         struct chlg_registered_dev *entry;
653         int rc;
654         ENTRY;
655
656         OBD_ALLOC_PTR(entry);
657         if (entry == NULL)
658                 RETURN(-ENOMEM);
659
660         get_chlg_name(entry->ced_name, sizeof(entry->ced_name), obd);
661
662         entry->ced_misc.minor = MISC_DYNAMIC_MINOR;
663         entry->ced_misc.name  = entry->ced_name;
664         entry->ced_misc.fops  = &chlg_fops;
665
666         kref_init(&entry->ced_refs);
667         INIT_LIST_HEAD(&entry->ced_obds);
668         INIT_LIST_HEAD(&entry->ced_link);
669
670         mutex_lock(&chlg_registered_dev_lock);
671         exist = chlg_registered_dev_find_by_name(entry->ced_name);
672         if (exist != NULL) {
673                 kref_get(&exist->ced_refs);
674                 list_add_tail(&obd->u.cli.cl_chg_dev_linkage, &exist->ced_obds);
675                 GOTO(out_unlock, rc = 0);
676         }
677
678         /* Register new character device */
679         rc = misc_register(&entry->ced_misc);
680         if (rc != 0)
681                 GOTO(out_unlock, rc);
682
683         list_add_tail(&obd->u.cli.cl_chg_dev_linkage, &entry->ced_obds);
684         list_add_tail(&entry->ced_link, &chlg_registered_devices);
685
686         entry = NULL;   /* prevent it from being freed below */
687
688 out_unlock:
689         mutex_unlock(&chlg_registered_dev_lock);
690         if (entry)
691                 OBD_FREE_PTR(entry);
692         RETURN(rc);
693 }
694
695 /**
696  * Deregister a changelog character device whose refcount has reached zero.
697  */
698 static void chlg_dev_clear(struct kref *kref)
699 {
700         struct chlg_registered_dev *entry = container_of(kref,
701                                                       struct chlg_registered_dev,
702                                                       ced_refs);
703         ENTRY;
704
705         list_del(&entry->ced_link);
706         misc_deregister(&entry->ced_misc);
707         OBD_FREE_PTR(entry);
708         EXIT;
709 }
710
711 /**
712  * Release OBD, decrease reference count of the corresponding changelog device.
713  */
714 void mdc_changelog_cdev_finish(struct obd_device *obd)
715 {
716         struct chlg_registered_dev *dev = chlg_registered_dev_find_by_obd(obd);
717         ENTRY;
718
719         mutex_lock(&chlg_registered_dev_lock);
720         list_del_init(&obd->u.cli.cl_chg_dev_linkage);
721         kref_put(&dev->ced_refs, chlg_dev_clear);
722         mutex_unlock(&chlg_registered_dev_lock);
723         EXIT;
724 }