Whamcloud - gitweb
not alloc memory with spinlock held.
[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-2006 Cluster File Systems, Inc.
5  *
6  *   This file is part of the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  * Config API
25  *
26  */
27
28 #define DEBUG_SUBSYSTEM S_CLASS
29 #ifdef __KERNEL__
30 #include <obd_class.h>
31 #include <linux/string.h>
32 #else
33 #include <liblustre.h>
34 #include <obd_class.h>
35 #include <obd.h>
36 #endif
37 #include <lustre_log.h>
38 #include <lprocfs_status.h>
39 #include <libcfs/list.h>
40 #include <lustre_param.h>
41 #include <class_hash.h>
42
43 extern struct lustre_hash_operations uuid_hash_operations;
44 extern struct lustre_hash_operations nid_hash_operations;
45
46 /*********** string parsing utils *********/
47
48 /* returns 0 if we find this key in the buffer, else 1 */
49 int class_find_param(char *buf, char *key, char **valp)
50 {
51         char *ptr;
52
53         if (!buf) 
54                 return 1;
55
56         if ((ptr = strstr(buf, key)) == NULL) 
57                 return 1;
58
59         if (valp) 
60                 *valp = ptr + strlen(key);
61         
62         return 0;
63 }
64
65 /* returns 0 if this is the first key in the buffer, else 1.
66    valp points to first char after key. */
67 int class_match_param(char *buf, char *key, char **valp)
68 {
69         if (!buf) 
70                 return 1;
71
72         if (memcmp(buf, key, strlen(key)) != 0) 
73                 return 1;
74
75         if (valp) 
76                 *valp = buf + strlen(key);
77         
78         return 0;
79 }
80
81 /* 0 is good nid, 
82    1 not found
83    < 0 error
84    endh is set to next separator */
85 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh)
86 {
87         char tmp, *endp;
88
89         if (!buf) 
90                 return 1;
91         while (*buf == ',' || *buf == ':') 
92                 buf++;
93         if (*buf == ' ' || *buf == '/' || *buf == '\0') 
94                 return 1;
95
96         /* nid separators or end of nids */
97         endp = strpbrk(buf, ",: /");
98         if (endp == NULL) 
99                 endp = buf + strlen(buf);
100
101         tmp = *endp;
102         *endp = '\0';
103         *nid = libcfs_str2nid(buf);
104         if (*nid == LNET_NID_ANY) {
105                 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
106                 *endp = tmp;
107                 return -EINVAL;
108         }
109         *endp = tmp;
110
111         if (endh) 
112                 *endh = endp;
113         CDEBUG(D_INFO, "Nid %s\n", libcfs_nid2str(*nid));
114         return 0;
115 }
116
117 EXPORT_SYMBOL(class_find_param);
118 EXPORT_SYMBOL(class_match_param);
119 EXPORT_SYMBOL(class_parse_nid);
120
121 /********************** class fns **********************/
122
123 /* Create a new device and set the type, name and uuid.  If
124  * successful, the new device can be accessed by either name or uuid.
125  */
126 int class_attach(struct lustre_cfg *lcfg)
127 {
128         struct obd_device *obd = NULL;
129         char *typename, *name, *uuid;
130         int rc, len;
131         ENTRY;
132
133         if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
134                 CERROR("No type passed!\n");
135                 RETURN(-EINVAL);
136         }
137         typename = lustre_cfg_string(lcfg, 1);
138
139         if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
140                 CERROR("No name passed!\n");
141                 RETURN(-EINVAL);
142         }
143         name = lustre_cfg_string(lcfg, 0);
144
145         if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
146                 CERROR("No UUID passed!\n");
147                 RETURN(-EINVAL);
148         }
149         uuid = lustre_cfg_string(lcfg, 2);
150
151         CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
152                MKSTR(typename), MKSTR(name), MKSTR(uuid));
153
154         obd = class_newdev(typename, name);
155         if (IS_ERR(obd)) {
156                 /* Already exists or out of obds */
157                 rc = PTR_ERR(obd);
158                 obd = NULL;
159                 CERROR("Cannot create device %s of type %s : %d\n",
160                        name, typename, rc);
161                 GOTO(out, rc);
162         }
163         LASSERTF(obd != NULL, "Cannot get obd device %s of type %s\n",
164                  name, typename);
165         LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC, 
166                  "obd %p obd_magic %08X != %08X\n",
167                  obd, obd->obd_magic, OBD_DEVICE_MAGIC);
168         LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0, "%p obd_name %s != %s\n",
169                  obd, obd->obd_name, name);
170
171         CFS_INIT_LIST_HEAD(&obd->obd_exports);
172         CFS_INIT_LIST_HEAD(&obd->obd_exports_timed);
173         spin_lock_init(&obd->obd_dev_lock);
174         sema_init(&obd->obd_dev_sem, 1);
175         sema_init(&obd->obd_proc_exp_sem, 1);
176         spin_lock_init(&obd->obd_osfs_lock);
177         /* obd->obd_osfs_age must be set to a value in the distant
178          * past to guarantee a fresh statfs is fetched on mount. */
179         obd->obd_osfs_age = cfs_time_shift_64(-1000);
180
181         /* XXX belongs in setup not attach  */
182         /* recovery data */
183         cfs_init_timer(&obd->obd_recovery_timer);
184         spin_lock_init(&obd->obd_processing_task_lock);
185         cfs_waitq_init(&obd->obd_next_transno_waitq);
186         cfs_waitq_init(&obd->obd_evict_inprogress_waitq);
187         CFS_INIT_LIST_HEAD(&obd->obd_req_replay_queue);
188         CFS_INIT_LIST_HEAD(&obd->obd_lock_replay_queue);
189         CFS_INIT_LIST_HEAD(&obd->obd_final_req_queue);
190
191         spin_lock_init(&obd->obd_uncommitted_replies_lock);
192         CFS_INIT_LIST_HEAD(&obd->obd_uncommitted_replies);
193
194         len = strlen(uuid);
195         if (len >= sizeof(obd->obd_uuid)) {
196                 CERROR("uuid must be < "LPSZ" bytes long\n",
197                        sizeof(obd->obd_uuid));
198                 GOTO(out, rc = -EINVAL);
199         }
200         memcpy(obd->obd_uuid.uuid, uuid, len);
201
202         /* do the attach */
203         if (OBP(obd, attach)) {
204                 rc = OBP(obd,attach)(obd, sizeof *lcfg, lcfg);
205                 if (rc)
206                         GOTO(out, rc = -EINVAL);
207         }
208
209         /* Detach drops this */
210         spin_lock(&obd->obd_dev_lock);
211         atomic_set(&obd->obd_refcount, 1);
212         spin_unlock(&obd->obd_dev_lock);
213
214         obd->obd_attached = 1;
215         CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
216                obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
217         RETURN(0);
218  out:
219         if (obd != NULL) {
220                 class_release_dev(obd);
221         }
222         return rc;
223 }
224
225 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
226 {
227         int err = 0;
228         struct obd_export *exp;
229         ENTRY;
230
231         LASSERT(obd != NULL);
232         LASSERTF(obd == class_num2obd(obd->obd_minor), "obd %p != obd_devs[%d] %p\n", 
233                  obd, obd->obd_minor, class_num2obd(obd->obd_minor));
234         LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC, "obd %p obd_magic %08x != %08x\n", 
235                  obd, obd->obd_magic, OBD_DEVICE_MAGIC);
236
237         /* have we attached a type to this device? */
238         if (!obd->obd_attached) {
239                 CERROR("Device %d not attached\n", obd->obd_minor);
240                 RETURN(-ENODEV);
241         }
242
243         if (obd->obd_set_up) {
244                 CERROR("Device %d already setup (type %s)\n",
245                        obd->obd_minor, obd->obd_type->typ_name);
246                 RETURN(-EEXIST);
247         }
248
249         /* is someone else setting us up right now? (attach inits spinlock) */
250         spin_lock(&obd->obd_dev_lock);
251         if (obd->obd_starting) {
252                 spin_unlock(&obd->obd_dev_lock);
253                 CERROR("Device %d setup in progress (type %s)\n",
254                        obd->obd_minor, obd->obd_type->typ_name);
255                 RETURN(-EEXIST);
256         }
257         /* just leave this on forever.  I can't use obd_set_up here because
258            other fns check that status, and we're not actually set up yet. */
259         obd->obd_starting = 1;
260         spin_unlock(&obd->obd_dev_lock);
261
262         /* create an uuid-export hash body */
263         err = lustre_hash_init(&obd->obd_uuid_hash_body, "UUID_HASH", 
264                                128, &uuid_hash_operations);
265         if (err) {
266                 GOTO(err_hash, err);
267         }
268
269         /* create a nid-export hash body */
270         err = lustre_hash_init(&obd->obd_nid_hash_body, "NID_HASH", 
271                                128, &nid_hash_operations);
272         if (err)
273                 GOTO(err_hash, err);
274
275         exp = class_new_export(obd, &obd->obd_uuid);
276         if (IS_ERR(exp))
277                 RETURN(PTR_ERR(exp));
278         obd->obd_self_export = exp;
279         list_del_init(&exp->exp_obd_chain_timed);
280         class_export_put(exp);
281
282         err = obd_setup(obd, lcfg);
283         if (err)
284                 GOTO(err_exp, err);
285
286         obd->obd_set_up = 1;
287         
288         spin_lock(&obd->obd_dev_lock);
289         /* cleanup drops this */
290         class_incref(obd);
291         spin_unlock(&obd->obd_dev_lock);
292
293         CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
294                obd->obd_name, obd->obd_uuid.uuid);
295
296         RETURN(0);
297
298 err_exp:
299         class_unlink_export(obd->obd_self_export);
300         obd->obd_self_export = NULL;
301 err_hash:
302         lustre_hash_exit(&obd->obd_uuid_hash_body);
303         lustre_hash_exit(&obd->obd_nid_hash_body);
304         obd->obd_starting = 0;
305         CERROR("setup %s failed (%d)\n", obd->obd_name, err);
306         RETURN(err);
307 }
308
309 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
310 {
311         ENTRY;
312
313         if (obd->obd_set_up) {
314                 CERROR("OBD device %d still set up\n", obd->obd_minor);
315                 RETURN(-EBUSY);
316         }
317
318         spin_lock(&obd->obd_dev_lock);
319         if (!obd->obd_attached) {
320                 spin_unlock(&obd->obd_dev_lock);
321                 CERROR("OBD device %d not attached\n", obd->obd_minor);
322                 RETURN(-ENODEV);
323         }
324         obd->obd_attached = 0;
325         spin_unlock(&obd->obd_dev_lock);
326
327         CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
328                obd->obd_name, obd->obd_uuid.uuid);
329
330         class_decref(obd);
331         
332         /* not strictly necessary, but cleans up eagerly */
333         obd_zombie_impexp_cull();
334         
335         RETURN(0);
336 }
337
338 static void dump_exports(struct obd_device *obd)
339 {
340         struct obd_export *exp, *n;
341
342         list_for_each_entry_safe(exp, n, &obd->obd_exports, exp_obd_chain) {
343                 struct ptlrpc_reply_state *rs;
344                 struct ptlrpc_reply_state *first_reply = NULL;
345                 int                        nreplies = 0;
346
347                 list_for_each_entry (rs, &exp->exp_outstanding_replies,
348                                      rs_exp_list) {
349                         if (nreplies == 0)
350                                 first_reply = rs;
351                         nreplies++;
352                 }
353
354                 CDEBUG(D_IOCTL, "%s: %p %s %s %d %d %d: %p %s\n",
355                        obd->obd_name, exp, exp->exp_client_uuid.uuid,
356                        obd_export_nid2str(exp),
357                        atomic_read(&exp->exp_refcount),
358                        exp->exp_failed, nreplies, first_reply,
359                        nreplies > 3 ? "..." : "");
360         }
361 }
362
363 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
364 {
365         int err = 0;
366         char *flag;
367         ENTRY;
368
369         OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
370
371         if (!obd->obd_set_up) {
372                 CERROR("Device %d not setup\n", obd->obd_minor);
373                 RETURN(-ENODEV);
374         }
375
376         spin_lock(&obd->obd_dev_lock);
377         if (obd->obd_stopping) {
378                 spin_unlock(&obd->obd_dev_lock);
379                 CERROR("OBD %d already stopping\n", obd->obd_minor);
380                 RETURN(-ENODEV);
381         }
382         /* Leave this on forever */
383         obd->obd_stopping = 1;
384         spin_unlock(&obd->obd_dev_lock);
385
386         if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
387                 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
388                         switch (*flag) {
389                         case 'F':
390                                 obd->obd_force = 1;
391                                 break;
392                         case 'A':
393                                 LCONSOLE_WARN("Failing over %s\n",
394                                               obd->obd_name);
395                                 obd->obd_fail = 1;
396                                 obd->obd_no_transno = 1;
397                                 obd->obd_no_recov = 1;
398                                 /* Set the obd readonly if we can */
399                                 if (OBP(obd, iocontrol))
400                                         obd_iocontrol(OBD_IOC_SET_READONLY,
401                                                       obd->obd_self_export,
402                                                       0, NULL, NULL);
403                                 break;
404                         default:
405                                 CERROR("unrecognised flag '%c'\n",
406                                        *flag);
407                         }
408         }
409
410         /* The three references that should be remaining are the
411          * obd_self_export and the attach and setup references. */
412         if (atomic_read(&obd->obd_refcount) > 3) {
413 #if 0           /* We should never fail to cleanup with mountconf */ 
414                 if (!(obd->obd_fail || obd->obd_force)) {
415                         CERROR("OBD %s is still busy with %d references\n"
416                                "You should stop active file system users,"
417                                " or use the --force option to cleanup.\n",
418                                obd->obd_name, atomic_read(&obd->obd_refcount));
419                         dump_exports(obd);
420                         /* Allow a failed cleanup to try again. */
421                         obd->obd_stopping = 0;
422                 }
423 #endif
424                 /* refcounf - 3 might be the number of real exports 
425                    (excluding self export). But class_incref is called
426                    by other things as well, so don't count on it. */
427                 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",
428                        obd->obd_name, atomic_read(&obd->obd_refcount) - 3);
429                 dump_exports(obd);
430                 class_disconnect_exports(obd);
431         }
432         LASSERT(obd->obd_self_export);
433
434         /* destroy an uuid-export hash body */
435         lustre_hash_exit(&obd->obd_uuid_hash_body);
436
437         /* destroy a nid-export hash body */
438         lustre_hash_exit(&obd->obd_nid_hash_body);
439
440         /* Precleanup stage 1, we must make sure all exports (other than the
441            self-export) get destroyed. */
442         err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);
443         if (err)
444                 CERROR("Precleanup %s returned %d\n",
445                        obd->obd_name, err);
446
447         class_decref(obd);
448         obd->obd_set_up = 0;
449         RETURN(0);
450 }
451
452 struct obd_device *class_incref(struct obd_device *obd)
453 {
454         atomic_inc(&obd->obd_refcount);
455         CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
456                atomic_read(&obd->obd_refcount));
457
458         return obd;
459 }
460
461 void class_decref(struct obd_device *obd)
462 {
463         int err;
464         int refs;
465
466         spin_lock(&obd->obd_dev_lock);
467         atomic_dec(&obd->obd_refcount);
468         refs = atomic_read(&obd->obd_refcount);
469         spin_unlock(&obd->obd_dev_lock);
470
471         CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
472
473         if ((refs == 1) && obd->obd_stopping) {
474                 /* All exports (other than the self-export) have been
475                    destroyed; there should be no more in-progress ops
476                    by this point.*/
477                 /* if we're not stopping, we didn't finish setup */
478                 /* Precleanup stage 2,  do other type-specific
479                    cleanup requiring the self-export. */
480                 err = obd_precleanup(obd, OBD_CLEANUP_SELF_EXP);
481                 if (err)
482                         CERROR("Precleanup %s returned %d\n",
483                                obd->obd_name, err);
484                 
485                 spin_lock(&obd->obd_self_export->exp_lock);
486                 obd->obd_self_export->exp_flags |=
487                         (obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
488                         (obd->obd_force ? OBD_OPT_FORCE : 0);
489                 spin_unlock(&obd->obd_self_export->exp_lock);
490
491                 /* note that we'll recurse into class_decref again */
492                 class_unlink_export(obd->obd_self_export);
493                 return;
494         }
495
496         if (refs == 0) {
497                 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
498                        obd->obd_name, obd->obd_uuid.uuid);
499                 LASSERT(!obd->obd_attached);
500                 if (obd->obd_stopping) {
501                         /* If we're not stopping, we were never set up */
502                         err = obd_cleanup(obd);
503                         if (err)
504                                 CERROR("Cleanup %s returned %d\n",
505                                        obd->obd_name, err);
506                 }
507                 if (OBP(obd, detach)) {
508                         err = OBP(obd,detach)(obd);
509                         if (err)
510                                 CERROR("Detach returned %d\n", err);
511                 }
512                 class_release_dev(obd);
513         }
514 }
515
516 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
517 {
518         struct obd_import *imp;
519         struct obd_uuid uuid;
520         int rc;
521         ENTRY;
522
523         if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
524             LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
525                 CERROR("invalid conn_uuid\n");
526                 RETURN(-EINVAL);
527         }
528         if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
529             strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
530             strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
531                 CERROR("can't add connection on non-client dev\n");
532                 RETURN(-EINVAL);
533         }
534
535         imp = obd->u.cli.cl_import;
536         if (!imp) {
537                 CERROR("try to add conn on immature client dev\n");
538                 RETURN(-EINVAL);
539         }
540
541         obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
542         rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
543
544         RETURN(rc);
545 }
546
547 int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
548 {
549         struct obd_import *imp;
550         struct obd_uuid uuid;
551         int rc;
552         ENTRY;
553
554         if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
555             LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
556                 CERROR("invalid conn_uuid\n");
557                 RETURN(-EINVAL);
558         }
559         if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
560             strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
561                 CERROR("can't del connection on non-client dev\n");
562                 RETURN(-EINVAL);
563         }
564
565         imp = obd->u.cli.cl_import;
566         if (!imp) {
567                 CERROR("try to del conn on immature client dev\n");
568                 RETURN(-EINVAL);
569         }
570
571         obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
572         rc = obd_del_conn(imp, &uuid);
573
574         RETURN(rc);
575 }
576
577 int class_sec_flavor(struct obd_device *obd, struct lustre_cfg *lcfg)
578 {
579         struct sec_flavor_config *conf;
580         ENTRY;
581
582         if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
583             strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
584                 CERROR("Can't set security flavor on obd %s\n",
585                        obd->obd_type->typ_name);
586                 RETURN(-EINVAL);
587         }
588
589         if (LUSTRE_CFG_BUFLEN(lcfg, 1) != sizeof(*conf)) {
590                 CERROR("invalid data\n");
591                 RETURN(-EINVAL);
592         }
593
594         conf = &obd->u.cli.cl_sec_conf;
595         memcpy(conf, lustre_cfg_buf(lcfg, 1), sizeof(*conf));
596
597 #ifdef __BIG_ENDIAN
598         __swab32s(&conf->sfc_rpc_flavor);
599         __swab32s(&conf->sfc_bulk_csum);
600         __swab32s(&conf->sfc_bulk_priv);
601         __swab32s(&conf->sfc_flags);
602 #endif
603
604         RETURN(0);
605 }
606
607 CFS_LIST_HEAD(lustre_profile_list);
608
609 struct lustre_profile *class_get_profile(const char * prof)
610 {
611         struct lustre_profile *lprof;
612
613         ENTRY;
614         list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
615                 if (!strcmp(lprof->lp_profile, prof)) {
616                         RETURN(lprof);
617                 }
618         }
619         RETURN(NULL);
620 }
621
622 int class_add_profile(int proflen, char *prof, int osclen, char *osc,
623                       int mdclen, char *mdc)
624 {
625         struct lustre_profile *lprof;
626         int err = 0;
627         ENTRY;
628
629         CDEBUG(D_CONFIG, "Add profile %s\n", prof);
630
631         OBD_ALLOC(lprof, sizeof(*lprof));
632         if (lprof == NULL)
633                 RETURN(-ENOMEM);
634         CFS_INIT_LIST_HEAD(&lprof->lp_list);
635
636         LASSERT(proflen == (strlen(prof) + 1));
637         OBD_ALLOC(lprof->lp_profile, proflen);
638         if (lprof->lp_profile == NULL)
639                 GOTO(out, err = -ENOMEM);
640         memcpy(lprof->lp_profile, prof, proflen);
641
642         LASSERT(osclen == (strlen(osc) + 1));
643         OBD_ALLOC(lprof->lp_dt, osclen);
644         if (lprof->lp_dt == NULL)
645                 GOTO(out, err = -ENOMEM);
646         memcpy(lprof->lp_dt, osc, osclen);
647
648         if (mdclen > 0) {
649                 LASSERT(mdclen == (strlen(mdc) + 1));
650                 OBD_ALLOC(lprof->lp_md, mdclen);
651                 if (lprof->lp_md == NULL)
652                         GOTO(out, err = -ENOMEM);
653                 memcpy(lprof->lp_md, mdc, mdclen);
654         }
655
656         list_add(&lprof->lp_list, &lustre_profile_list);
657         RETURN(err);
658
659 out:
660         if (lprof->lp_md)
661                 OBD_FREE(lprof->lp_md, mdclen);
662         if (lprof->lp_dt)
663                 OBD_FREE(lprof->lp_dt, osclen);
664         if (lprof->lp_profile)
665                 OBD_FREE(lprof->lp_profile, proflen);
666         OBD_FREE(lprof, sizeof(*lprof));        
667         RETURN(err);
668 }
669
670 void class_del_profile(const char *prof)
671 {
672         struct lustre_profile *lprof;
673         ENTRY;
674
675         CDEBUG(D_CONFIG, "Del profile %s\n", prof);
676
677         lprof = class_get_profile(prof);
678         if (lprof) {
679                 list_del(&lprof->lp_list);
680                 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
681                 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
682                 if (lprof->lp_md)
683                         OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
684                 OBD_FREE(lprof, sizeof *lprof);
685         }
686         EXIT;
687 }
688
689 /* COMPAT_146 */
690 void class_del_profiles(void)
691 {
692         struct lustre_profile *lprof, *n;
693         ENTRY;
694
695         list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
696                 list_del(&lprof->lp_list);
697                 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
698                 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
699                 if (lprof->lp_md)
700                         OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
701                 OBD_FREE(lprof, sizeof *lprof);
702         }
703         EXIT;
704 }
705
706 /* We can't call ll_process_config directly because it lives in a module that
707    must be loaded after this one. */
708 static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
709
710 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
711 {
712         client_process_config = cpc;
713 }
714 EXPORT_SYMBOL(lustre_register_client_process_config);
715
716 int class_process_config(struct lustre_cfg *lcfg)
717 {
718         struct obd_device *obd;
719         int err;
720
721         LASSERT(lcfg && !IS_ERR(lcfg));
722         CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
723
724         /* Commands that don't need a device */
725         switch(lcfg->lcfg_command) {
726         case LCFG_ATTACH: {
727                 err = class_attach(lcfg);
728                 GOTO(out, err);
729         }
730         case LCFG_ADD_UUID: {
731                 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64
732                        " (%s)\n", lustre_cfg_string(lcfg, 1),
733                        lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));
734
735                 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
736                 GOTO(out, err);
737         }
738         case LCFG_DEL_UUID: {
739                 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
740                        (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
741                        ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
742
743                 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
744                 GOTO(out, err);
745         }
746         case LCFG_MOUNTOPT: {
747                 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
748                        lustre_cfg_string(lcfg, 1),
749                        lustre_cfg_string(lcfg, 2),
750                        lustre_cfg_string(lcfg, 3));
751                 /* set these mount options somewhere, so ll_fill_super
752                  * can find them. */
753                 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
754                                         lustre_cfg_string(lcfg, 1),
755                                         LUSTRE_CFG_BUFLEN(lcfg, 2),
756                                         lustre_cfg_string(lcfg, 2),
757                                         LUSTRE_CFG_BUFLEN(lcfg, 3),
758                                         lustre_cfg_string(lcfg, 3));
759                 GOTO(out, err);
760         }
761         case LCFG_DEL_MOUNTOPT: {
762                 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
763                        lustre_cfg_string(lcfg, 1));
764                 class_del_profile(lustre_cfg_string(lcfg, 1));
765                 GOTO(out, err = 0);
766         }
767         case LCFG_SET_TIMEOUT: {
768                 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
769                        obd_timeout, lcfg->lcfg_num);
770                 obd_timeout = max(lcfg->lcfg_num, 1U);
771                 obd_health_check_timeout = HEALTH_CHECK_TIMEOUT;
772                 GOTO(out, err = 0);
773         }
774         case LCFG_SET_UPCALL: {
775                 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
776                 /* COMPAT_146 Don't fail on old configs */
777                 GOTO(out, err = 0);
778         }
779         case LCFG_MARKER: {
780                 struct cfg_marker *marker;
781                 marker = lustre_cfg_buf(lcfg, 1);
782                 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
783                        marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
784                 GOTO(out, err = 0);
785         }
786         case LCFG_PARAM: {
787                 /* llite has no obd */
788                 if ((class_match_param(lustre_cfg_string(lcfg, 1), 
789                                        PARAM_LLITE, 0) == 0) &&
790                     client_process_config) {
791                         err = (*client_process_config)(lcfg);
792                         GOTO(out, err);
793                 }
794                 /* Fall through */
795                 break;
796         }
797         }
798
799         /* Commands that require a device */
800         obd = class_name2obd(lustre_cfg_string(lcfg, 0));
801         if (obd == NULL) {
802                 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
803                         CERROR("this lcfg command requires a device name\n");
804                 else
805                         CERROR("no device for: %s\n",
806                                lustre_cfg_string(lcfg, 0));
807
808                 GOTO(out, err = -EINVAL);
809         }
810
811         switch(lcfg->lcfg_command) {
812         case LCFG_SETUP: {
813                 err = class_setup(obd, lcfg);
814                 GOTO(out, err);
815         }
816         case LCFG_DETACH: {
817                 err = class_detach(obd, lcfg);
818                 GOTO(out, err = 0);
819         }
820         case LCFG_CLEANUP: {
821                 err = class_cleanup(obd, lcfg);
822                 GOTO(out, err = 0);
823         }
824         case LCFG_ADD_CONN: {
825                 err = class_add_conn(obd, lcfg);
826                 GOTO(out, err = 0);
827         }
828         case LCFG_DEL_CONN: {
829                 err = class_del_conn(obd, lcfg);
830                 GOTO(out, err = 0);
831         }
832         case LCFG_SEC_FLAVOR: {
833                 err = class_sec_flavor(obd, lcfg);
834                 GOTO(out, err = 0);
835         }
836         default: {
837                 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
838                 GOTO(out, err);
839
840         }
841         }
842 out:
843         if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
844                 CWARN("Ignoring error %d on optional command %#x\n", err, 
845                       lcfg->lcfg_command);
846                 err = 0;
847         }
848         return err;
849 }
850
851 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, 
852                              struct lustre_cfg *lcfg, void *data)
853 {
854 #ifdef __KERNEL__
855         struct lprocfs_vars *var;
856         char *key, *sval;
857         int i, keylen, vallen;
858         int matched = 0, j = 0;
859         int rc = 0;
860         ENTRY;
861
862         if (lcfg->lcfg_command != LCFG_PARAM) {
863                 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
864                 RETURN(-EINVAL);
865         }
866
867         /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
868            or   lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
869            or   lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
870         for (i = 1; i < lcfg->lcfg_bufcount; i++) {
871                 key = lustre_cfg_buf(lcfg, i);
872                 /* Strip off prefix */
873                 class_match_param(key, prefix, &key);
874                 sval = strchr(key, '=');
875                 if (!sval || (*(sval + 1) == 0)) {
876                         CERROR("Can't parse param %s\n", key);
877                         rc = -EINVAL;
878                         /* continue parsing other params */
879                         continue;
880                 }
881                 keylen = sval - key;
882                 sval++;
883                 vallen = strlen(sval);
884                 matched = 0;
885                 j = 0;
886                 /* Search proc entries */
887                 while (lvars[j].name) {
888                         var = &lvars[j];
889                         if (class_match_param(key, (char *)var->name, 0) == 0 &&
890                             keylen == strlen(var->name)) {
891                                 matched++;
892                                 rc = -EROFS;
893                                 if (var->write_fptr) {
894                                         mm_segment_t oldfs;
895                                         oldfs = get_fs();
896                                         set_fs(KERNEL_DS);
897                                         rc = (var->write_fptr)(NULL, sval,
898                                                                vallen, data);
899                                         set_fs(oldfs);
900                                 }
901                                 if (rc < 0) 
902                                         CERROR("writing proc entry %s err %d\n", 
903                                                var->name, rc);
904                                 break;
905                         }
906                         j++;
907                 }    
908                 if (!matched) {
909                         CERROR("%s: unknown param %s\n",
910                                (char *)lustre_cfg_string(lcfg, 0), key);
911                         rc = -EINVAL;
912                         /* continue parsing other params */
913                 } else {
914                         LCONSOLE_INFO("%s.%.*s: set parameter %.*s=%s\n", 
915                                       (char *)lustre_cfg_string(lcfg, 0),
916                                       (int)strlen(prefix) - 1, prefix,
917                                       (int)(sval - key - 1), key, sval);
918                 }
919         }
920         
921         if (rc > 0) 
922                 rc = 0;
923         RETURN(rc);
924 #else
925         CDEBUG(D_CONFIG, "liblustre can't process params.\n");
926         /* Don't throw config error */
927         RETURN(0);
928 #endif
929 }
930
931 int class_config_dump_handler(struct llog_handle * handle,
932                               struct llog_rec_hdr *rec, void *data);
933
934 #ifdef __KERNEL__
935 extern int lustre_check_exclusion(struct super_block *sb, char *svname);
936 #else
937 #define lustre_check_exclusion(a,b)  0
938 #endif
939
940 static int class_config_llog_handler(struct llog_handle * handle,
941                                      struct llog_rec_hdr *rec, void *data)
942 {
943         struct config_llog_instance *clli = data;
944         int cfg_len = rec->lrh_len;
945         char *cfg_buf = (char*) (rec + 1);
946         int rc = 0;
947         ENTRY;
948
949         //class_config_dump_handler(handle, rec, data);
950
951         switch (rec->lrh_type) {
952         case OBD_CFG_REC: {
953                 struct lustre_cfg *lcfg, *lcfg_new;
954                 struct lustre_cfg_bufs bufs;
955                 char *inst_name = NULL;
956                 int inst_len = 0;
957                 int inst = 0;
958
959                 lcfg = (struct lustre_cfg *)cfg_buf;
960                 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION))
961                         lustre_swab_lustre_cfg(lcfg);
962
963                 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
964                 if (rc)
965                         GOTO(out, rc);
966
967                 /* Figure out config state info */
968                 if (lcfg->lcfg_command == LCFG_MARKER) {
969                         struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
970                         CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
971                                clli->cfg_flags, marker->cm_flags);
972                         if (marker->cm_flags & CM_START) {
973                                 /* all previous flags off */
974                                 clli->cfg_flags = CFG_F_MARKER;
975                                 if (marker->cm_flags & CM_SKIP) { 
976                                         clli->cfg_flags |= CFG_F_SKIP;
977                                         CDEBUG(D_CONFIG, "SKIP #%d\n",
978                                                marker->cm_step);
979                                 } else if ((marker->cm_flags & CM_EXCLUDE) ||
980                                            lustre_check_exclusion(clli->cfg_sb, 
981                                                           marker->cm_tgtname)) {
982                                         clli->cfg_flags |= CFG_F_EXCLUDE;
983                                         CDEBUG(D_CONFIG, "EXCLUDE %d\n",
984                                                marker->cm_step);
985                                 }
986                         } else if (marker->cm_flags & CM_END) {
987                                 clli->cfg_flags = 0;
988                         }
989                 }
990                 /* A config command without a start marker before it is 
991                    illegal (post 146) */
992                 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
993                     !(clli->cfg_flags & CFG_F_MARKER) && 
994                     (lcfg->lcfg_command != LCFG_MARKER)) {
995                         CWARN("Config not inside markers, ignoring! "
996                               "(inst: %s, uuid: %s, flags: %#x)\n",
997                               clli->cfg_instance ? clli->cfg_instance : "<null>",
998                               clli->cfg_uuid.uuid, clli->cfg_flags);
999                         clli->cfg_flags |= CFG_F_SKIP;
1000                 }
1001                 if (clli->cfg_flags & CFG_F_SKIP) {
1002                         CDEBUG(D_CONFIG, "skipping %#x\n",
1003                                clli->cfg_flags);
1004                         rc = 0;
1005                         /* No processing! */
1006                         break;
1007                 }
1008
1009                 if ((clli->cfg_flags & CFG_F_EXCLUDE) && 
1010                     (lcfg->lcfg_command == LCFG_LOV_ADD_OBD))
1011                         /* Add inactive instead */
1012                         lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1013
1014                 lustre_cfg_bufs_init(&bufs, lcfg);
1015
1016                 if (clli && clli->cfg_instance && 
1017                     LUSTRE_CFG_BUFLEN(lcfg, 0) > 0){
1018                         inst = 1;
1019                         inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1020                                 strlen(clli->cfg_instance) + 1;
1021                         OBD_ALLOC(inst_name, inst_len);
1022                         if (inst_name == NULL)
1023                                 GOTO(out, rc = -ENOMEM);
1024                         sprintf(inst_name, "%s-%s",
1025                                 lustre_cfg_string(lcfg, 0),
1026                                 clli->cfg_instance);
1027                         lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1028                         CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1029                                lcfg->lcfg_command, inst_name);
1030                 }
1031
1032                 /* we override the llog's uuid for clients, to insure they
1033                 are unique */
1034                 if (clli && clli->cfg_instance && 
1035                     lcfg->lcfg_command == LCFG_ATTACH) {
1036                         lustre_cfg_bufs_set_string(&bufs, 2,
1037                                                    clli->cfg_uuid.uuid);
1038                 }
1039
1040                 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
1041
1042                 lcfg_new->lcfg_num   = lcfg->lcfg_num;
1043                 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1044
1045                 /* XXX Hack to try to remain binary compatible with
1046                  * pre-newconfig logs */
1047                 if (lcfg->lcfg_nal != 0 &&      /* pre-newconfig log? */
1048                     (lcfg->lcfg_nid >> 32) == 0) {
1049                         __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1050
1051                         lcfg_new->lcfg_nid =
1052                                 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1053                         CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1054                               lcfg->lcfg_nal, addr,
1055                               libcfs_nid2str(lcfg_new->lcfg_nid));
1056                 } else {
1057                         lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1058                 }
1059
1060                 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1061
1062                 rc = class_process_config(lcfg_new);
1063                 lustre_cfg_free(lcfg_new);
1064
1065                 if (inst)
1066                         OBD_FREE(inst_name, inst_len);
1067                 break;
1068         }
1069         default:
1070                 CERROR("Unknown llog record type %#x encountered\n",
1071                        rec->lrh_type);
1072                 break;
1073         }
1074 out:
1075         if (rc) {
1076                 CERROR("Err %d on cfg command:\n", rc);
1077                 class_config_dump_handler(handle, rec, data);
1078         }
1079         RETURN(rc);
1080 }
1081
1082 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
1083                             struct config_llog_instance *cfg)
1084 {
1085         struct llog_process_cat_data cd = {0, 0};
1086         struct llog_handle *llh;
1087         int rc, rc2;
1088         ENTRY;
1089
1090         CDEBUG(D_INFO, "looking up llog %s\n", name);
1091         rc = llog_create(ctxt, &llh, NULL, name);
1092         if (rc)
1093                 RETURN(rc);
1094
1095         rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1096         if (rc)
1097                 GOTO(parse_out, rc);
1098
1099         /* continue processing from where we last stopped to end-of-log */
1100         if (cfg)
1101                 cd.first_idx = cfg->cfg_last_idx;
1102         cd.last_idx = 0;
1103
1104         rc = llog_process(llh, class_config_llog_handler, cfg, &cd);
1105
1106         CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name, 
1107                cd.first_idx + 1, cd.last_idx, rc);
1108
1109         if (cfg)
1110                 cfg->cfg_last_idx = cd.last_idx;
1111
1112 parse_out:
1113         rc2 = llog_close(llh);
1114         if (rc == 0)
1115                 rc = rc2;
1116
1117         RETURN(rc);
1118 }
1119
1120 int class_config_dump_handler(struct llog_handle * handle,
1121                               struct llog_rec_hdr *rec, void *data)
1122 {
1123         int cfg_len = rec->lrh_len;
1124         char *cfg_buf = (char*) (rec + 1);
1125         char *outstr, *ptr, *end;
1126         int rc = 0;
1127         ENTRY;
1128
1129         OBD_ALLOC(outstr, 256);
1130         end = outstr + 256;
1131         ptr = outstr;
1132         if (!outstr) {
1133                 RETURN(-ENOMEM);
1134         }
1135         if (rec->lrh_type == OBD_CFG_REC) {
1136                 struct lustre_cfg *lcfg;
1137                 int i;
1138
1139                 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1140                 if (rc)
1141                         GOTO(out, rc);
1142                 lcfg = (struct lustre_cfg *)cfg_buf;
1143
1144                 ptr += snprintf(ptr, end-ptr, "cmd=%05x ",
1145                                 lcfg->lcfg_command);
1146                 if (lcfg->lcfg_flags) {
1147                         ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1148                                         lcfg->lcfg_flags);
1149                 }
1150                 if (lcfg->lcfg_num) {
1151                         ptr += snprintf(ptr, end-ptr, "num=%#08x ",
1152                                         lcfg->lcfg_num);
1153                 }
1154                 if (lcfg->lcfg_nid) {
1155                         ptr += snprintf(ptr, end-ptr, "nid=%s("LPX64")\n     ",
1156                                         libcfs_nid2str(lcfg->lcfg_nid),
1157                                         lcfg->lcfg_nid);
1158                 }
1159                 if (lcfg->lcfg_command == LCFG_MARKER) {
1160                         struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1161                         ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1162                                         marker->cm_step, marker->cm_flags,
1163                                         marker->cm_tgtname, marker->cm_comment);
1164                 } else {
1165                         for (i = 0; i <  lcfg->lcfg_bufcount; i++) {
1166                                 ptr += snprintf(ptr, end-ptr, "%d:%s  ", i,
1167                                                 lustre_cfg_string(lcfg, i));
1168                         }
1169                 }
1170                 LCONSOLE(D_WARNING, "   %s\n", outstr);
1171         } else {
1172                 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1173                 rc = -EINVAL;
1174         }
1175 out:
1176         OBD_FREE(outstr, 256);
1177         RETURN(rc);
1178 }
1179
1180 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
1181                            struct config_llog_instance *cfg)
1182 {
1183         struct llog_handle *llh;
1184         int rc, rc2;
1185         ENTRY;
1186
1187         LCONSOLE_INFO("Dumping config log %s\n", name);
1188
1189         rc = llog_create(ctxt, &llh, NULL, name);
1190         if (rc)
1191                 RETURN(rc);
1192
1193         rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1194         if (rc)
1195                 GOTO(parse_out, rc);
1196
1197         rc = llog_process(llh, class_config_dump_handler, cfg, NULL);
1198 parse_out:
1199         rc2 = llog_close(llh);
1200         if (rc == 0)
1201                 rc = rc2;
1202
1203         LCONSOLE_INFO("End config log %s\n", name);
1204         RETURN(rc);
1205
1206 }
1207
1208 /* Cleanup and detach */
1209 int class_manual_cleanup(struct obd_device *obd)
1210 {
1211         struct lustre_cfg *lcfg;
1212         struct lustre_cfg_bufs bufs;
1213         int rc;
1214         char flags[3]="";
1215         ENTRY;
1216
1217         if (!obd) {
1218                 CERROR("empty cleanup\n");
1219                 RETURN(-EALREADY);
1220         }
1221
1222         if (obd->obd_force)
1223                 strcat(flags, "F");
1224         if (obd->obd_fail)
1225                 strcat(flags, "A");
1226
1227         CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1228                obd->obd_name, flags);
1229
1230         lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1231         lustre_cfg_bufs_set_string(&bufs, 1, flags);
1232         lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
1233
1234         rc = class_process_config(lcfg);
1235         if (rc) {
1236                 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1237                 GOTO(out, rc);
1238         }
1239
1240         /* the lcfg is almost the same for both ops */
1241         lcfg->lcfg_command = LCFG_DETACH;
1242         rc = class_process_config(lcfg);
1243         if (rc)
1244                 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1245 out:
1246         lustre_cfg_free(lcfg);
1247         RETURN(rc);
1248 }
1249