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