Whamcloud - gitweb
0b5ec846f30a64fd0a3fb86717cab89277294b56
[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  
261         /* create an uuid-export hash body */
262         err = lustre_hash_init(&obd->obd_uuid_hash_body, "UUID_HASH", 
263                                128, &uuid_hash_operations);
264         if (err) {
265                 spin_unlock(&obd->obd_dev_lock);
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         spin_unlock(&obd->obd_dev_lock);
273         if (err)
274                 GOTO(err_hash, err);
275
276         exp = class_new_export(obd, &obd->obd_uuid);
277         if (IS_ERR(exp))
278                 RETURN(PTR_ERR(exp));
279         obd->obd_self_export = exp;
280         list_del_init(&exp->exp_obd_chain_timed);
281         class_export_put(exp);
282
283         err = obd_setup(obd, lcfg);
284         if (err)
285                 GOTO(err_exp, err);
286
287         obd->obd_set_up = 1;
288         
289         spin_lock(&obd->obd_dev_lock);
290         /* cleanup drops this */
291         class_incref(obd);
292         spin_unlock(&obd->obd_dev_lock);
293
294         CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
295                obd->obd_name, obd->obd_uuid.uuid);
296
297         RETURN(0);
298
299 err_exp:
300         class_unlink_export(obd->obd_self_export);
301         obd->obd_self_export = NULL;
302 err_hash:
303         lustre_hash_exit(&obd->obd_uuid_hash_body);
304         lustre_hash_exit(&obd->obd_nid_hash_body);
305         obd->obd_starting = 0;
306         CERROR("setup %s failed (%d)\n", obd->obd_name, err);
307         RETURN(err);
308 }
309
310 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
311 {
312         ENTRY;
313
314         if (obd->obd_set_up) {
315                 CERROR("OBD device %d still set up\n", obd->obd_minor);
316                 RETURN(-EBUSY);
317         }
318
319         spin_lock(&obd->obd_dev_lock);
320         if (!obd->obd_attached) {
321                 spin_unlock(&obd->obd_dev_lock);
322                 CERROR("OBD device %d not attached\n", obd->obd_minor);
323                 RETURN(-ENODEV);
324         }
325         obd->obd_attached = 0;
326         spin_unlock(&obd->obd_dev_lock);
327
328         CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
329                obd->obd_name, obd->obd_uuid.uuid);
330
331         class_decref(obd);
332         
333         /* not strictly necessary, but cleans up eagerly */
334         obd_zombie_impexp_cull();
335         
336         RETURN(0);
337 }
338
339 static void dump_exports(struct obd_device *obd)
340 {
341         struct obd_export *exp, *n;
342
343         list_for_each_entry_safe(exp, n, &obd->obd_exports, exp_obd_chain) {
344                 struct ptlrpc_reply_state *rs;
345                 struct ptlrpc_reply_state *first_reply = NULL;
346                 int                        nreplies = 0;
347
348                 list_for_each_entry (rs, &exp->exp_outstanding_replies,
349                                      rs_exp_list) {
350                         if (nreplies == 0)
351                                 first_reply = rs;
352                         nreplies++;
353                 }
354
355                 CDEBUG(D_IOCTL, "%s: %p %s %s %d %d %d: %p %s\n",
356                        obd->obd_name, exp, exp->exp_client_uuid.uuid,
357                        obd_export_nid2str(exp),
358                        atomic_read(&exp->exp_refcount),
359                        exp->exp_failed, nreplies, first_reply,
360                        nreplies > 3 ? "..." : "");
361         }
362 }
363
364 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
365 {
366         int err = 0;
367         char *flag;
368         ENTRY;
369
370         OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
371
372         if (!obd->obd_set_up) {
373                 CERROR("Device %d not setup\n", obd->obd_minor);
374                 RETURN(-ENODEV);
375         }
376
377         spin_lock(&obd->obd_dev_lock);
378         if (obd->obd_stopping) {
379                 spin_unlock(&obd->obd_dev_lock);
380                 CERROR("OBD %d already stopping\n", obd->obd_minor);
381                 RETURN(-ENODEV);
382         }
383         /* Leave this on forever */
384         obd->obd_stopping = 1;
385         spin_unlock(&obd->obd_dev_lock);
386
387         if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
388                 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
389                         switch (*flag) {
390                         case 'F':
391                                 obd->obd_force = 1;
392                                 break;
393                         case 'A':
394                                 LCONSOLE_WARN("Failing over %s\n",
395                                               obd->obd_name);
396                                 obd->obd_fail = 1;
397                                 obd->obd_no_transno = 1;
398                                 obd->obd_no_recov = 1;
399                                 /* Set the obd readonly if we can */
400                                 if (OBP(obd, iocontrol))
401                                         obd_iocontrol(OBD_IOC_SET_READONLY,
402                                                       obd->obd_self_export,
403                                                       0, NULL, NULL);
404                                 break;
405                         default:
406                                 CERROR("unrecognised flag '%c'\n",
407                                        *flag);
408                         }
409         }
410
411         /* The three references that should be remaining are the
412          * obd_self_export and the attach and setup references. */
413         if (atomic_read(&obd->obd_refcount) > 3) {
414 #if 0           /* We should never fail to cleanup with mountconf */ 
415                 if (!(obd->obd_fail || obd->obd_force)) {
416                         CERROR("OBD %s is still busy with %d references\n"
417                                "You should stop active file system users,"
418                                " or use the --force option to cleanup.\n",
419                                obd->obd_name, atomic_read(&obd->obd_refcount));
420                         dump_exports(obd);
421                         /* Allow a failed cleanup to try again. */
422                         obd->obd_stopping = 0;
423                 }
424 #endif
425                 /* refcounf - 3 might be the number of real exports 
426                    (excluding self export). But class_incref is called
427                    by other things as well, so don't count on it. */
428                 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",
429                        obd->obd_name, atomic_read(&obd->obd_refcount) - 3);
430                 dump_exports(obd);
431                 class_disconnect_exports(obd);
432         }
433         LASSERT(obd->obd_self_export);
434
435         /* destroy an uuid-export hash body */
436         lustre_hash_exit(&obd->obd_uuid_hash_body);
437
438         /* destroy a nid-export hash body */
439         lustre_hash_exit(&obd->obd_nid_hash_body);
440
441         /* Precleanup stage 1, we must make sure all exports (other than the
442            self-export) get destroyed. */
443         err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);
444         if (err)
445                 CERROR("Precleanup %s returned %d\n",
446                        obd->obd_name, err);
447
448         class_decref(obd);
449         obd->obd_set_up = 0;
450         RETURN(0);
451 }
452
453 struct obd_device *class_incref(struct obd_device *obd)
454 {
455         atomic_inc(&obd->obd_refcount);
456         CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
457                atomic_read(&obd->obd_refcount));
458
459         return obd;
460 }
461
462 void class_decref(struct obd_device *obd)
463 {
464         int err;
465         int refs;
466
467         spin_lock(&obd->obd_dev_lock);
468         atomic_dec(&obd->obd_refcount);
469         refs = atomic_read(&obd->obd_refcount);
470         spin_unlock(&obd->obd_dev_lock);
471
472         CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
473
474         if ((refs == 1) && obd->obd_stopping) {
475                 /* All exports (other than the self-export) have been
476                    destroyed; there should be no more in-progress ops
477                    by this point.*/
478                 /* if we're not stopping, we didn't finish setup */
479                 /* Precleanup stage 2,  do other type-specific
480                    cleanup requiring the self-export. */
481                 err = obd_precleanup(obd, OBD_CLEANUP_SELF_EXP);
482                 if (err)
483                         CERROR("Precleanup %s returned %d\n",
484                                obd->obd_name, err);
485                 
486                 spin_lock(&obd->obd_self_export->exp_lock);
487                 obd->obd_self_export->exp_flags |=
488                         (obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
489                         (obd->obd_force ? OBD_OPT_FORCE : 0);
490                 spin_unlock(&obd->obd_self_export->exp_lock);
491
492                 /* note that we'll recurse into class_decref again */
493                 class_unlink_export(obd->obd_self_export);
494                 return;
495         }
496
497         if (refs == 0) {
498                 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
499                        obd->obd_name, obd->obd_uuid.uuid);
500                 LASSERT(!obd->obd_attached);
501                 if (obd->obd_stopping) {
502                         /* If we're not stopping, we were never set up */
503                         err = obd_cleanup(obd);
504                         if (err)
505                                 CERROR("Cleanup %s returned %d\n",
506                                        obd->obd_name, err);
507                 }
508                 if (OBP(obd, detach)) {
509                         err = OBP(obd,detach)(obd);
510                         if (err)
511                                 CERROR("Detach returned %d\n", err);
512                 }
513                 class_release_dev(obd);
514         }
515 }
516
517 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
518 {
519         struct obd_import *imp;
520         struct obd_uuid uuid;
521         int rc;
522         ENTRY;
523
524         if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
525             LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
526                 CERROR("invalid conn_uuid\n");
527                 RETURN(-EINVAL);
528         }
529         if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
530             strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
531             strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
532                 CERROR("can't add connection on non-client dev\n");
533                 RETURN(-EINVAL);
534         }
535
536         imp = obd->u.cli.cl_import;
537         if (!imp) {
538                 CERROR("try to add conn on immature client dev\n");
539                 RETURN(-EINVAL);
540         }
541
542         obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
543         rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
544
545         RETURN(rc);
546 }
547
548 int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
549 {
550         struct obd_import *imp;
551         struct obd_uuid uuid;
552         int rc;
553         ENTRY;
554
555         if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
556             LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
557                 CERROR("invalid conn_uuid\n");
558                 RETURN(-EINVAL);
559         }
560         if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
561             strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
562                 CERROR("can't del connection on non-client dev\n");
563                 RETURN(-EINVAL);
564         }
565
566         imp = obd->u.cli.cl_import;
567         if (!imp) {
568                 CERROR("try to del conn on immature client dev\n");
569                 RETURN(-EINVAL);
570         }
571
572         obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
573         rc = obd_del_conn(imp, &uuid);
574
575         RETURN(rc);
576 }
577
578 int class_sec_flavor(struct obd_device *obd, struct lustre_cfg *lcfg)
579 {
580         struct sec_flavor_config *conf;
581         ENTRY;
582
583         if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
584             strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
585                 CERROR("Can't set security flavor on obd %s\n",
586                        obd->obd_type->typ_name);
587                 RETURN(-EINVAL);
588         }
589
590         if (LUSTRE_CFG_BUFLEN(lcfg, 1) != sizeof(*conf)) {
591                 CERROR("invalid data\n");
592                 RETURN(-EINVAL);
593         }
594
595         conf = &obd->u.cli.cl_sec_conf;
596         memcpy(conf, lustre_cfg_buf(lcfg, 1), sizeof(*conf));
597
598 #ifdef __BIG_ENDIAN
599         __swab32s(&conf->sfc_rpc_flavor);
600         __swab32s(&conf->sfc_bulk_csum);
601         __swab32s(&conf->sfc_bulk_priv);
602         __swab32s(&conf->sfc_flags);
603 #endif
604
605         RETURN(0);
606 }
607
608 CFS_LIST_HEAD(lustre_profile_list);
609
610 struct lustre_profile *class_get_profile(const char * prof)
611 {
612         struct lustre_profile *lprof;
613
614         ENTRY;
615         list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
616                 if (!strcmp(lprof->lp_profile, prof)) {
617                         RETURN(lprof);
618                 }
619         }
620         RETURN(NULL);
621 }
622
623 int class_add_profile(int proflen, char *prof, int osclen, char *osc,
624                       int mdclen, char *mdc)
625 {
626         struct lustre_profile *lprof;
627         int err = 0;
628         ENTRY;
629
630         CDEBUG(D_CONFIG, "Add profile %s\n", prof);
631
632         OBD_ALLOC(lprof, sizeof(*lprof));
633         if (lprof == NULL)
634                 RETURN(-ENOMEM);
635         CFS_INIT_LIST_HEAD(&lprof->lp_list);
636
637         LASSERT(proflen == (strlen(prof) + 1));
638         OBD_ALLOC(lprof->lp_profile, proflen);
639         if (lprof->lp_profile == NULL)
640                 GOTO(out, err = -ENOMEM);
641         memcpy(lprof->lp_profile, prof, proflen);
642
643         LASSERT(osclen == (strlen(osc) + 1));
644         OBD_ALLOC(lprof->lp_dt, osclen);
645         if (lprof->lp_dt == NULL)
646                 GOTO(out, err = -ENOMEM);
647         memcpy(lprof->lp_dt, osc, osclen);
648
649         if (mdclen > 0) {
650                 LASSERT(mdclen == (strlen(mdc) + 1));
651                 OBD_ALLOC(lprof->lp_md, mdclen);
652                 if (lprof->lp_md == NULL)
653                         GOTO(out, err = -ENOMEM);
654                 memcpy(lprof->lp_md, mdc, mdclen);
655         }
656
657         list_add(&lprof->lp_list, &lustre_profile_list);
658         RETURN(err);
659
660 out:
661         if (lprof->lp_md)
662                 OBD_FREE(lprof->lp_md, mdclen);
663         if (lprof->lp_dt)
664                 OBD_FREE(lprof->lp_dt, osclen);
665         if (lprof->lp_profile)
666                 OBD_FREE(lprof->lp_profile, proflen);
667         OBD_FREE(lprof, sizeof(*lprof));        
668         RETURN(err);
669 }
670
671 void class_del_profile(const char *prof)
672 {
673         struct lustre_profile *lprof;
674         ENTRY;
675
676         CDEBUG(D_CONFIG, "Del profile %s\n", prof);
677
678         lprof = class_get_profile(prof);
679         if (lprof) {
680                 list_del(&lprof->lp_list);
681                 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
682                 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
683                 if (lprof->lp_md)
684                         OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
685                 OBD_FREE(lprof, sizeof *lprof);
686         }
687         EXIT;
688 }
689
690 /* COMPAT_146 */
691 void class_del_profiles(void)
692 {
693         struct lustre_profile *lprof, *n;
694         ENTRY;
695
696         list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
697                 list_del(&lprof->lp_list);
698                 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
699                 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
700                 if (lprof->lp_md)
701                         OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
702                 OBD_FREE(lprof, sizeof *lprof);
703         }
704         EXIT;
705 }
706
707 /* We can't call ll_process_config directly because it lives in a module that
708    must be loaded after this one. */
709 static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
710
711 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
712 {
713         client_process_config = cpc;
714 }
715 EXPORT_SYMBOL(lustre_register_client_process_config);
716
717 int class_process_config(struct lustre_cfg *lcfg)
718 {
719         struct obd_device *obd;
720         int err;
721
722         LASSERT(lcfg && !IS_ERR(lcfg));
723         CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
724
725         /* Commands that don't need a device */
726         switch(lcfg->lcfg_command) {
727         case LCFG_ATTACH: {
728                 err = class_attach(lcfg);
729                 GOTO(out, err);
730         }
731         case LCFG_ADD_UUID: {
732                 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64
733                        " (%s)\n", lustre_cfg_string(lcfg, 1),
734                        lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));
735
736                 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
737                 GOTO(out, err);
738         }
739         case LCFG_DEL_UUID: {
740                 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
741                        (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
742                        ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
743
744                 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
745                 GOTO(out, err);
746         }
747         case LCFG_MOUNTOPT: {
748                 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
749                        lustre_cfg_string(lcfg, 1),
750                        lustre_cfg_string(lcfg, 2),
751                        lustre_cfg_string(lcfg, 3));
752                 /* set these mount options somewhere, so ll_fill_super
753                  * can find them. */
754                 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
755                                         lustre_cfg_string(lcfg, 1),
756                                         LUSTRE_CFG_BUFLEN(lcfg, 2),
757                                         lustre_cfg_string(lcfg, 2),
758                                         LUSTRE_CFG_BUFLEN(lcfg, 3),
759                                         lustre_cfg_string(lcfg, 3));
760                 GOTO(out, err);
761         }
762         case LCFG_DEL_MOUNTOPT: {
763                 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
764                        lustre_cfg_string(lcfg, 1));
765                 class_del_profile(lustre_cfg_string(lcfg, 1));
766                 GOTO(out, err = 0);
767         }
768         case LCFG_SET_TIMEOUT: {
769                 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
770                        obd_timeout, lcfg->lcfg_num);
771                 obd_timeout = max(lcfg->lcfg_num, 1U);
772                 obd_health_check_timeout = HEALTH_CHECK_TIMEOUT;
773                 GOTO(out, err = 0);
774         }
775         case LCFG_SET_UPCALL: {
776                 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
777                 /* COMPAT_146 Don't fail on old configs */
778                 GOTO(out, err = 0);
779         }
780         case LCFG_MARKER: {
781                 struct cfg_marker *marker;
782                 marker = lustre_cfg_buf(lcfg, 1);
783                 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
784                        marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
785                 GOTO(out, err = 0);
786         }
787         case LCFG_PARAM: {
788                 /* llite has no obd */
789                 if ((class_match_param(lustre_cfg_string(lcfg, 1), 
790                                        PARAM_LLITE, 0) == 0) &&
791                     client_process_config) {
792                         err = (*client_process_config)(lcfg);
793                         GOTO(out, err);
794                 }
795                 /* Fall through */
796                 break;
797         }
798         }
799
800         /* Commands that require a device */
801         obd = class_name2obd(lustre_cfg_string(lcfg, 0));
802         if (obd == NULL) {
803                 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
804                         CERROR("this lcfg command requires a device name\n");
805                 else
806                         CERROR("no device for: %s\n",
807                                lustre_cfg_string(lcfg, 0));
808
809                 GOTO(out, err = -EINVAL);
810         }
811
812         switch(lcfg->lcfg_command) {
813         case LCFG_SETUP: {
814                 err = class_setup(obd, lcfg);
815                 GOTO(out, err);
816         }
817         case LCFG_DETACH: {
818                 err = class_detach(obd, lcfg);
819                 GOTO(out, err = 0);
820         }
821         case LCFG_CLEANUP: {
822                 err = class_cleanup(obd, lcfg);
823                 GOTO(out, err = 0);
824         }
825         case LCFG_ADD_CONN: {
826                 err = class_add_conn(obd, lcfg);
827                 GOTO(out, err = 0);
828         }
829         case LCFG_DEL_CONN: {
830                 err = class_del_conn(obd, lcfg);
831                 GOTO(out, err = 0);
832         }
833         case LCFG_SEC_FLAVOR: {
834                 err = class_sec_flavor(obd, lcfg);
835                 GOTO(out, err = 0);
836         }
837         default: {
838                 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
839                 GOTO(out, err);
840
841         }
842         }
843 out:
844         if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
845                 CWARN("Ignoring error %d on optional command %#x\n", err, 
846                       lcfg->lcfg_command);
847                 err = 0;
848         }
849         return err;
850 }
851
852 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, 
853                              struct lustre_cfg *lcfg, void *data)
854 {
855 #ifdef __KERNEL__
856         struct lprocfs_vars *var;
857         char *key, *sval;
858         int i, keylen, vallen;
859         int matched = 0, j = 0;
860         int rc = 0;
861         ENTRY;
862
863         if (lcfg->lcfg_command != LCFG_PARAM) {
864                 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
865                 RETURN(-EINVAL);
866         }
867
868         /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
869            or   lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
870            or   lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
871         for (i = 1; i < lcfg->lcfg_bufcount; i++) {
872                 key = lustre_cfg_buf(lcfg, i);
873                 /* Strip off prefix */
874                 class_match_param(key, prefix, &key);
875                 sval = strchr(key, '=');
876                 if (!sval || (*(sval + 1) == 0)) {
877                         CERROR("Can't parse param %s\n", key);
878                         rc = -EINVAL;
879                         /* continue parsing other params */
880                         continue;
881                 }
882                 keylen = sval - key;
883                 sval++;
884                 vallen = strlen(sval);
885                 matched = 0;
886                 j = 0;
887                 /* Search proc entries */
888                 while (lvars[j].name) {
889                         var = &lvars[j];
890                         if (class_match_param(key, (char *)var->name, 0) == 0 &&
891                             keylen == strlen(var->name)) {
892                                 matched++;
893                                 rc = -EROFS;
894                                 if (var->write_fptr) {
895                                         mm_segment_t oldfs;
896                                         oldfs = get_fs();
897                                         set_fs(KERNEL_DS);
898                                         rc = (var->write_fptr)(NULL, sval,
899                                                                vallen, data);
900                                         set_fs(oldfs);
901                                 }
902                                 if (rc < 0) 
903                                         CERROR("writing proc entry %s err %d\n", 
904                                                var->name, rc);
905                                 break;
906                         }
907                         j++;
908                 }    
909                 if (!matched) {
910                         CERROR("%s: unknown param %s\n",
911                                (char *)lustre_cfg_string(lcfg, 0), key);
912                         rc = -EINVAL;
913                         /* continue parsing other params */
914                 } else {
915                         LCONSOLE_INFO("%s.%.*s: set parameter %.*s=%s\n", 
916                                       (char *)lustre_cfg_string(lcfg, 0),
917                                       (int)strlen(prefix) - 1, prefix,
918                                       (int)(sval - key - 1), key, sval);
919                 }
920         }
921         
922         if (rc > 0) 
923                 rc = 0;
924         RETURN(rc);
925 #else
926         CDEBUG(D_CONFIG, "liblustre can't process params.\n");
927         /* Don't throw config error */
928         RETURN(0);
929 #endif
930 }
931
932 int class_config_dump_handler(struct llog_handle * handle,
933                               struct llog_rec_hdr *rec, void *data);
934
935 #ifdef __KERNEL__
936 extern int lustre_check_exclusion(struct super_block *sb, char *svname);
937 #else
938 #define lustre_check_exclusion(a,b)  0
939 #endif
940
941 static int class_config_llog_handler(struct llog_handle * handle,
942                                      struct llog_rec_hdr *rec, void *data)
943 {
944         struct config_llog_instance *clli = data;
945         int cfg_len = rec->lrh_len;
946         char *cfg_buf = (char*) (rec + 1);
947         int rc = 0;
948         ENTRY;
949
950         //class_config_dump_handler(handle, rec, data);
951
952         switch (rec->lrh_type) {
953         case OBD_CFG_REC: {
954                 struct lustre_cfg *lcfg, *lcfg_new;
955                 struct lustre_cfg_bufs bufs;
956                 char *inst_name = NULL;
957                 int inst_len = 0;
958                 int inst = 0;
959
960                 lcfg = (struct lustre_cfg *)cfg_buf;
961                 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION))
962                         lustre_swab_lustre_cfg(lcfg);
963
964                 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
965                 if (rc)
966                         GOTO(out, rc);
967
968                 /* Figure out config state info */
969                 if (lcfg->lcfg_command == LCFG_MARKER) {
970                         struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
971                         CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
972                                clli->cfg_flags, marker->cm_flags);
973                         if (marker->cm_flags & CM_START) {
974                                 /* all previous flags off */
975                                 clli->cfg_flags = CFG_F_MARKER;
976                                 if (marker->cm_flags & CM_SKIP) { 
977                                         clli->cfg_flags |= CFG_F_SKIP;
978                                         CDEBUG(D_CONFIG, "SKIP #%d\n",
979                                                marker->cm_step);
980                                 } else if ((marker->cm_flags & CM_EXCLUDE) ||
981                                            lustre_check_exclusion(clli->cfg_sb, 
982                                                           marker->cm_tgtname)) {
983                                         clli->cfg_flags |= CFG_F_EXCLUDE;
984                                         CDEBUG(D_CONFIG, "EXCLUDE %d\n",
985                                                marker->cm_step);
986                                 }
987                         } else if (marker->cm_flags & CM_END) {
988                                 clli->cfg_flags = 0;
989                         }
990                 }
991                 /* A config command without a start marker before it is 
992                    illegal (post 146) */
993                 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
994                     !(clli->cfg_flags & CFG_F_MARKER) && 
995                     (lcfg->lcfg_command != LCFG_MARKER)) {
996                         CWARN("Config not inside markers, ignoring! "
997                               "(inst: %s, uuid: %s, flags: %#x)\n",
998                               clli->cfg_instance ? clli->cfg_instance : "<null>",
999                               clli->cfg_uuid.uuid, clli->cfg_flags);
1000                         clli->cfg_flags |= CFG_F_SKIP;
1001                 }
1002                 if (clli->cfg_flags & CFG_F_SKIP) {
1003                         CDEBUG(D_CONFIG, "skipping %#x\n",
1004                                clli->cfg_flags);
1005                         rc = 0;
1006                         /* No processing! */
1007                         break;
1008                 }
1009
1010                 if ((clli->cfg_flags & CFG_F_EXCLUDE) && 
1011                     (lcfg->lcfg_command == LCFG_LOV_ADD_OBD))
1012                         /* Add inactive instead */
1013                         lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1014
1015                 lustre_cfg_bufs_init(&bufs, lcfg);
1016
1017                 if (clli && clli->cfg_instance && 
1018                     LUSTRE_CFG_BUFLEN(lcfg, 0) > 0){
1019                         inst = 1;
1020                         inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1021                                 strlen(clli->cfg_instance) + 1;
1022                         OBD_ALLOC(inst_name, inst_len);
1023                         if (inst_name == NULL)
1024                                 GOTO(out, rc = -ENOMEM);
1025                         sprintf(inst_name, "%s-%s",
1026                                 lustre_cfg_string(lcfg, 0),
1027                                 clli->cfg_instance);
1028                         lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1029                         CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1030                                lcfg->lcfg_command, inst_name);
1031                 }
1032
1033                 /* we override the llog's uuid for clients, to insure they
1034                 are unique */
1035                 if (clli && clli->cfg_instance && 
1036                     lcfg->lcfg_command == LCFG_ATTACH) {
1037                         lustre_cfg_bufs_set_string(&bufs, 2,
1038                                                    clli->cfg_uuid.uuid);
1039                 }
1040
1041                 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
1042
1043                 lcfg_new->lcfg_num   = lcfg->lcfg_num;
1044                 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1045
1046                 /* XXX Hack to try to remain binary compatible with
1047                  * pre-newconfig logs */
1048                 if (lcfg->lcfg_nal != 0 &&      /* pre-newconfig log? */
1049                     (lcfg->lcfg_nid >> 32) == 0) {
1050                         __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1051
1052                         lcfg_new->lcfg_nid =
1053                                 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1054                         CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1055                               lcfg->lcfg_nal, addr,
1056                               libcfs_nid2str(lcfg_new->lcfg_nid));
1057                 } else {
1058                         lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1059                 }
1060
1061                 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1062
1063                 rc = class_process_config(lcfg_new);
1064                 lustre_cfg_free(lcfg_new);
1065
1066                 if (inst)
1067                         OBD_FREE(inst_name, inst_len);
1068                 break;
1069         }
1070         default:
1071                 CERROR("Unknown llog record type %#x encountered\n",
1072                        rec->lrh_type);
1073                 break;
1074         }
1075 out:
1076         if (rc) {
1077                 CERROR("Err %d on cfg command:\n", rc);
1078                 class_config_dump_handler(handle, rec, data);
1079         }
1080         RETURN(rc);
1081 }
1082
1083 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
1084                             struct config_llog_instance *cfg)
1085 {
1086         struct llog_process_cat_data cd = {0, 0};
1087         struct llog_handle *llh;
1088         int rc, rc2;
1089         ENTRY;
1090
1091         CDEBUG(D_INFO, "looking up llog %s\n", name);
1092         rc = llog_create(ctxt, &llh, NULL, name);
1093         if (rc)
1094                 RETURN(rc);
1095
1096         rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1097         if (rc)
1098                 GOTO(parse_out, rc);
1099
1100         /* continue processing from where we last stopped to end-of-log */
1101         if (cfg)
1102                 cd.first_idx = cfg->cfg_last_idx;
1103         cd.last_idx = 0;
1104
1105         rc = llog_process(llh, class_config_llog_handler, cfg, &cd);
1106
1107         CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name, 
1108                cd.first_idx + 1, cd.last_idx, rc);
1109
1110         if (cfg)
1111                 cfg->cfg_last_idx = cd.last_idx;
1112
1113 parse_out:
1114         rc2 = llog_close(llh);
1115         if (rc == 0)
1116                 rc = rc2;
1117
1118         RETURN(rc);
1119 }
1120
1121 int class_config_dump_handler(struct llog_handle * handle,
1122                               struct llog_rec_hdr *rec, void *data)
1123 {
1124         int cfg_len = rec->lrh_len;
1125         char *cfg_buf = (char*) (rec + 1);
1126         char *outstr, *ptr, *end;
1127         int rc = 0;
1128         ENTRY;
1129
1130         OBD_ALLOC(outstr, 256);
1131         end = outstr + 256;
1132         ptr = outstr;
1133         if (!outstr) {
1134                 RETURN(-ENOMEM);
1135         }
1136         if (rec->lrh_type == OBD_CFG_REC) {
1137                 struct lustre_cfg *lcfg;
1138                 int i;
1139
1140                 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1141                 if (rc)
1142                         GOTO(out, rc);
1143                 lcfg = (struct lustre_cfg *)cfg_buf;
1144
1145                 ptr += snprintf(ptr, end-ptr, "cmd=%05x ",
1146                                 lcfg->lcfg_command);
1147                 if (lcfg->lcfg_flags) {
1148                         ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1149                                         lcfg->lcfg_flags);
1150                 }
1151                 if (lcfg->lcfg_num) {
1152                         ptr += snprintf(ptr, end-ptr, "num=%#08x ",
1153                                         lcfg->lcfg_num);
1154                 }
1155                 if (lcfg->lcfg_nid) {
1156                         ptr += snprintf(ptr, end-ptr, "nid=%s("LPX64")\n     ",
1157                                         libcfs_nid2str(lcfg->lcfg_nid),
1158                                         lcfg->lcfg_nid);
1159                 }
1160                 if (lcfg->lcfg_command == LCFG_MARKER) {
1161                         struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1162                         ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1163                                         marker->cm_step, marker->cm_flags,
1164                                         marker->cm_tgtname, marker->cm_comment);
1165                 } else {
1166                         for (i = 0; i <  lcfg->lcfg_bufcount; i++) {
1167                                 ptr += snprintf(ptr, end-ptr, "%d:%s  ", i,
1168                                                 lustre_cfg_string(lcfg, i));
1169                         }
1170                 }
1171                 LCONSOLE(D_WARNING, "   %s\n", outstr);
1172         } else {
1173                 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1174                 rc = -EINVAL;
1175         }
1176 out:
1177         OBD_FREE(outstr, 256);
1178         RETURN(rc);
1179 }
1180
1181 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
1182                            struct config_llog_instance *cfg)
1183 {
1184         struct llog_handle *llh;
1185         int rc, rc2;
1186         ENTRY;
1187
1188         LCONSOLE_INFO("Dumping config log %s\n", name);
1189
1190         rc = llog_create(ctxt, &llh, NULL, name);
1191         if (rc)
1192                 RETURN(rc);
1193
1194         rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1195         if (rc)
1196                 GOTO(parse_out, rc);
1197
1198         rc = llog_process(llh, class_config_dump_handler, cfg, NULL);
1199 parse_out:
1200         rc2 = llog_close(llh);
1201         if (rc == 0)
1202                 rc = rc2;
1203
1204         LCONSOLE_INFO("End config log %s\n", name);
1205         RETURN(rc);
1206
1207 }
1208
1209 /* Cleanup and detach */
1210 int class_manual_cleanup(struct obd_device *obd)
1211 {
1212         struct lustre_cfg *lcfg;
1213         struct lustre_cfg_bufs bufs;
1214         int rc;
1215         char flags[3]="";
1216         ENTRY;
1217
1218         if (!obd) {
1219                 CERROR("empty cleanup\n");
1220                 RETURN(-EALREADY);
1221         }
1222
1223         if (obd->obd_force)
1224                 strcat(flags, "F");
1225         if (obd->obd_fail)
1226                 strcat(flags, "A");
1227
1228         CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1229                obd->obd_name, flags);
1230
1231         lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1232         lustre_cfg_bufs_set_string(&bufs, 1, flags);
1233         lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
1234
1235         rc = class_process_config(lcfg);
1236         if (rc) {
1237                 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1238                 GOTO(out, rc);
1239         }
1240
1241         /* the lcfg is almost the same for both ops */
1242         lcfg->lcfg_command = LCFG_DETACH;
1243         rc = class_process_config(lcfg);
1244         if (rc)
1245                 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1246 out:
1247         lustre_cfg_free(lcfg);
1248         RETURN(rc);
1249 }
1250