Whamcloud - gitweb
cleanup usage obd_set_info_async, obd_get_info.
[fs/lustre-release.git] / lustre / mgc / mgc_request.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/mgc/mgc_request.c
5  *  Lustre Management Client
6  *
7  *  Copyright (C) 2006 Cluster File Systems, Inc.
8  *   Author: Nathan Rutman <nathan@clusterfs.com>
9  *
10  *   This file is part of Lustre, http://www.lustre.org
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  */
26
27 #ifndef EXPORT_SYMTAB
28 # define EXPORT_SYMTAB
29 #endif
30 #define DEBUG_SUBSYSTEM S_MGC
31 #define D_MGC D_CONFIG /*|D_WARNING*/
32
33 #ifdef __KERNEL__
34 # include <linux/module.h>
35 # include <linux/pagemap.h>
36 # include <linux/miscdevice.h>
37 # include <linux/init.h>
38 #else
39 # include <liblustre.h>
40 #endif
41
42 #include <obd_class.h>
43 #include <lustre_dlm.h>
44 #include <lprocfs_status.h>
45 #include <lustre_log.h>
46 #include <lustre_fsfilt.h>
47 #include <lustre_disk.h>
48 #include "mgc_internal.h"
49
50 static int mgc_name2resid(char *name, int len, struct ldlm_res_id *res_id)
51 {
52         __u64 resname = 0;
53
54         if (len > 8) {
55                 CERROR("name too long: %s\n", name);
56                 return -EINVAL;
57         }
58         if (len <= 0) {
59                 CERROR("missing name: %s\n", name);
60                 return -EINVAL;
61         }
62         memcpy(&resname, name, len);
63
64         memset(res_id, 0, sizeof(*res_id));
65
66         /* Always use the same endianness for the resid */
67         res_id->name[0] = cpu_to_le64(resname);
68         CDEBUG(D_MGC, "log %s to resid "LPX64"/"LPX64" (%.8s)\n", name,
69                res_id->name[0], res_id->name[1], (char *)&res_id->name[0]);
70         return 0;
71 }
72
73 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id)
74 {
75         /* fsname is at most 8 chars long, maybe contain "-".
76          * e.g. "lustre", "CFS-000" */
77         return mgc_name2resid(fsname, strlen(fsname), res_id);
78 }
79 EXPORT_SYMBOL(mgc_fsname2resid);
80
81 int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id)
82 {
83         char *name_end;
84         int len;
85
86         /* logname consists of "fsname-nodetype".
87          * e.g. "lustre-MDT0001", "CFS-000-client" */
88         name_end = strrchr(logname, '-');
89         LASSERT(name_end);
90         len = name_end - logname;
91         return mgc_name2resid(logname, len, res_id);
92 }
93
94 /********************** config llog list **********************/
95 static CFS_LIST_HEAD(config_llog_list);
96 static spinlock_t       config_list_lock = SPIN_LOCK_UNLOCKED;
97
98 /* Take a reference to a config log */
99 static int config_log_get(struct config_llog_data *cld)
100 {
101         ENTRY;
102         if (cld->cld_stopping)
103                 RETURN(1);
104         atomic_inc(&cld->cld_refcount);
105         CDEBUG(D_INFO, "log %s refs %d\n", cld->cld_logname,
106                atomic_read(&cld->cld_refcount));
107         RETURN(0);
108 }
109
110 /* Drop a reference to a config log.  When no longer referenced,
111    we can free the config log data */
112 static void config_log_put(struct config_llog_data *cld)
113 {
114         ENTRY;
115         CDEBUG(D_INFO, "log %s refs %d\n", cld->cld_logname,
116                atomic_read(&cld->cld_refcount));
117         if (atomic_dec_and_test(&cld->cld_refcount)) {
118                 CDEBUG(D_MGC, "dropping config log %s\n", cld->cld_logname);
119                 class_export_put(cld->cld_mgcexp);
120                 spin_lock(&config_list_lock);
121                 list_del(&cld->cld_list_chain);
122                 spin_unlock(&config_list_lock);
123                 OBD_FREE(cld->cld_logname, strlen(cld->cld_logname) + 1);
124                 if (cld->cld_cfg.cfg_instance != NULL)
125                         OBD_FREE(cld->cld_cfg.cfg_instance,
126                                  strlen(cld->cld_cfg.cfg_instance) + 1);
127                 OBD_FREE(cld, sizeof(*cld));
128         }
129         EXIT;
130 }
131
132 /* Find a config log by name */
133 static struct config_llog_data *config_log_find(char *logname,
134                                                 struct config_llog_instance *cfg)
135 {
136         struct list_head *tmp;
137         struct config_llog_data *cld;
138         char *logid = logname;
139         int match_instance = 0;
140         ENTRY;
141
142         if (cfg && cfg->cfg_instance) {
143                 match_instance++;
144                 logid = cfg->cfg_instance;
145         }
146         if (!logid) {
147                 CERROR("No log specified\n");
148                 RETURN(ERR_PTR(-EINVAL));
149         }
150
151         spin_lock(&config_list_lock);
152         list_for_each(tmp, &config_llog_list) {
153                 cld = list_entry(tmp, struct config_llog_data, cld_list_chain);
154                 if (match_instance && cld->cld_cfg.cfg_instance &&
155                     strcmp(logid, cld->cld_cfg.cfg_instance) == 0)
156                         goto out_found;
157                 if (!match_instance &&
158                     strcmp(logid, cld->cld_logname) == 0)
159                         goto out_found;
160         }
161         spin_unlock(&config_list_lock);
162
163         CDEBUG(D_CONFIG, "can't get log %s\n", logid);
164         RETURN(ERR_PTR(-ENOENT));
165 out_found:
166         atomic_inc(&cld->cld_refcount);
167         spin_unlock(&config_list_lock);
168         RETURN(cld);
169 }
170
171 /* Add this log to our list of active logs.
172    We have one active log per "mount" - client instance or servername.
173    Each instance may be at a different point in the log. */
174 static int config_log_add(char *logname, struct config_llog_instance *cfg,
175                           struct super_block *sb)
176 {
177         struct config_llog_data *cld;
178         struct lustre_sb_info *lsi = s2lsi(sb);
179         int rc;
180         ENTRY;
181
182         CDEBUG(D_MGC, "adding config log %s:%s\n", logname, cfg->cfg_instance);
183
184         OBD_ALLOC(cld, sizeof(*cld));
185         if (!cld)
186                 RETURN(-ENOMEM);
187         OBD_ALLOC(cld->cld_logname, strlen(logname) + 1);
188         if (!cld->cld_logname) {
189                 OBD_FREE(cld, sizeof(*cld));
190                 RETURN(-ENOMEM);
191         }
192         strcpy(cld->cld_logname, logname);
193         cld->cld_cfg = *cfg;
194         cld->cld_cfg.cfg_last_idx = 0;
195         cld->cld_cfg.cfg_flags = 0;
196         cld->cld_cfg.cfg_sb = sb;
197         atomic_set(&cld->cld_refcount, 1);
198
199         /* Keep the mgc around until we are done */
200         cld->cld_mgcexp = class_export_get(lsi->lsi_mgc->obd_self_export);
201
202         if (cfg->cfg_instance != NULL) {
203                 OBD_ALLOC(cld->cld_cfg.cfg_instance,
204                           strlen(cfg->cfg_instance) + 1);
205                 strcpy(cld->cld_cfg.cfg_instance, cfg->cfg_instance);
206         }
207         rc = mgc_logname2resid(logname, &cld->cld_resid);
208         spin_lock(&config_list_lock);
209         list_add(&cld->cld_list_chain, &config_llog_list);
210         spin_unlock(&config_list_lock);
211         
212         if (rc) {
213                 config_log_put(cld);
214                 RETURN(rc);
215         }
216
217         RETURN(rc);
218 }
219
220 /* Stop watching for updates on this log. */
221 static int config_log_end(char *logname, struct config_llog_instance *cfg)
222 {
223         struct config_llog_data *cld;
224         int rc = 0;
225         ENTRY;
226
227         cld = config_log_find(logname, cfg);
228         if (IS_ERR(cld))
229                 RETURN(PTR_ERR(cld));
230         /* drop the ref from the find */
231         config_log_put(cld);
232
233         cld->cld_stopping = 1;
234         /* drop the start ref */
235         config_log_put(cld);
236         CDEBUG(D_MGC, "end config log %s (%d)\n", logname ? logname : "client",
237                rc);
238         RETURN(rc);
239 }
240
241 /* reenqueue any lost locks */
242 #define RQ_RUNNING 0x1
243 #define RQ_NOW     0x2
244 #define RQ_LATER   0x4
245 #define RQ_STOP    0x8
246 static int rq_state = 0;
247 static cfs_waitq_t rq_waitq;
248
249 static int mgc_process_log(struct obd_device *mgc, 
250                            struct config_llog_data *cld);
251 static int mgc_requeue_add(struct config_llog_data *cld, int later);
252
253 static int mgc_requeue_thread(void *data)
254 {
255         struct l_wait_info lwi_now, lwi_later;
256         struct config_llog_data *cld, *n;
257         char name[] = "ll_cfg_requeue";
258         int rc = 0;
259         ENTRY;
260
261         ptlrpc_daemonize(name);
262         
263         CDEBUG(D_MGC, "Starting requeue thread\n");
264
265         lwi_later = LWI_TIMEOUT(60 * HZ, NULL, NULL);
266         l_wait_event(rq_waitq, rq_state & (RQ_NOW | RQ_STOP), &lwi_later);
267
268         /* Keep trying failed locks periodically */
269         spin_lock(&config_list_lock);
270         while (rq_state & (RQ_NOW | RQ_LATER)) {
271                 /* Any new or requeued lostlocks will change the state */
272                 rq_state &= ~(RQ_NOW | RQ_LATER); 
273                 spin_unlock(&config_list_lock);
274
275                 /* Always wait a few seconds to allow the server who 
276                    caused the lock revocation to finish its setup, plus some
277                    random so everyone doesn't try to reconnect at once. */
278                 lwi_now = LWI_TIMEOUT(3 * HZ + (ll_rand() & 0xff) * (HZ / 100),
279                                       NULL, NULL);
280                 l_wait_event(rq_waitq, rq_state & RQ_STOP, &lwi_now);
281                 
282                 spin_lock(&config_list_lock);
283                 list_for_each_entry_safe(cld, n, &config_llog_list,
284                                          cld_list_chain) {
285                         spin_unlock(&config_list_lock);                        
286                         if (cld->cld_lostlock) {
287                                 CDEBUG(D_MGC, "updating log %s\n", 
288                                        cld->cld_logname);
289                                 cld->cld_lostlock = 0;
290                                 rc = mgc_process_log(cld->cld_mgcexp->exp_obd,
291                                                      cld);
292                                 /* Whether we enqueued again or not in 
293                                    mgc_process_log, we're done with the ref 
294                                    from the old enqueue */      
295                                 config_log_put(cld);
296                         }
297                         spin_lock(&config_list_lock);
298                 }
299                 spin_unlock(&config_list_lock);
300                 
301                 /* Wait a bit to see if anyone else needs a requeue */
302                 l_wait_event(rq_waitq, rq_state & (RQ_NOW | RQ_STOP),
303                              &lwi_later);
304                 spin_lock(&config_list_lock);
305         }
306         /* spinlock and while guarantee RQ_NOW and RQ_LATER are not set */
307         rq_state &= ~RQ_RUNNING;
308         spin_unlock(&config_list_lock);
309         
310         CDEBUG(D_MGC, "Ending requeue thread\n");
311         RETURN(rc);
312 }
313
314 /* Add a cld to the list to requeue.  Start the requeue thread if needed.
315    We are responsible for dropping the config log reference from here on out. */
316 static int mgc_requeue_add(struct config_llog_data *cld, int later)
317 {
318         int rc = 0;
319
320         CDEBUG(D_INFO, "log %s: requeue (l=%d r=%d sp=%d st=%x)\n", 
321                cld->cld_logname, later, atomic_read(&cld->cld_refcount),
322                cld->cld_stopping, rq_state);
323
324         /* Hold lock for rq_state */
325         spin_lock(&config_list_lock);
326         cld->cld_lostlock = 1;
327
328         if (cld->cld_stopping || (rq_state & RQ_STOP)) {
329                 spin_unlock(&config_list_lock);
330                 config_log_put(cld);
331                 RETURN(0);
332         }
333
334         if (!(rq_state & RQ_RUNNING)) {
335                 LASSERT(rq_state == 0);
336                 rq_state = RQ_RUNNING | (later ? RQ_LATER : RQ_NOW);
337                 spin_unlock(&config_list_lock);
338                 rc = cfs_kernel_thread(mgc_requeue_thread, 0,
339                                        CLONE_VM | CLONE_FILES);
340                 if (rc < 0) {
341                         CERROR("log %s: cannot start requeue thread (%d),"
342                                "no more log updates!\n", cld->cld_logname, rc);
343                         /* Drop the ref, since the rq thread won't */
344                         cld->cld_lostlock = 0;
345                         config_log_put(cld);
346                         rq_state = 0;
347                         RETURN(rc);
348                 }
349         } else {
350                 rq_state |= later ? RQ_LATER : RQ_NOW;
351                 spin_unlock(&config_list_lock);
352                 cfs_waitq_signal(&rq_waitq);
353         }
354
355         RETURN(0);
356 }
357
358 /********************** class fns **********************/
359
360 static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb,
361                         struct vfsmount *mnt)
362 {
363         struct lvfs_run_ctxt saved;
364         struct lustre_sb_info *lsi = s2lsi(sb);
365         struct client_obd *cli = &obd->u.cli;
366         struct dentry *dentry;
367         char *label;
368         int err = 0;
369         ENTRY;
370
371         LASSERT(lsi);
372         LASSERT(lsi->lsi_srv_mnt == mnt);
373
374         /* The mgc fs exclusion sem. Only one fs can be setup at a time. */
375         down(&cli->cl_mgc_sem);
376
377         cleanup_group_info();
378
379         obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
380         if (IS_ERR(obd->obd_fsops)) {
381                 up(&cli->cl_mgc_sem);
382                 CERROR("No fstype %s rc=%ld\n", MT_STR(lsi->lsi_ldd),
383                        PTR_ERR(obd->obd_fsops));
384                 RETURN(PTR_ERR(obd->obd_fsops));
385         }
386
387         cli->cl_mgc_vfsmnt = mnt;
388         fsfilt_setup(obd, mnt->mnt_sb);
389
390         OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
391         obd->obd_lvfs_ctxt.pwdmnt = mnt;
392         obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
393         obd->obd_lvfs_ctxt.fs = get_ds();
394
395         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
396         dentry = lookup_one_len(MOUNT_CONFIGS_DIR, current->fs->pwd,
397                                 strlen(MOUNT_CONFIGS_DIR));
398         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
399         if (IS_ERR(dentry)) {
400                 err = PTR_ERR(dentry);
401                 CERROR("cannot lookup %s directory: rc = %d\n",
402                        MOUNT_CONFIGS_DIR, err);
403                 GOTO(err_ops, err);
404         }
405         cli->cl_mgc_configs_dir = dentry;
406
407         /* We take an obd ref to insure that we can't get to mgc_cleanup
408            without calling mgc_fs_cleanup first. */
409         class_incref(obd);
410
411         label = fsfilt_get_label(obd, mnt->mnt_sb);
412         if (label)
413                 CDEBUG(D_MGC, "MGC using disk labelled=%s\n", label);
414
415         /* We keep the cl_mgc_sem until mgc_fs_cleanup */
416         RETURN(0);
417
418 err_ops:
419         fsfilt_put_ops(obd->obd_fsops);
420         obd->obd_fsops = NULL;
421         cli->cl_mgc_vfsmnt = NULL;
422         up(&cli->cl_mgc_sem);
423         RETURN(err);
424 }
425
426 static int mgc_fs_cleanup(struct obd_device *obd)
427 {
428         struct client_obd *cli = &obd->u.cli;
429         int rc = 0;
430         ENTRY;
431
432         LASSERT(cli->cl_mgc_vfsmnt != NULL);
433
434         if (cli->cl_mgc_configs_dir != NULL) {
435                 struct lvfs_run_ctxt saved;
436                 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
437                 l_dput(cli->cl_mgc_configs_dir);
438                 cli->cl_mgc_configs_dir = NULL;
439                 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
440                 class_decref(obd);
441         }
442
443         cli->cl_mgc_vfsmnt = NULL;
444         if (obd->obd_fsops)
445                 fsfilt_put_ops(obd->obd_fsops);
446
447         up(&cli->cl_mgc_sem);
448
449         RETURN(rc);
450 }
451
452 static atomic_t mgc_count = ATOMIC_INIT(0);
453 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
454 {
455         int rc = 0;
456         ENTRY;
457
458         switch (stage) {
459         case OBD_CLEANUP_EARLY:
460                 break;
461         case OBD_CLEANUP_EXPORTS:
462                 if (atomic_dec_and_test(&mgc_count)) {
463                         /* Kick the requeue waitq - cld's should all be 
464                            stopping */
465                         spin_lock(&config_list_lock);
466                         rq_state |= RQ_STOP;
467                         spin_unlock(&config_list_lock);
468                         cfs_waitq_signal(&rq_waitq);
469                 }
470                 break;
471         case OBD_CLEANUP_SELF_EXP:
472                 rc = obd_llog_finish(obd, 0);
473                 if (rc != 0)
474                         CERROR("failed to cleanup llogging subsystems\n");
475                 break;
476         case OBD_CLEANUP_OBD:
477                 break;
478         }
479         RETURN(rc);
480 }
481
482 static int mgc_cleanup(struct obd_device *obd)
483 {
484         struct client_obd *cli = &obd->u.cli;
485         int rc;
486         ENTRY;
487
488         LASSERT(cli->cl_mgc_vfsmnt == NULL);
489
490         /* COMPAT_146 - old config logs may have added profiles we don't
491            know about */
492         if (obd->obd_type->typ_refcnt <= 1)
493                 /* Only for the last mgc */
494                 class_del_profiles();
495
496         lprocfs_obd_cleanup(obd);
497         ptlrpcd_decref();
498
499         rc = client_obd_cleanup(obd);
500         RETURN(rc);
501 }
502
503 static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
504 {
505         struct lprocfs_static_vars lvars;
506         int rc;
507         ENTRY;
508
509         ptlrpcd_addref();
510
511         rc = client_obd_setup(obd, lcfg);
512         if (rc)
513                 GOTO(err_decref, rc);
514
515         rc = obd_llog_init(obd, OBD_LLOG_GROUP, obd, 0, NULL, NULL);
516         if (rc) {
517                 CERROR("failed to setup llogging subsystems\n");
518                 GOTO(err_cleanup, rc);
519         }
520
521         lprocfs_mgc_init_vars(&lvars);
522         lprocfs_obd_setup(obd, lvars.obd_vars);
523
524         spin_lock(&config_list_lock);
525         atomic_inc(&mgc_count);
526         if (atomic_read(&mgc_count) == 1) {
527                 rq_state &= ~RQ_STOP;
528                 cfs_waitq_init(&rq_waitq);
529         }
530         spin_unlock(&config_list_lock);
531         
532         RETURN(rc);
533
534 err_cleanup:
535         client_obd_cleanup(obd);
536 err_decref:
537         ptlrpcd_decref();
538         RETURN(rc);
539 }
540
541 /* based on ll_mdc_blocking_ast */
542 static int mgc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
543                             void *data, int flag)
544 {
545         struct lustre_handle lockh;
546         struct config_llog_data *cld = (struct config_llog_data *)data;
547         int rc = 0;
548         ENTRY;
549
550         switch (flag) {
551         case LDLM_CB_BLOCKING:
552                 /* mgs wants the lock, give it up... */
553                 LDLM_DEBUG(lock, "MGC blocking CB");
554                 ldlm_lock2handle(lock, &lockh);
555                 rc = ldlm_cli_cancel(&lockh);
556                 break;
557         case LDLM_CB_CANCELING: {
558                 /* We've given up the lock, prepare ourselves to update. */
559                 LDLM_DEBUG(lock, "MGC cancel CB");
560
561                 CDEBUG(D_MGC, "Lock res "LPX64" (%.8s)\n",
562                        lock->l_resource->lr_name.name[0],
563                        (char *)&lock->l_resource->lr_name.name[0]);
564
565                 if (!cld) {
566                         CERROR("missing data, won't requeue\n");
567                         break;
568                 }
569                 /* Are we done with this log? */
570                 if (cld->cld_stopping) {
571                         CDEBUG(D_MGC, "log %s: stopping, won't requeue\n", 
572                                cld->cld_logname);
573                         config_log_put(cld);    
574                         break;
575                 }
576                 /* Make sure not to re-enqueue when the mgc is stopping
577                    (we get called from client_disconnect_export) */
578                 if (!lock->l_conn_export ||
579                     !lock->l_conn_export->exp_obd->u.cli.cl_conn_count) {
580                         CDEBUG(D_MGC, "log %s: disconnecting, won't requeue\n",
581                                cld->cld_logname);
582                         config_log_put(cld);    
583                         break;
584                 }
585                 /* Did we fail to get the lock? */
586                 if (lock->l_req_mode != lock->l_granted_mode) {
587                         CDEBUG(D_MGC, "log %s: original grant failed, will "
588                                "requeue later\n", cld->cld_logname);
589                         /* Try to re-enqueue later */
590                         rc = mgc_requeue_add(cld, 1);
591                         break;
592                 }
593                 /* Re-enqueue now */
594                 rc = mgc_requeue_add(cld, 0);
595                 break;
596         }
597         default:
598                 LBUG();
599         }
600
601
602         if (rc) {
603                 CERROR("%s CB failed %d:\n", flag == LDLM_CB_BLOCKING ?
604                        "blocking" : "cancel", rc);
605                 LDLM_ERROR(lock, "MGC ast");
606         }
607         RETURN(rc);
608 }
609
610 /* Send parameter to MGS*/
611 static int mgc_set_mgs_param(struct obd_export *exp,
612                              struct mgs_send_param *msp)
613 {
614         struct ptlrpc_request *req;
615         struct mgs_send_param *req_msp, *rep_msp;
616         int size[] = { sizeof(struct ptlrpc_body), sizeof(*req_msp) };
617         int rep_size[] = { sizeof(struct ptlrpc_body), sizeof(*msp) };
618         int rc;
619         ENTRY;
620
621         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MGS_VERSION,
622                               MGS_SET_INFO, 2, size, NULL);
623         if (!req)
624                 RETURN(-ENOMEM);
625
626         req_msp = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*req_msp));
627         if (!req_msp)
628                 RETURN(-ENOMEM);
629
630         memcpy(req_msp, msp, sizeof(*req_msp));
631         ptlrpc_req_set_repsize(req, 2, rep_size);
632         rc = ptlrpc_queue_wait(req);
633         if (!rc) {
634                 rep_msp = lustre_swab_repbuf(req, REPLY_REC_OFF,
635                                              sizeof(*rep_msp), NULL);
636                 memcpy(msp, rep_msp, sizeof(*rep_msp));
637         }
638
639         ptlrpc_req_finished(req);
640
641         RETURN(rc);
642 }
643
644 /* Take a config lock so we can get cancel notifications */
645 static int mgc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
646                        __u32 type, ldlm_policy_data_t *policy, __u32 mode,
647                        int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
648                        void *data, __u32 lvb_len, void *lvb_swabber,
649                        struct lustre_handle *lockh)
650 {
651         struct config_llog_data *cld = (struct config_llog_data *)data;
652         struct ldlm_enqueue_info einfo = { type, mode, mgc_blocking_ast,
653                 ldlm_completion_ast, NULL, data};
654
655         int rc;
656         ENTRY;
657
658         CDEBUG(D_MGC, "Enqueue for %s (res "LPX64")\n", cld->cld_logname,
659                cld->cld_resid.name[0]);
660
661         /* We can only drop this config log ref when we drop the lock */
662         if (config_log_get(cld))
663                 RETURN(ELDLM_LOCK_ABORTED);
664
665         /* We need a callback for every lockholder, so don't try to
666            ldlm_lock_match (see rev 1.1.2.11.2.47) */
667
668         rc = ldlm_cli_enqueue(exp, NULL, &einfo, &cld->cld_resid,
669                               NULL, flags, NULL, 0, NULL, lockh, 0);
670         /* A failed enqueue should still call the mgc_blocking_ast, 
671            where it will be requeued if needed ("grant failed"). */ 
672
673         RETURN(rc);
674 }
675
676 static int mgc_cancel(struct obd_export *exp, struct lov_stripe_md *md,
677                       __u32 mode, struct lustre_handle *lockh)
678 {
679         ENTRY;
680
681         ldlm_lock_decref(lockh, mode);
682
683         RETURN(0);
684 }
685
686 #if 0
687 static int mgc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
688                          void *karg, void *uarg)
689 {
690         struct obd_device *obd = exp->exp_obd;
691         struct obd_ioctl_data *data = karg;
692         struct llog_ctxt *ctxt;
693         struct lvfs_run_ctxt saved;
694         int rc;
695         ENTRY;
696
697         if (!try_module_get(THIS_MODULE)) {
698                 CERROR("Can't get module. Is it alive?");
699                 return -EINVAL;
700         }
701         switch (cmd) {
702         /* REPLicator context */
703         case OBD_IOC_PARSE: {
704                 CERROR("MGC parsing llog %s\n", data->ioc_inlbuf1);
705                 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
706                 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
707                 GOTO(out, rc);
708         }
709 #ifdef __KERNEL__
710         case OBD_IOC_LLOG_INFO:
711         case OBD_IOC_LLOG_PRINT: {
712                 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
713                 rc = llog_ioctl(ctxt, cmd, data);
714
715                 GOTO(out, rc);
716         }
717 #endif
718         /* ORIGinator context */
719         case OBD_IOC_DUMP_LOG: {
720                 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
721                 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
722                 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
723                 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
724                 if (rc)
725                         RETURN(rc);
726
727                 GOTO(out, rc);
728         }
729         default:
730                 CERROR("mgc_ioctl(): unrecognised ioctl %#x\n", cmd);
731                 GOTO(out, rc = -ENOTTY);
732         }
733 out:
734         module_put(THIS_MODULE);
735
736         return rc;
737 }
738 #endif
739
740 /* Send target_reg message to MGS */
741 static int mgc_target_register(struct obd_export *exp,
742                                struct mgs_target_info *mti)
743 {
744         struct ptlrpc_request  *req;
745         struct mgs_target_info *req_mti, *rep_mti;
746         int                     rc;
747         ENTRY;
748
749         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
750                                         &RQF_MGS_TARGET_REG, LUSTRE_MGS_VERSION,
751                                         MGS_TARGET_REG);
752         if (req == NULL)
753                 RETURN(-ENOMEM);
754
755         req_mti = req_capsule_client_get(&req->rq_pill, &RMF_MGS_TARGET_INFO);
756         memcpy(req_mti, mti, sizeof(*req_mti));
757
758         ptlrpc_request_set_replen(req);
759
760         CDEBUG(D_MGC, "register %s\n", mti->mti_svname);
761
762         rc = ptlrpc_queue_wait(req);
763         if (!rc) {
764                 rep_mti = req_capsule_server_get(&req->rq_pill,
765                                                  &RMF_MGS_TARGET_INFO);
766                 memcpy(mti, rep_mti, sizeof(*rep_mti));
767                 CDEBUG(D_MGC, "register %s got index = %d\n",
768                        mti->mti_svname, mti->mti_stripe_index);
769         }
770         ptlrpc_req_finished(req);
771
772         RETURN(rc);
773 }
774
775 int mgc_set_info_async(struct obd_export *exp, obd_count keylen,
776                        void *key, obd_count vallen, void *val,
777                        struct ptlrpc_request_set *set)
778 {
779         struct obd_import *imp = class_exp2cliimp(exp);
780         int rc = -EINVAL;
781         ENTRY;
782
783         /* Try to "recover" the initial connection; i.e. retry */
784         if (KEY_IS(KEY_INIT_RECOV)) {
785                 if (vallen != sizeof(int))
786                         RETURN(-EINVAL);
787                 spin_lock(&imp->imp_lock);
788                 imp->imp_initial_recov = *(int *)val;
789                 spin_unlock(&imp->imp_lock);
790                 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
791                        exp->exp_obd->obd_name, imp->imp_initial_recov);
792                 RETURN(0);
793         }
794         /* Turn off initial_recov after we try all backup servers once */
795         if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
796                 int value;
797                 if (vallen != sizeof(int))
798                         RETURN(-EINVAL);
799                 value = *(int *)val;
800                 spin_lock(&imp->imp_lock);
801                 imp->imp_initial_recov_bk = value > 0;
802                 /* Even after the initial connection, give up all comms if
803                    nobody answers the first time. */
804                 imp->imp_recon_bk = 1;
805                 spin_unlock(&imp->imp_lock);
806                 CDEBUG(D_MGC, "InitRecov %s %d/%d:d%d:i%d:r%d:or%d:%s\n",
807                        imp->imp_obd->obd_name, value, imp->imp_initial_recov,
808                        imp->imp_deactive, imp->imp_invalid,
809                        imp->imp_replayable, imp->imp_obd->obd_replayable,
810                        ptlrpc_import_state_name(imp->imp_state));
811                 /* Resurrect if we previously died */
812                 if (imp->imp_invalid || value > 1)
813                         ptlrpc_reconnect_import(imp);
814                 RETURN(0);
815         }
816         /* FIXME move this to mgc_process_config */
817         if (KEY_IS(KEY_REGISTER_TARGET)) {
818                 struct mgs_target_info *mti;
819                 if (vallen != sizeof(struct mgs_target_info))
820                         RETURN(-EINVAL);
821                 mti = (struct mgs_target_info *)val;
822                 CDEBUG(D_MGC, "register_target %s %#x\n",
823                        mti->mti_svname, mti->mti_flags);
824                 rc =  mgc_target_register(exp, mti);
825                 RETURN(rc);
826         }
827         if (KEY_IS(KEY_SET_FS)) {
828                 struct super_block *sb = (struct super_block *)val;
829                 struct lustre_sb_info *lsi;
830                 if (vallen != sizeof(struct super_block))
831                         RETURN(-EINVAL);
832                 lsi = s2lsi(sb);
833                 rc = mgc_fs_setup(exp->exp_obd, sb, lsi->lsi_srv_mnt);
834                 if (rc) {
835                         CERROR("set_fs got %d\n", rc);
836                 }
837                 RETURN(rc);
838         }
839         if (KEY_IS(KEY_CLEAR_FS)) {
840                 if (vallen != 0)
841                         RETURN(-EINVAL);
842                 rc = mgc_fs_cleanup(exp->exp_obd);
843                 if (rc) {
844                         CERROR("clear_fs got %d\n", rc);
845                 }
846                 RETURN(rc);
847         }
848         if (KEY_IS(KEY_SET_INFO)) {
849                 struct mgs_send_param *msp;
850
851                 msp = (struct mgs_send_param *)val;
852                 rc =  mgc_set_mgs_param(exp, msp);
853                 RETURN(rc);
854         }
855
856         RETURN(rc);
857 }
858
859 static int mgc_import_event(struct obd_device *obd,
860                             struct obd_import *imp,
861                             enum obd_import_event event)
862 {
863         int rc = 0;
864
865         LASSERT(imp->imp_obd == obd);
866         CDEBUG(D_MGC, "import event %#x\n", event);
867
868         switch (event) {
869         case IMP_EVENT_DISCON:
870                 /* MGC imports should not wait for recovery */
871                 break;
872         case IMP_EVENT_INACTIVE:
873                 break;
874         case IMP_EVENT_INVALIDATE: {
875                 struct ldlm_namespace *ns = obd->obd_namespace;
876                 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
877                 break;
878         }
879         case IMP_EVENT_ACTIVE:
880                 LCONSOLE_WARN("%s: Reactivating import\n", obd->obd_name);
881                 /* Clearing obd_no_recov allows us to continue pinging */
882                 obd->obd_no_recov = 0;        
883                 break;
884         case IMP_EVENT_OCD:
885                 break;
886         default:
887                 CERROR("Unknown import event %#x\n", event);
888                 LBUG();
889         }
890         RETURN(rc);
891 }
892
893 static int mgc_llog_init(struct obd_device *obd, int group,
894                          struct obd_device *tgt, int count,
895                          struct llog_catid *logid, struct obd_uuid *uuid)
896 {
897         struct llog_ctxt *ctxt;
898         struct obd_llog_group *olg = &obd->obd_olg;
899         int rc;
900         ENTRY;
901
902         LASSERT(group == OBD_LLOG_GROUP);
903         LASSERT(olg->olg_group == group);
904
905         rc = llog_setup(obd, olg, LLOG_CONFIG_ORIG_CTXT, tgt, 0, NULL,
906                         &llog_lvfs_ops);
907         if (rc)
908                 RETURN(rc);
909
910         rc = llog_setup(obd, olg, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
911                         &llog_client_ops);
912         if (rc == 0) {
913                 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
914                 llog_initiator_connect(ctxt);
915                 llog_ctxt_put(ctxt);
916         }
917
918         RETURN(rc);
919 }
920
921 static int mgc_llog_finish(struct obd_device *obd, int count)
922 {
923         struct llog_ctxt *ctxt;
924         int rc = 0, rc2 = 0;
925         ENTRY;
926
927         ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
928         if (ctxt)
929                 rc = llog_cleanup(ctxt);
930
931         ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
932         if (ctxt)
933                 rc2 = llog_cleanup(ctxt);
934
935         if (!rc)
936                 rc = rc2;
937
938         RETURN(rc);
939 }
940
941 /* identical to mgs_log_is_empty */
942 static int mgc_llog_is_empty(struct obd_device *obd, struct llog_ctxt *ctxt,
943                             char *name)
944 {
945         struct lvfs_run_ctxt saved;
946         struct llog_handle *llh;
947         int rc = 0;
948
949         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
950         rc = llog_create(ctxt, &llh, NULL, name);
951         if (rc == 0) {
952                 llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
953                 rc = llog_get_size(llh);
954                 llog_close(llh);
955         }
956         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
957         /* header is record 1 */
958         return(rc <= 1);
959 }
960
961 static int mgc_copy_handler(struct llog_handle *llh, struct llog_rec_hdr *rec,
962                             void *data)
963 {
964         struct llog_rec_hdr local_rec = *rec;
965         struct llog_handle *local_llh = (struct llog_handle *)data;
966         char *cfg_buf = (char*) (rec + 1);
967         struct lustre_cfg *lcfg;
968         int rc = 0;
969         ENTRY;
970
971         /* Append all records */
972         local_rec.lrh_len -= sizeof(*rec) + sizeof(struct llog_rec_tail);
973         rc = llog_write_rec(local_llh, &local_rec, NULL, 0,
974                             (void *)cfg_buf, -1);
975
976         lcfg = (struct lustre_cfg *)cfg_buf;
977         CDEBUG(D_INFO, "idx=%d, rc=%d, len=%d, cmd %x %s %s\n",
978                rec->lrh_index, rc, rec->lrh_len, lcfg->lcfg_command,
979                lustre_cfg_string(lcfg, 0), lustre_cfg_string(lcfg, 1));
980
981         RETURN(rc);
982 }
983
984 /* Copy a remote log locally */
985 static int mgc_copy_llog(struct obd_device *obd, struct llog_ctxt *rctxt,
986                          struct llog_ctxt *lctxt, char *logname)
987 {
988         struct llog_handle *local_llh, *remote_llh;
989         struct obd_uuid *uuid;
990         char *temp_log;
991         int rc, rc2;
992         ENTRY;
993
994         /* Write new log to a temp name, then vfs_rename over logname
995            upon successful completion. */
996
997         OBD_ALLOC(temp_log, strlen(logname) + 1);
998         if (!temp_log) 
999                 RETURN(-ENOMEM);
1000         sprintf(temp_log, "%sT", logname);
1001
1002         /* Make sure there's no old temp log */
1003         rc = llog_create(lctxt, &local_llh, NULL, temp_log);
1004         if (rc)
1005                 GOTO(out, rc);
1006         rc = llog_init_handle(local_llh, LLOG_F_IS_PLAIN, NULL);
1007         if (rc) 
1008                 GOTO(out, rc);
1009         rc = llog_destroy(local_llh);
1010         llog_free_handle(local_llh);
1011         if (rc)
1012                 GOTO(out, rc);
1013
1014         /* open local log */
1015         rc = llog_create(lctxt, &local_llh, NULL, temp_log);
1016         if (rc)
1017                 GOTO(out, rc);
1018
1019         /* set the log header uuid for fun */
1020         OBD_ALLOC_PTR(uuid);
1021         obd_str2uuid(uuid, logname);
1022         rc = llog_init_handle(local_llh, LLOG_F_IS_PLAIN, uuid);
1023         OBD_FREE_PTR(uuid);
1024         if (rc)
1025                 GOTO(out_closel, rc);
1026
1027         /* open remote log */
1028         rc = llog_create(rctxt, &remote_llh, NULL, logname);
1029         if (rc)
1030                 GOTO(out_closel, rc);
1031         rc = llog_init_handle(remote_llh, LLOG_F_IS_PLAIN, NULL);
1032         if (rc)
1033                 GOTO(out_closer, rc);
1034
1035         /* Copy remote log */
1036         rc = llog_process(remote_llh, mgc_copy_handler,(void *)local_llh, NULL);
1037
1038 out_closer:
1039         rc2 = llog_close(remote_llh);
1040         if (!rc)
1041                 rc = rc2;
1042 out_closel:
1043         rc2 = llog_close(local_llh);
1044         if (!rc)
1045                 rc = rc2;
1046
1047         /* We've copied the remote log to the local temp log, now
1048            replace the old local log with the temp log. */
1049         if (!rc) {
1050                 struct client_obd *cli = &obd->u.cli;
1051                 LASSERT(cli);
1052                 LASSERT(cli->cl_mgc_configs_dir);
1053                 rc = lustre_rename(cli->cl_mgc_configs_dir, temp_log, logname);
1054         }
1055         CDEBUG(D_MGC, "Copied remote log %s (%d)\n", logname, rc);
1056 out:
1057         if (rc)
1058                 CERROR("Failed to copy remote log %s (%d)\n", logname, rc);
1059         OBD_FREE(temp_log, strlen(logname) + 1);
1060         RETURN(rc);
1061 }
1062
1063 DECLARE_MUTEX(llog_process_lock);
1064
1065 /* Get a config log from the MGS and process it.
1066    This func is called for both clients and servers. */
1067 static int mgc_process_log(struct obd_device *mgc,
1068                            struct config_llog_data *cld)
1069 {
1070         struct llog_ctxt *ctxt, *lctxt;
1071         struct lustre_handle lockh;
1072         struct client_obd *cli = &mgc->u.cli;
1073         struct lvfs_run_ctxt saved;
1074         struct lustre_sb_info *lsi;
1075         int rc = 0, rcl, flags = 0, must_pop = 0;
1076         ENTRY;
1077
1078         if (!cld || !cld->cld_cfg.cfg_sb) {
1079                 /* This should never happen */
1080                 CERROR("Missing cld, aborting log update\n");
1081                 RETURN(-EINVAL);
1082         }
1083         if (cld->cld_stopping)
1084                 RETURN(0);
1085
1086         OBD_FAIL_TIMEOUT(OBD_FAIL_MGC_PROCESS_LOG, 20);
1087
1088         lsi = s2lsi(cld->cld_cfg.cfg_sb);
1089
1090         CDEBUG(D_MGC, "Process log %s:%s from %d\n", cld->cld_logname,
1091                cld->cld_cfg.cfg_instance, cld->cld_cfg.cfg_last_idx + 1);
1092
1093         ctxt = llog_get_context(mgc, LLOG_CONFIG_REPL_CTXT);
1094         if (!ctxt) {
1095                 CERROR("missing llog context\n");
1096                 RETURN(-EINVAL);
1097         }
1098
1099         /* I don't want mutliple processes running process_log at once --
1100            sounds like badness.  It actually might be fine, as long as
1101            we're not trying to update from the same log
1102            simultaneously (in which case we should use a per-log sem.) */
1103         down(&llog_process_lock);
1104
1105         /* Get the cfg lock on the llog */
1106         rcl = mgc_enqueue(mgc->u.cli.cl_mgc_mgsexp, NULL, LDLM_PLAIN, NULL,
1107                           LCK_CR, &flags, NULL, NULL, NULL,
1108                           cld, 0, NULL, &lockh);
1109         if (rcl)
1110                 CDEBUG(D_MGC, "Can't get cfg lock: %d\n", rcl);
1111
1112         lctxt = llog_get_context(mgc, LLOG_CONFIG_ORIG_CTXT);
1113
1114         /* Copy the setup log locally if we can. Don't mess around if we're
1115            running an MGS though (logs are already local). */
1116         if (lctxt && lsi && (lsi->lsi_flags & LSI_SERVER) &&
1117             (lsi->lsi_srv_mnt == cli->cl_mgc_vfsmnt) &&
1118             !IS_MGS(lsi->lsi_ldd)) {
1119                 push_ctxt(&saved, &mgc->obd_lvfs_ctxt, NULL);
1120                 must_pop++;
1121                 if (rcl == 0)
1122                         /* Only try to copy log if we have the lock. */
1123                         rc = mgc_copy_llog(mgc, ctxt, lctxt, cld->cld_logname);
1124                 if (rcl || rc) {
1125                         if (mgc_llog_is_empty(mgc, lctxt, cld->cld_logname)) {
1126                                 LCONSOLE_ERROR_MSG(0x13a, "Failed to get MGS "
1127                                                    "log %s and no local copy."
1128                                                    "\n", cld->cld_logname);
1129                                 GOTO(out_pop, rc = -ENOTCONN);
1130                         }
1131                         CDEBUG(D_MGC, "Failed to get MGS log %s, using local "
1132                                       "copy for now, will try to update later.\n",
1133                                cld->cld_logname);
1134                 }
1135                 /* Now, whether we copied or not, start using the local llog.
1136                    If we failed to copy, we'll start using whatever the old
1137                    log has. */
1138                 llog_ctxt_put(ctxt);
1139                 ctxt = lctxt;
1140         }
1141
1142         /* logname and instance info should be the same, so use our
1143            copy of the instance for the update.  The cfg_last_idx will
1144            be updated here. */
1145         rc = class_config_parse_llog(ctxt, cld->cld_logname, &cld->cld_cfg);
1146 out_pop:
1147         llog_ctxt_put(ctxt);
1148         if (ctxt != lctxt)
1149                 llog_ctxt_put(lctxt);
1150         if (must_pop)
1151                 pop_ctxt(&saved, &mgc->obd_lvfs_ctxt, NULL);
1152
1153         /* Now drop the lock so MGS can revoke it */
1154         if (!rcl) {
1155                 rcl = mgc_cancel(mgc->u.cli.cl_mgc_mgsexp, NULL,
1156                                  LCK_CR, &lockh);
1157                 if (rcl)
1158                         CERROR("Can't drop cfg lock: %d\n", rcl);
1159         }
1160
1161         CDEBUG(D_MGC, "%s: configuration from log '%s' %sed (%d).\n",
1162                mgc->obd_name, cld->cld_logname, rc ? "fail" : "succeed", rc);
1163
1164         up(&llog_process_lock);
1165
1166         RETURN(rc);
1167 }
1168
1169 static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
1170 {
1171         struct lustre_cfg *lcfg = buf;
1172         int cmd;
1173         int rc = 0;
1174         ENTRY;
1175
1176         switch(cmd = lcfg->lcfg_command) {
1177         case LCFG_LOV_ADD_OBD: {
1178                 /* Add any new target, not just osts */
1179                 struct mgs_target_info *mti;
1180
1181                 if (LUSTRE_CFG_BUFLEN(lcfg, 1) !=
1182                     sizeof(struct mgs_target_info))
1183                         GOTO(out, rc = -EINVAL);
1184
1185                 mti = (struct mgs_target_info *)lustre_cfg_buf(lcfg, 1);
1186                 CDEBUG(D_MGC, "add_target %s %#x\n",
1187                        mti->mti_svname, mti->mti_flags);
1188                 rc = mgc_target_register(obd->u.cli.cl_mgc_mgsexp, mti);
1189                 break;
1190         }
1191         case LCFG_LOV_DEL_OBD:
1192                 /* Remove target from the fs? */
1193                 /* FIXME */
1194                 CERROR("lov_del_obd unimplemented\n");
1195                 rc = -ENOSYS;
1196                 break;
1197         case LCFG_LOG_START: {
1198                 struct config_llog_data *cld;
1199                 struct config_llog_instance *cfg;
1200                 struct super_block *sb;
1201                 char *logname = lustre_cfg_string(lcfg, 1);
1202                 cfg = (struct config_llog_instance *)lustre_cfg_buf(lcfg, 2);
1203                 sb = *(struct super_block **)lustre_cfg_buf(lcfg, 3);
1204
1205                 CDEBUG(D_MGC, "parse_log %s from %d\n", logname,
1206                        cfg->cfg_last_idx);
1207
1208                 /* We're only called through here on the initial mount */
1209                 rc = config_log_add(logname, cfg, sb);
1210                 if (rc)
1211                         break;
1212                 cld = config_log_find(logname, cfg);
1213                 if (IS_ERR(cld)) {
1214                         rc = PTR_ERR(cld);
1215                         break;
1216                 }
1217
1218                 /* COMPAT_146 */
1219                 /* FIXME only set this for old logs!  Right now this forces
1220                    us to always skip the "inside markers" check */
1221                 cld->cld_cfg.cfg_flags |= CFG_F_COMPAT146;
1222
1223                 rc = mgc_process_log(obd, cld);
1224                 config_log_put(cld);
1225
1226                 break;
1227         }
1228         case LCFG_LOG_END: {
1229                 struct config_llog_instance *cfg = NULL;
1230                 char *logname = lustre_cfg_string(lcfg, 1);
1231                 if (lcfg->lcfg_bufcount >= 2)
1232                         cfg = (struct config_llog_instance *)lustre_cfg_buf(
1233                                 lcfg, 2);
1234                 rc = config_log_end(logname, cfg);
1235                 break;
1236         }
1237         default: {
1238                 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1239                 GOTO(out, rc = -EINVAL);
1240
1241         }
1242         }
1243 out:
1244         RETURN(rc);
1245 }
1246
1247 struct obd_ops mgc_obd_ops = {
1248         .o_owner        = THIS_MODULE,
1249         .o_setup        = mgc_setup,
1250         .o_precleanup   = mgc_precleanup,
1251         .o_cleanup      = mgc_cleanup,
1252         .o_add_conn     = client_import_add_conn,
1253         .o_del_conn     = client_import_del_conn,
1254         .o_connect      = client_connect_import,
1255         .o_disconnect   = client_disconnect_export,
1256         //.o_enqueue      = mgc_enqueue,
1257         .o_cancel       = mgc_cancel,
1258         //.o_iocontrol    = mgc_iocontrol,
1259         .o_set_info_async = mgc_set_info_async,
1260         .o_import_event = mgc_import_event,
1261         .o_llog_init    = mgc_llog_init,
1262         .o_llog_finish  = mgc_llog_finish,
1263         .o_process_config = mgc_process_config,
1264 };
1265
1266 int __init mgc_init(void)
1267 {
1268         return class_register_type(&mgc_obd_ops, NULL, NULL,
1269                                    LUSTRE_MGC_NAME, NULL);
1270 }
1271
1272 #ifdef __KERNEL__
1273 static void /*__exit*/ mgc_exit(void)
1274 {
1275         class_unregister_type(LUSTRE_MGC_NAME);
1276 }
1277
1278 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1279 MODULE_DESCRIPTION("Lustre Management Client");
1280 MODULE_LICENSE("GPL");
1281
1282 module_init(mgc_init);
1283 module_exit(mgc_exit);
1284 #endif