Whamcloud - gitweb
b=14149
[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                     rc;
739         ENTRY;
740
741         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
742                                         &RQF_MGS_TARGET_REG, LUSTRE_MGS_VERSION,
743                                         MGS_TARGET_REG);
744         if (req == NULL)
745                 RETURN(-ENOMEM);
746
747         req_mti = req_capsule_client_get(&req->rq_pill, &RMF_MGS_TARGET_INFO);
748         memcpy(req_mti, mti, sizeof(*req_mti));
749
750         ptlrpc_request_set_replen(req);
751
752         CDEBUG(D_MGC, "register %s\n", mti->mti_svname);
753
754         rc = ptlrpc_queue_wait(req);
755         if (!rc) {
756                 rep_mti = req_capsule_server_get(&req->rq_pill,
757                                                  &RMF_MGS_TARGET_INFO);
758                 memcpy(mti, rep_mti, sizeof(*rep_mti));
759                 CDEBUG(D_MGC, "register %s got index = %d\n",
760                        mti->mti_svname, mti->mti_stripe_index);
761         }
762         ptlrpc_req_finished(req);
763
764         RETURN(rc);
765 }
766
767 int mgc_reconnect_import(struct obd_import *imp)
768 {
769         /* Force a new connect attempt */
770         ptlrpc_invalidate_import(imp);
771         /* Do a fresh connect next time by zeroing the handle */
772         ptlrpc_disconnect_import(imp, 1);
773         /* Wait for all invalidate calls to finish */
774         if (atomic_read(&imp->imp_inval_count) > 0) {
775                 int rc;
776                 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
777                 rc = l_wait_event(imp->imp_recovery_waitq,
778                                   (atomic_read(&imp->imp_inval_count) == 0),
779                                   &lwi);
780                 if (rc)
781                         CERROR("Interrupted, inval=%d\n",
782                                atomic_read(&imp->imp_inval_count));
783         }
784
785         /* Allow reconnect attempts */
786         imp->imp_obd->obd_no_recov = 0;
787         /* Remove 'invalid' flag */
788         ptlrpc_activate_import(imp);
789         /* Attempt a new connect */
790         ptlrpc_recover_import(imp, NULL);
791         return 0;
792 }
793
794 int mgc_set_info_async(struct obd_export *exp, obd_count keylen,
795                        void *key, obd_count vallen, void *val,
796                        struct ptlrpc_request_set *set)
797 {
798         struct obd_import *imp = class_exp2cliimp(exp);
799         int rc = -EINVAL;
800         ENTRY;
801
802         /* Try to "recover" the initial connection; i.e. retry */
803         if (KEY_IS(KEY_INIT_RECOV)) {
804                 if (vallen != sizeof(int))
805                         RETURN(-EINVAL);
806                 spin_lock(&imp->imp_lock);
807                 imp->imp_initial_recov = *(int *)val;
808                 spin_unlock(&imp->imp_lock);
809                 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
810                        exp->exp_obd->obd_name, imp->imp_initial_recov);
811                 RETURN(0);
812         }
813         /* Turn off initial_recov after we try all backup servers once */
814         if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
815                 int value;
816                 if (vallen != sizeof(int))
817                         RETURN(-EINVAL);
818                 value = *(int *)val;
819                 spin_lock(&imp->imp_lock);
820                 imp->imp_initial_recov_bk = value > 0;
821                 /* Even after the initial connection, give up all comms if
822                    nobody answers the first time. */
823                 imp->imp_recon_bk = 1;
824                 spin_unlock(&imp->imp_lock);
825                 CDEBUG(D_MGC, "InitRecov %s %d/%d:d%d:i%d:r%d:or%d:%s\n",
826                        imp->imp_obd->obd_name, value, imp->imp_initial_recov,
827                        imp->imp_deactive, imp->imp_invalid,
828                        imp->imp_replayable, imp->imp_obd->obd_replayable,
829                        ptlrpc_import_state_name(imp->imp_state));
830                 /* Resurrect if we previously died */
831                 if (imp->imp_invalid || value > 1)
832                         mgc_reconnect_import(imp);
833                 RETURN(0);
834         }
835         /* FIXME move this to mgc_process_config */
836         if (KEY_IS("register_target")) {
837                 struct mgs_target_info *mti;
838                 if (vallen != sizeof(struct mgs_target_info))
839                         RETURN(-EINVAL);
840                 mti = (struct mgs_target_info *)val;
841                 CDEBUG(D_MGC, "register_target %s %#x\n",
842                        mti->mti_svname, mti->mti_flags);
843                 rc =  mgc_target_register(exp, mti);
844                 RETURN(rc);
845         }
846         if (KEY_IS("set_fs")) {
847                 struct super_block *sb = (struct super_block *)val;
848                 struct lustre_sb_info *lsi;
849                 if (vallen != sizeof(struct super_block))
850                         RETURN(-EINVAL);
851                 lsi = s2lsi(sb);
852                 rc = mgc_fs_setup(exp->exp_obd, sb, lsi->lsi_srv_mnt);
853                 if (rc) {
854                         CERROR("set_fs got %d\n", rc);
855                 }
856                 RETURN(rc);
857         }
858         if (KEY_IS("clear_fs")) {
859                 if (vallen != 0)
860                         RETURN(-EINVAL);
861                 rc = mgc_fs_cleanup(exp->exp_obd);
862                 if (rc) {
863                         CERROR("clear_fs got %d\n", rc);
864                 }
865                 RETURN(rc);
866         }
867         if (KEY_IS(KEY_SET_INFO)) {
868                 struct mgs_send_param *msp;
869
870                 msp = (struct mgs_send_param *)val;
871                 rc =  mgc_set_mgs_param(exp, msp);
872                 RETURN(rc);
873         }
874
875         RETURN(rc);
876 }
877
878 static int mgc_import_event(struct obd_device *obd,
879                             struct obd_import *imp,
880                             enum obd_import_event event)
881 {
882         int rc = 0;
883
884         LASSERT(imp->imp_obd == obd);
885         CDEBUG(D_MGC, "import event %#x\n", event);
886
887         switch (event) {
888         case IMP_EVENT_DISCON:
889                 /* MGC imports should not wait for recovery */
890                 ptlrpc_invalidate_import(imp);
891                 break;
892         case IMP_EVENT_INACTIVE:
893                 break;
894         case IMP_EVENT_INVALIDATE: {
895                 struct ldlm_namespace *ns = obd->obd_namespace;
896                 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
897                 break;
898         }
899         case IMP_EVENT_ACTIVE:
900                 LCONSOLE_WARN("%s: Reactivating import\n", obd->obd_name);
901                 break;
902         case IMP_EVENT_OCD:
903                 break;
904         default:
905                 CERROR("Unknown import event %#x\n", event);
906                 LBUG();
907         }
908         RETURN(rc);
909 }
910
911 static int mgc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
912                          struct obd_device *tgt, int count,
913                          struct llog_catid *logid, struct obd_uuid *uuid)
914 {
915         struct llog_ctxt *ctxt;
916         int rc;
917         ENTRY;
918
919         rc = llog_setup(obd, llogs, LLOG_CONFIG_ORIG_CTXT, tgt, 0, NULL,
920                         &llog_lvfs_ops);
921         if (rc)
922                 RETURN(rc);
923
924         rc = llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
925                         &llog_client_ops);
926         if (rc == 0) {
927                 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
928                 ctxt->loc_imp = obd->u.cli.cl_import;
929         }
930
931         RETURN(rc);
932 }
933
934 static int mgc_llog_finish(struct obd_device *obd, int count)
935 {
936         int rc;
937         ENTRY;
938
939         rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
940         rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT));
941
942         RETURN(rc);
943 }
944
945 /* identical to mgs_log_is_empty */
946 static int mgc_llog_is_empty(struct obd_device *obd, struct llog_ctxt *ctxt,
947                             char *name)
948 {
949         struct lvfs_run_ctxt saved;
950         struct llog_handle *llh;
951         int rc = 0;
952
953         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
954         rc = llog_create(ctxt, &llh, NULL, name);
955         if (rc == 0) {
956                 llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
957                 rc = llog_get_size(llh);
958                 llog_close(llh);
959         }
960         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
961         /* header is record 1 */
962         return(rc <= 1);
963 }
964
965 static int mgc_copy_handler(struct llog_handle *llh, struct llog_rec_hdr *rec,
966                             void *data)
967 {
968         struct llog_rec_hdr local_rec = *rec;
969         struct llog_handle *local_llh = (struct llog_handle *)data;
970         char *cfg_buf = (char*) (rec + 1);
971         struct lustre_cfg *lcfg;
972         int rc = 0;
973         ENTRY;
974
975         /* Append all records */
976         local_rec.lrh_len -= sizeof(*rec) + sizeof(struct llog_rec_tail);
977         rc = llog_write_rec(local_llh, &local_rec, NULL, 0,
978                             (void *)cfg_buf, -1);
979
980         lcfg = (struct lustre_cfg *)cfg_buf;
981         CDEBUG(D_INFO, "idx=%d, rc=%d, len=%d, cmd %x %s %s\n",
982                rec->lrh_index, rc, rec->lrh_len, lcfg->lcfg_command,
983                lustre_cfg_string(lcfg, 0), lustre_cfg_string(lcfg, 1));
984
985         RETURN(rc);
986 }
987
988 /* Copy a remote log locally */
989 static int mgc_copy_llog(struct obd_device *obd, struct llog_ctxt *rctxt,
990                          struct llog_ctxt *lctxt, char *logname)
991 {
992         struct llog_handle *local_llh, *remote_llh;
993         struct obd_uuid *uuid;
994         char *temp_log;
995         int rc, rc2;
996         ENTRY;
997
998         /* Write new log to a temp name, then vfs_rename over logname
999            upon successful completion. */
1000
1001         OBD_ALLOC(temp_log, strlen(logname) + 1);
1002         if (!temp_log) 
1003                 RETURN(-ENOMEM);
1004         sprintf(temp_log, "%sT", logname);
1005
1006         /* Make sure there's no old temp log */
1007         rc = llog_create(lctxt, &local_llh, NULL, temp_log);
1008         if (rc)
1009                 GOTO(out, rc);
1010         rc = llog_init_handle(local_llh, LLOG_F_IS_PLAIN, NULL);
1011         if (rc) 
1012                 GOTO(out, rc);
1013         rc = llog_destroy(local_llh);
1014         llog_free_handle(local_llh);
1015         if (rc)
1016                 GOTO(out, rc);
1017
1018         /* open local log */
1019         rc = llog_create(lctxt, &local_llh, NULL, temp_log);
1020         if (rc)
1021                 GOTO(out, rc);
1022
1023         /* set the log header uuid for fun */
1024         OBD_ALLOC_PTR(uuid);
1025         obd_str2uuid(uuid, logname);
1026         rc = llog_init_handle(local_llh, LLOG_F_IS_PLAIN, uuid);
1027         OBD_FREE_PTR(uuid);
1028         if (rc)
1029                 GOTO(out_closel, rc);
1030
1031         /* open remote log */
1032         rc = llog_create(rctxt, &remote_llh, NULL, logname);
1033         if (rc)
1034                 GOTO(out_closel, rc);
1035         rc = llog_init_handle(remote_llh, LLOG_F_IS_PLAIN, NULL);
1036         if (rc)
1037                 GOTO(out_closer, rc);
1038
1039         /* Copy remote log */
1040         rc = llog_process(remote_llh, mgc_copy_handler,(void *)local_llh, NULL);
1041
1042 out_closer:
1043         rc2 = llog_close(remote_llh);
1044         if (!rc)
1045                 rc = rc2;
1046 out_closel:
1047         rc2 = llog_close(local_llh);
1048         if (!rc)
1049                 rc = rc2;
1050
1051         /* We've copied the remote log to the local temp log, now
1052            replace the old local log with the temp log. */
1053         if (!rc) {
1054                 struct client_obd *cli = &obd->u.cli;
1055                 LASSERT(cli);
1056                 LASSERT(cli->cl_mgc_configs_dir);
1057                 rc = lustre_rename(cli->cl_mgc_configs_dir, temp_log, logname);
1058         }
1059         CDEBUG(D_MGC, "Copied remote log %s (%d)\n", logname, rc);
1060 out:
1061         if (rc)
1062                 CERROR("Failed to copy remote log %s (%d)\n", logname, rc);
1063         OBD_FREE(temp_log, strlen(logname) + 1);
1064         RETURN(rc);
1065 }
1066
1067 DECLARE_MUTEX(llog_process_lock);
1068
1069 /* Get a config log from the MGS and process it.
1070    This func is called for both clients and servers. */
1071 static int mgc_process_log(struct obd_device *mgc,
1072                            struct config_llog_data *cld)
1073 {
1074         struct llog_ctxt *ctxt, *lctxt;
1075         struct lustre_handle lockh;
1076         struct client_obd *cli = &mgc->u.cli;
1077         struct lvfs_run_ctxt saved;
1078         struct lustre_sb_info *lsi;
1079         int rc = 0, rcl, flags = 0, must_pop = 0;
1080         ENTRY;
1081
1082         if (!cld || !cld->cld_cfg.cfg_sb) {
1083                 /* This should never happen */
1084                 CERROR("Missing cld, aborting log update\n");
1085                 RETURN(-EINVAL);
1086         }
1087         if (cld->cld_stopping)
1088                 RETURN(0);
1089
1090         OBD_FAIL_TIMEOUT(OBD_FAIL_MGC_PROCESS_LOG, 20);
1091
1092         lsi = s2lsi(cld->cld_cfg.cfg_sb);
1093
1094         CDEBUG(D_MGC, "Process log %s:%s from %d\n", cld->cld_logname,
1095                cld->cld_cfg.cfg_instance, cld->cld_cfg.cfg_last_idx + 1);
1096
1097         ctxt = llog_get_context(mgc, LLOG_CONFIG_REPL_CTXT);
1098         if (!ctxt) {
1099                 CERROR("missing llog context\n");
1100                 RETURN(-EINVAL);
1101         }
1102
1103         /* I don't want mutliple processes running process_log at once --
1104            sounds like badness.  It actually might be fine, as long as
1105            we're not trying to update from the same log
1106            simultaneously (in which case we should use a per-log sem.) */
1107         down(&llog_process_lock);
1108
1109         /* Get the cfg lock on the llog */
1110         rcl = mgc_enqueue(mgc->u.cli.cl_mgc_mgsexp, NULL, LDLM_PLAIN, NULL,
1111                           LCK_CR, &flags, NULL, NULL, NULL,
1112                           cld, 0, NULL, &lockh);
1113         if (rcl)
1114                 CDEBUG(D_MGC, "Can't get cfg lock: %d\n", rcl);
1115
1116         lctxt = llog_get_context(mgc, LLOG_CONFIG_ORIG_CTXT);
1117
1118         /* Copy the setup log locally if we can. Don't mess around if we're
1119            running an MGS though (logs are already local). */
1120         if (lctxt && lsi && (lsi->lsi_flags & LSI_SERVER) &&
1121             (lsi->lsi_srv_mnt == cli->cl_mgc_vfsmnt) &&
1122             !IS_MGS(lsi->lsi_ldd)) {
1123                 push_ctxt(&saved, &mgc->obd_lvfs_ctxt, NULL);
1124                 must_pop++;
1125                 if (rcl == 0)
1126                         /* Only try to copy log if we have the lock. */
1127                         rc = mgc_copy_llog(mgc, ctxt, lctxt, cld->cld_logname);
1128                 if (rcl || rc) {
1129                         if (mgc_llog_is_empty(mgc, lctxt, cld->cld_logname)) {
1130                                 LCONSOLE_ERROR_MSG(0x13a, "Failed to get MGS "
1131                                                    "log %s and no local copy."
1132                                                    "\n", cld->cld_logname);
1133                                 GOTO(out_pop, rc = -ENOTCONN);
1134                         }
1135                         LCONSOLE_WARN("Failed to get MGS log %s, using "
1136                                       "local copy.\n", cld->cld_logname);
1137                 }
1138                 /* Now, whether we copied or not, start using the local llog.
1139                    If we failed to copy, we'll start using whatever the old
1140                    log has. */
1141                 ctxt = lctxt;
1142         }
1143
1144         /* logname and instance info should be the same, so use our
1145            copy of the instance for the update.  The cfg_last_idx will
1146            be updated here. */
1147         rc = class_config_parse_llog(ctxt, cld->cld_logname, &cld->cld_cfg);
1148
1149  out_pop:
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