Whamcloud - gitweb
- landing of b_hd_cleanup_merge to HEAD.
[fs/lustre-release.git] / lustre / obdclass / obd_config.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Config API
22  *
23  */
24
25 #define DEBUG_SUBSYSTEM S_CLASS
26 #ifdef __KERNEL__
27 #include <linux/kmod.h>   /* for request_module() */
28 #include <linux/module.h>
29 #include <linux/obd_class.h>
30 #include <linux/random.h>
31 #include <linux/slab.h>
32 #include <linux/pagemap.h>
33 #else
34 #include <liblustre.h>
35 #include <linux/obd_class.h>
36 #include <linux/obd.h>
37 #endif
38 #include <linux/lustre_log.h>
39 #include <linux/lprocfs_status.h>
40 #include <portals/list.h>
41
42
43 /* Create a new device and set the type, name and uuid.  If
44  * successful, the new device can be accessed by either name or uuid.
45  */
46 static int class_attach(struct lustre_cfg *lcfg)
47 {
48         struct obd_type *type;
49         struct obd_device *obd;
50         char *typename, *name, *uuid;
51         int rc, len, cleanup_phase = 0;
52
53         if (!lcfg->lcfg_inllen1 || !lcfg->lcfg_inlbuf1) {
54                 CERROR("No type passed!\n");
55                 RETURN(-EINVAL);
56         }
57         if (lcfg->lcfg_inlbuf1[lcfg->lcfg_inllen1 - 1] != 0) {
58                 CERROR("Type not nul terminated!\n");
59                 RETURN(-EINVAL);
60         }
61         typename = lcfg->lcfg_inlbuf1;
62
63         if (!lcfg->lcfg_dev_namelen || !lcfg->lcfg_dev_name) {
64                 CERROR("No name passed!\n");
65                 RETURN(-EINVAL);
66         }
67         if (lcfg->lcfg_dev_name[lcfg->lcfg_dev_namelen - 1] != 0) {
68                 CERROR("Name not nul terminated!\n");
69                 RETURN(-EINVAL);
70         }
71         name = lcfg->lcfg_dev_name;
72
73         if (!lcfg->lcfg_inllen2 || !lcfg->lcfg_inlbuf2) {
74                 CERROR("No UUID passed!\n");
75                 RETURN(-EINVAL);
76         }
77         if (lcfg->lcfg_inlbuf2[lcfg->lcfg_inllen2 - 1] != 0) {
78                 CERROR("UUID not nul terminated!\n");
79                 RETURN(-EINVAL);
80         }
81         uuid = lcfg->lcfg_inlbuf2;
82
83         CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
84                MKSTR(lcfg->lcfg_inlbuf1),
85                MKSTR(lcfg->lcfg_dev_name), MKSTR(lcfg->lcfg_inlbuf2));
86
87         /* find the type */
88         type = class_get_type(typename);
89         if (!type) {
90                 CERROR("OBD: unknown type: %s\n", typename);
91                 RETURN(-EINVAL);
92         }
93         cleanup_phase = 1;  /* class_put_type */
94
95         obd = class_name2obd(name);
96         if (obd != NULL) {
97                 CERROR("obd %s already attached\n", name);
98                 GOTO(out, rc = -EEXIST);
99         }
100
101         obd = class_newdev(type);
102         if (obd == NULL)
103                 GOTO(out, rc = -EINVAL);
104
105         cleanup_phase = 2;  /* class_release_dev */
106         
107         INIT_LIST_HEAD(&obd->obd_exports);
108         obd->obd_num_exports = 0;
109         spin_lock_init(&obd->obd_dev_lock);
110         spin_lock_init(&obd->obd_osfs_lock);
111         obd->obd_osfs_age = jiffies - 1000 * HZ;
112         init_waitqueue_head(&obd->obd_refcount_waitq);
113
114         /* XXX belongs in setup not attach  */
115         /* recovery data */
116         init_timer(&obd->obd_recovery_timer);
117         spin_lock_init(&obd->obd_processing_task_lock);
118         init_waitqueue_head(&obd->obd_next_transno_waitq);
119         INIT_LIST_HEAD(&obd->obd_recovery_queue);
120         INIT_LIST_HEAD(&obd->obd_delayed_reply_queue);
121
122         spin_lock_init(&obd->obd_uncommitted_replies_lock);
123         INIT_LIST_HEAD(&obd->obd_uncommitted_replies);
124
125         len = strlen(name) + 1;
126         OBD_ALLOC(obd->obd_name, len);
127         if (!obd->obd_name)
128                 GOTO(out, rc = -ENOMEM);
129         memcpy(obd->obd_name, name, len);
130         
131         cleanup_phase = 3; /* free obd_name */
132
133         len = strlen(uuid);
134         if (len >= sizeof(obd->obd_uuid)) {
135                 CERROR("uuid must be < "LPSZ" bytes long\n",
136                        sizeof(obd->obd_uuid));
137                 GOTO(out, rc = -EINVAL);
138         }
139         memcpy(obd->obd_uuid.uuid, uuid, len);
140
141         /* do the attach */
142         if (OBP(obd, attach)) {
143                 rc = OBP(obd,attach)(obd, sizeof *lcfg, lcfg);
144                 if (rc)
145                         GOTO(out, rc = -EINVAL);
146         }
147
148         obd->obd_attached = 1;
149         type->typ_refcnt++;
150         CDEBUG(D_IOCTL, "OBD: dev %d attached type %s\n",
151                obd->obd_minor, typename);
152         RETURN(0);
153  out:
154         switch (cleanup_phase) {
155         case 3:
156                 OBD_FREE(obd->obd_name, strlen(obd->obd_name) + 1);
157         case 2:
158                 class_release_dev(obd);
159         case 1:
160                 class_put_type(type);
161                 obd->obd_type = NULL;
162         }
163         return rc;
164 }
165
166 static int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
167 {
168         int err = 0;
169         struct obd_export *exp;
170         ENTRY;
171
172         LASSERT(obd == (obd_dev + obd->obd_minor));
173
174         /* have we attached a type to this device? */
175         if (!obd->obd_attached) {
176                 CERROR("Device %d not attached\n", obd->obd_minor);
177                 RETURN(-ENODEV);
178         }
179
180         /* has this been done already? */
181         if (obd->obd_set_up) {
182                 CERROR("Device %d already setup (type %s)\n",
183                        obd->obd_minor, obd->obd_type->typ_name);
184                 RETURN(-EBUSY);
185         }
186
187         atomic_set(&obd->obd_refcount, 0);
188
189         exp = class_new_export(obd);
190         if (exp == NULL)
191                 RETURN(err);
192         memcpy(&exp->exp_client_uuid, &obd->obd_uuid,
193                sizeof(exp->exp_client_uuid));
194         obd->obd_self_export = exp;
195         class_export_put(exp);
196
197         err = obd_setup(obd, sizeof(*lcfg), lcfg);
198         if (err)
199                 GOTO(err_exp, err);
200
201         obd->obd_type->typ_refcnt++;
202         obd->obd_set_up = 1;
203
204         RETURN(err);
205
206 err_exp:
207         class_unlink_export(obd->obd_self_export);
208         obd->obd_self_export = NULL;
209         RETURN(err);
210 }
211
212 static int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
213 {
214         int err = 0;
215
216         ENTRY;
217         if (obd->obd_set_up) {
218                 CERROR("OBD device %d still set up\n", obd->obd_minor);
219                 RETURN(-EBUSY);
220         }
221         if (!obd->obd_attached) {
222                 CERROR("OBD device %d not attached\n", obd->obd_minor);
223                 RETURN(-ENODEV);
224         }
225         if (OBP(obd, detach))
226                 err = OBP(obd,detach)(obd);
227
228         if (obd->obd_name) {
229                 OBD_FREE(obd->obd_name, strlen(obd->obd_name)+1);
230                 obd->obd_name = NULL;
231         } else {
232                 CERROR("device %d: no name at detach\n", obd->obd_minor);
233         }
234
235         obd->obd_attached = 0;
236         obd->obd_type->typ_refcnt--;
237         class_put_type(obd->obd_type);
238         class_release_dev(obd);
239         RETURN(err);
240 }
241
242 static void dump_exports(struct obd_device *obd)
243 {
244         struct obd_export *exp, *n;
245
246         list_for_each_entry_safe(exp, n, &obd->obd_exports, exp_obd_chain) {
247                 struct ptlrpc_reply_state *rs;
248                 struct ptlrpc_reply_state *first_reply = NULL;
249                 int                        nreplies = 0;
250
251                 list_for_each_entry (rs, &exp->exp_outstanding_replies,
252                                      rs_exp_list) {
253                         if (nreplies == 0)
254                                 first_reply = rs;
255                         nreplies++;
256                 }
257
258                 CERROR("%s: %p %s %d %d %d: %p %s\n",
259                        obd->obd_name, exp, exp->exp_client_uuid.uuid,
260                        atomic_read(&exp->exp_refcount),
261                        exp->exp_failed, nreplies, first_reply,
262                        nreplies > 3 ? "..." : "");
263         }
264 }
265
266 static int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
267 {
268         int flags = 0;
269         int err = 0;
270         char *flag;
271
272         ENTRY;
273         if (!obd->obd_set_up) {
274                 CERROR("Device %d not setup\n", obd->obd_minor);
275                 RETURN(-ENODEV);
276         }
277
278         if (lcfg->lcfg_inlbuf1) {
279                 for (flag = lcfg->lcfg_inlbuf1; *flag != 0; flag++)
280                         switch (*flag) {
281                         case 'F':
282                                 flags |= OBD_OPT_FORCE;
283                                 break;
284                         case 'A':
285                                 flags |= OBD_OPT_FAILOVER;
286                                 break;
287                         default:
288                                 CERROR("unrecognised flag '%c'\n",
289                                        *flag);
290                         }
291         }
292
293         /* The one reference that should be remaining is the
294          * obd_self_export */
295         if (atomic_read(&obd->obd_refcount) <= 1 ||
296             flags & OBD_OPT_FORCE) {
297                 /* this will stop new connections, and need to
298                    do it before class_disconnect_exports() */
299                 obd->obd_stopping = 1;
300         }
301
302         if (atomic_read(&obd->obd_refcount) > 1) {
303                 struct l_wait_info lwi = LWI_TIMEOUT_INTR(1 * HZ, NULL,
304                                                           NULL, NULL);
305                 int rc;
306
307                 if (!(flags & OBD_OPT_FORCE)) {
308                         CERROR("OBD device %d (%p,%s) has refcount %d\n",
309                                obd->obd_minor, obd, obd->obd_name,
310                                atomic_read(&obd->obd_refcount));
311                         dump_exports(obd);
312                         GOTO(out, err = -EBUSY);
313                 }
314                 class_disconnect_exports(obd, flags);
315                 CDEBUG(D_IOCTL,
316                        "%s: waiting for obd refs to go away: %d\n",
317                        obd->obd_name, atomic_read(&obd->obd_refcount));
318
319                 rc = l_wait_event(obd->obd_refcount_waitq,
320                                   atomic_read(&obd->obd_refcount) < 2, &lwi);
321                 if (rc == 0) {
322                         LASSERT(atomic_read(&obd->obd_refcount) == 1);
323                 } else {
324                         CERROR("wait cancelled cleaning anyway. "
325                                "refcount: %d\n",
326                                atomic_read(&obd->obd_refcount));
327                         dump_exports(obd);
328                 }
329                 CDEBUG(D_IOCTL, "%s: awake, now finishing cleanup\n",
330                        obd->obd_name);
331         }
332
333         if (obd->obd_self_export) {
334                 err = obd_precleanup(obd, flags);
335                 if (err)
336                         GOTO(out, err);
337                 class_unlink_export(obd->obd_self_export);
338                 obd->obd_self_export = NULL;
339         }
340
341         err = obd_cleanup(obd, flags);
342 out:
343         if (!err) {
344                 obd->obd_set_up = obd->obd_stopping = 0;
345                 obd->obd_type->typ_refcnt--;
346                 /* XXX this should be an LASSERT */
347                 if (atomic_read(&obd->obd_refcount) > 0) {
348                         CERROR("%s (%p) still has refcount %d after "
349                                "cleanup.\n", obd->obd_name, obd,
350                                atomic_read(&obd->obd_refcount));
351                         dump_exports(obd);
352                 }
353         }
354
355         RETURN(err);
356 }
357
358 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
359 {
360         struct obd_import *imp;
361         struct obd_uuid uuid;
362         int priority, rc;
363         ENTRY;
364
365         if (lcfg->lcfg_inllen1 <= 0 ||
366             lcfg->lcfg_inllen1 > sizeof(struct obd_uuid)) {
367                 CERROR("invalid conn_uuid\n");
368                 RETURN(-EINVAL);
369         }
370         if (lcfg->lcfg_inllen2 != sizeof(int)) {
371                 CERROR("invalid priority\n");
372                 RETURN(-EINVAL);
373         }
374         if (strcmp(obd->obd_type->typ_name, "mdc") &&
375             strcmp(obd->obd_type->typ_name, "osc")) {
376                 CERROR("can't add connection on non-client dev\n");
377                 RETURN(-EINVAL);
378         }
379
380         imp = obd->u.cli.cl_import;
381         if (!imp) {
382                 CERROR("try to add conn on immature client dev\n");
383                 RETURN(-EINVAL);
384         }
385
386         obd_str2uuid(&uuid, lcfg->lcfg_inlbuf1);
387         priority = *((int*) lcfg->lcfg_inlbuf2);
388         rc = obd_add_conn(imp, &uuid, priority);
389
390         RETURN(rc);
391 }
392 int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
393 {
394         struct obd_import *imp;
395         struct obd_uuid uuid;
396         int rc;
397         ENTRY;
398
399         if (lcfg->lcfg_inllen1 <= 0 ||
400             lcfg->lcfg_inllen1 > sizeof(struct obd_uuid)) {
401                 CERROR("invalid conn_uuid\n");
402                 RETURN(-EINVAL);
403         }
404         if (strcmp(obd->obd_type->typ_name, "mdc") &&
405             strcmp(obd->obd_type->typ_name, "osc")) {
406                 CERROR("can't add connection on non-client dev\n");
407                 RETURN(-EINVAL);
408         }
409
410         imp = obd->u.cli.cl_import;
411         if (!imp) {
412                 CERROR("try to del conn on immature client dev\n");
413                 RETURN(-EINVAL);
414         }
415
416         obd_str2uuid(&uuid, lcfg->lcfg_inlbuf1);
417         rc = obd_del_conn(imp, &uuid);
418
419         RETURN(rc);
420 }
421
422 LIST_HEAD(lustre_profile_list);
423
424 struct lustre_profile *class_get_profile(char * prof)
425 {
426         struct lustre_profile *lprof;
427
428         list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
429                 if (!strcmp(lprof->lp_profile, prof)) {
430                         RETURN(lprof);
431                 }
432         }
433         RETURN(NULL);
434 }
435
436 int class_add_profile(int proflen, char *prof, int osclen, char *osc,
437                       int mdclen, char *mdc)
438 {
439         struct lustre_profile *lprof;
440         int err = 0;
441
442         OBD_ALLOC(lprof, sizeof(*lprof));
443         if (lprof == NULL)
444                 GOTO(out, err = -ENOMEM);
445         INIT_LIST_HEAD(&lprof->lp_list);
446
447         LASSERT(proflen == (strlen(prof) + 1));
448         OBD_ALLOC(lprof->lp_profile, proflen);
449         if (lprof->lp_profile == NULL)
450                 GOTO(out, err = -ENOMEM);
451         memcpy(lprof->lp_profile, prof, proflen);
452
453         LASSERT(osclen == (strlen(osc) + 1));
454         OBD_ALLOC(lprof->lp_osc, osclen);
455         if (lprof->lp_profile == NULL)
456                 GOTO(out, err = -ENOMEM);
457         memcpy(lprof->lp_osc, osc, osclen);
458
459         if (mdclen > 0) {
460                 LASSERT(mdclen == (strlen(mdc) + 1));
461                 OBD_ALLOC(lprof->lp_mdc, mdclen);
462                 if (lprof->lp_mdc == NULL)
463                         GOTO(out, err = -ENOMEM);
464                 memcpy(lprof->lp_mdc, mdc, mdclen);
465         }
466
467         list_add(&lprof->lp_list, &lustre_profile_list);
468
469 out:
470         RETURN(err);
471 }
472
473 void class_del_profile(char *prof)
474 {
475         struct lustre_profile *lprof;
476
477         lprof = class_get_profile(prof);
478         if (lprof) {
479                 list_del(&lprof->lp_list);
480                 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
481                 OBD_FREE(lprof->lp_osc, strlen(lprof->lp_osc) + 1);
482                 if (lprof->lp_mdc)
483                         OBD_FREE(lprof->lp_mdc, strlen(lprof->lp_mdc) + 1);
484                 OBD_FREE(lprof, sizeof *lprof);
485         }
486 }
487
488 int class_process_config(struct lustre_cfg *lcfg)
489 {
490         struct obd_device *obd;
491         char str[PTL_NALFMT_SIZE];
492         int err;
493         ENTRY;
494
495         LASSERT(lcfg && !IS_ERR(lcfg));
496
497         CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
498
499         /* Commands that don't need a device */
500         switch(lcfg->lcfg_command) {
501         case LCFG_ATTACH: {
502                 err = class_attach(lcfg);
503                 GOTO(out, err);
504         }
505         case LCFG_ADD_UUID: {
506                 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64
507                        " (%s), nal %d\n", lcfg->lcfg_inlbuf1, lcfg->lcfg_nid,
508                        portals_nid2str(lcfg->lcfg_nal, lcfg->lcfg_nid, str),
509                        lcfg->lcfg_nal);
510
511                 err = class_add_uuid(lcfg->lcfg_inlbuf1, lcfg->lcfg_nid,
512                                      lcfg->lcfg_nal);
513                 GOTO(out, err);
514         }
515         case LCFG_DEL_UUID: {
516                 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
517                        lcfg->lcfg_inlbuf1 == NULL ? "<all uuids>" :
518                        lcfg->lcfg_inlbuf1);
519
520                 err = class_del_uuid(lcfg->lcfg_inlbuf1);
521                 GOTO(out, err);
522         }
523         case LCFG_MOUNTOPT: {
524                 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
525                        lcfg->lcfg_inlbuf1, lcfg->lcfg_inlbuf2,
526                        lcfg->lcfg_inlbuf3);
527                 /* set these mount options somewhere, so ll_fill_super
528                  * can find them. */
529                 err = class_add_profile(lcfg->lcfg_inllen1, lcfg->lcfg_inlbuf1,
530                                         lcfg->lcfg_inllen2, lcfg->lcfg_inlbuf2,
531                                         lcfg->lcfg_inllen3, lcfg->lcfg_inlbuf3);
532                 GOTO(out, err);
533         }
534         case LCFG_DEL_MOUNTOPT: {
535                 CDEBUG(D_IOCTL, "mountopt: profile %s\n", lcfg->lcfg_inlbuf1);
536                 /* set these mount options somewhere, so ll_fill_super
537                  * can find them. */
538                 class_del_profile(lcfg->lcfg_inlbuf1);
539                 GOTO(out, err = 0);
540         }
541         case LCFG_SET_TIMEOUT: {
542                 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
543                        obd_timeout,
544                        lcfg->lcfg_num);
545                 obd_timeout = lcfg->lcfg_num;
546                 GOTO(out, err = 0);
547         }
548         case LCFG_SET_UPCALL: {
549                 CDEBUG(D_IOCTL, "setting lustre ucpall to: %s\n",
550                        lcfg->lcfg_inlbuf1);
551                 if (lcfg->lcfg_inllen1 > sizeof obd_lustre_upcall)
552                         GOTO(out, err = -EINVAL);
553                 memcpy(obd_lustre_upcall, lcfg->lcfg_inlbuf1,
554                        lcfg->lcfg_inllen1);
555                 GOTO(out, err = 0);
556         }
557         }
558
559         /* Commands that require a device */
560         obd = class_name2obd(lcfg->lcfg_dev_name);
561         if (obd == NULL) {
562                 if (lcfg->lcfg_dev_name == NULL)
563                         CERROR("this lcfg command requires a device name\n");
564                 else
565                         CERROR("no device for: %s\n", lcfg->lcfg_dev_name);
566
567                 GOTO(out, err = -EINVAL);
568         }
569
570         switch(lcfg->lcfg_command) {
571         case LCFG_SETUP: {
572                 err = class_setup(obd, lcfg);
573                 GOTO(out, err);
574         }
575         case LCFG_DETACH: {
576                 err = class_detach(obd, lcfg);
577                 GOTO(out, err = 0);
578         }
579         case LCFG_CLEANUP: {
580                 err = class_cleanup(obd, lcfg);
581                 GOTO(out, err = 0);
582         }
583         case LCFG_ADD_CONN: {
584                 err = class_add_conn(obd, lcfg);
585                 GOTO(out, err = 0);
586         }
587         case LCFG_DEL_CONN: {
588                 err = class_del_conn(obd, lcfg);
589                 GOTO(out, err = 0);
590         }
591         default: {
592                 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
593                 GOTO(out, err);
594
595         }
596         }
597 out:
598         RETURN(err);
599 }
600
601 static int class_config_parse_handler(struct llog_handle * handle,
602                                       struct llog_rec_hdr *rec, void *data)
603 {
604         struct config_llog_instance *cfg = data;
605         int cfg_len = rec->lrh_len;
606         char *cfg_buf = (char*) (rec + 1);
607         int rc = 0;
608         ENTRY;
609
610         if (rec->lrh_type == OBD_CFG_REC) {
611                 char *buf;
612                 struct lustre_cfg *lcfg;
613                 char *old_name = NULL;
614                 int old_len = 0;
615                 char *old_uuid = NULL;
616                 int old_uuid_len = 0;
617                 char *inst_name = NULL;
618                 int inst_len = 0;
619
620                 rc = lustre_cfg_getdata(&buf, cfg_len, cfg_buf, 1);
621                 if (rc)
622                         GOTO(out, rc);
623                 lcfg = (struct lustre_cfg* ) buf;
624
625                 if (cfg && cfg->cfg_instance && lcfg->lcfg_dev_name) {
626                         inst_len = strlen(lcfg->lcfg_dev_name) +
627                                 strlen(cfg->cfg_instance) + 2;
628                         OBD_ALLOC(inst_name, inst_len);
629                         if (inst_name == NULL)
630                                 GOTO(out, rc = -ENOMEM);
631                         sprintf(inst_name, "%s-%s", lcfg->lcfg_dev_name,
632                                 cfg->cfg_instance);
633                         old_name = lcfg->lcfg_dev_name;
634                         old_len = lcfg->lcfg_dev_namelen;
635                         lcfg->lcfg_dev_name = inst_name;
636                         lcfg->lcfg_dev_namelen = strlen(inst_name) + 1;
637                 }
638
639                 if (cfg && lcfg->lcfg_command == LCFG_ATTACH) {
640                         old_uuid = lcfg->lcfg_inlbuf2;
641                         old_uuid_len = lcfg->lcfg_inllen2;
642
643                         lcfg->lcfg_inlbuf2 = (char*)&cfg->cfg_uuid.uuid;
644                         lcfg->lcfg_inllen2 = sizeof(cfg->cfg_uuid);
645                 }
646
647                 rc = class_process_config(lcfg);
648
649                 if (old_name) {
650                         lcfg->lcfg_dev_name = old_name;
651                         lcfg->lcfg_dev_namelen = old_len;
652                         OBD_FREE(inst_name, inst_len);
653                 }
654
655                 if (old_uuid) {
656                         lcfg->lcfg_inlbuf2 = old_uuid;
657                         lcfg->lcfg_inllen2 = old_uuid_len;
658                 }
659
660                 lustre_cfg_freedata(buf, cfg_len);
661         } else if (rec->lrh_type == PTL_CFG_REC) {
662                 struct portals_cfg *pcfg = (struct portals_cfg *)cfg_buf;
663                 if (pcfg->pcfg_command == NAL_CMD_REGISTER_MYNID &&
664                     cfg->cfg_local_nid != PTL_NID_ANY) {
665                         pcfg->pcfg_nid = cfg->cfg_local_nid;
666                 }
667
668                 rc = libcfs_nal_cmd(pcfg);
669         } else {
670                 CERROR("unrecognized record type: 0x%x\n", rec->lrh_type);
671         }
672 out:
673         RETURN(rc);
674 }
675
676 int class_config_process_llog(struct llog_ctxt *ctxt, char *name,
677                               struct config_llog_instance *cfg)
678 {
679         struct llog_handle *llh;
680         int rc, rc2;
681         ENTRY;
682
683         rc = llog_open(ctxt, &llh, NULL, name, 0);
684         if (rc)
685                 RETURN(rc);
686
687         rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
688         if (rc == 0)
689                 rc = llog_process(llh, class_config_parse_handler, cfg, NULL);
690
691         rc2 = llog_close(llh);
692         if (rc == 0)
693                 rc = rc2;
694
695         RETURN(rc);
696 }
697
698 static int class_config_dump_handler(struct llog_handle * handle,
699                                      struct llog_rec_hdr *rec, void *data)
700 {
701         int cfg_len = rec->lrh_len;
702         char *cfg_buf = (char*) (rec + 1);
703         int rc = 0;
704         ENTRY;
705
706         if (rec->lrh_type == OBD_CFG_REC) {
707                 char *buf;
708                 struct lustre_cfg *lcfg;
709
710                 rc = lustre_cfg_getdata(&buf, cfg_len, cfg_buf, 1);
711                 if (rc)
712                         GOTO(out, rc);
713                 lcfg = (struct lustre_cfg* ) buf;
714
715                 CDEBUG(D_INFO, "lcfg command: 0x%x\n", lcfg->lcfg_command);
716                 if (lcfg->lcfg_dev_name)
717                         CDEBUG(D_INFO, "     devname: %s\n",
718                                lcfg->lcfg_dev_name);
719                 if (lcfg->lcfg_flags)
720                         CDEBUG(D_INFO, "       flags: 0x%x\n", lcfg->lcfg_flags);
721                 if (lcfg->lcfg_nid)
722                         CDEBUG(D_INFO, "         nid: "LPX64"\n",
723                                lcfg->lcfg_nid);
724                 if (lcfg->lcfg_nal)
725                         CDEBUG(D_INFO, "         nal: %x\n", lcfg->lcfg_nal);
726                 if (lcfg->lcfg_num)
727                         CDEBUG(D_INFO, "         nal: %x\n", lcfg->lcfg_num);
728                 if (lcfg->lcfg_inlbuf1)
729                         CDEBUG(D_INFO, "     inlbuf1: %s\n",lcfg->lcfg_inlbuf1);
730                 if (lcfg->lcfg_inlbuf2)
731                         CDEBUG(D_INFO, "     inlbuf2: %s\n",lcfg->lcfg_inlbuf2);
732                 if (lcfg->lcfg_inlbuf3)
733                         CDEBUG(D_INFO, "     inlbuf3: %s\n",lcfg->lcfg_inlbuf3);
734                 if (lcfg->lcfg_inlbuf4)
735                         CDEBUG(D_INFO, "     inlbuf4: %s\n",lcfg->lcfg_inlbuf4);
736                 if (lcfg->lcfg_inlbuf5)
737                         CDEBUG(D_INFO, "     inlbuf5: %s\n",lcfg->lcfg_inlbuf5);
738                 if (lcfg->lcfg_inlbuf6)
739                         CDEBUG(D_INFO, "     inlbuf6: %s\n",lcfg->lcfg_inlbuf6);
740
741                 lustre_cfg_freedata(buf, cfg_len);
742         } else if (rec->lrh_type == PTL_CFG_REC) {
743                 struct portals_cfg *pcfg = (struct portals_cfg *)cfg_buf;
744
745                 CDEBUG(D_INFO, "pcfg command: 0x%x\n", pcfg->pcfg_command);
746                 if (pcfg->pcfg_nal)
747                         CDEBUG(D_INFO, "         nal: %d\n",
748                                pcfg->pcfg_nal);
749                 if (pcfg->pcfg_gw_nal)
750                         CDEBUG(D_INFO, "      gw_nal: %d\n",
751                                pcfg->pcfg_gw_nal);
752                 if (pcfg->pcfg_nid)
753                         CDEBUG(D_INFO, "         nid: "LPX64"\n",
754                                pcfg->pcfg_nid);
755                 if (pcfg->pcfg_nid2)
756                         CDEBUG(D_INFO, "        nid2: "LPX64"\n",
757                                pcfg->pcfg_nid2);
758                 if (pcfg->pcfg_nid3)
759                         CDEBUG(D_INFO, "        nid3: "LPX64"\n",
760                                pcfg->pcfg_nid3);
761                 if (pcfg->pcfg_misc)
762                         CDEBUG(D_INFO, "        misc: %d\n",
763                                pcfg->pcfg_misc);
764                 if (pcfg->pcfg_id)
765                         CDEBUG(D_INFO, "          id: 0x%x\n",
766                                pcfg->pcfg_id);
767                 if (pcfg->pcfg_flags)
768                         CDEBUG(D_INFO, "       flags: 0x%x\n",
769                                pcfg->pcfg_flags);
770         } else {
771                 CERROR("unhandled lrh_type: %#x\n", rec->lrh_type);
772                 rc = -EINVAL;
773         }
774 out:
775         RETURN(rc);
776 }
777
778 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
779                            struct config_llog_instance *cfg)
780 {
781         struct llog_handle *llh;
782         int rc, rc2;
783         ENTRY;
784
785         rc = llog_open(ctxt, &llh, NULL, name, 0);
786         if (rc)
787                 RETURN(rc);
788
789         rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
790         if (rc == 0)
791                 rc = llog_process(llh, class_config_dump_handler, cfg, NULL);
792
793         rc2 = llog_close(llh);
794         if (rc == 0)
795                 rc = rc2;
796
797         RETURN(rc);
798 }