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