Version:  2.0.40 2.2.26 2.4.37 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16

Linux/drivers/staging/lustre/lustre/obdclass/obd_mount.c

  1 /*
  2  * GPL HEADER START
  3  *
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This program is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License version 2 only,
  8  * as published by the Free Software Foundation.
  9  *
 10  * This program is distributed in the hope that it will be useful, but
 11  * WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  * General Public License version 2 for more details (a copy is included
 14  * in the LICENSE file that accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License
 17  * version 2 along with this program; If not, see
 18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
 19  *
 20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 21  * CA 95054 USA or visit www.sun.com if you need additional information or
 22  * have any questions.
 23  *
 24  * GPL HEADER END
 25  */
 26 /*
 27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 28  * Use is subject to license terms.
 29  *
 30  * Copyright (c) 2011, 2012, Intel Corporation.
 31  */
 32 /*
 33  * This file is part of Lustre, http://www.lustre.org/
 34  * Lustre is a trademark of Sun Microsystems, Inc.
 35  *
 36  * lustre/obdclass/obd_mount.c
 37  *
 38  * Client mount routines
 39  *
 40  * Author: Nathan Rutman <nathan@clusterfs.com>
 41  */
 42 
 43 
 44 #define DEBUG_SUBSYSTEM S_CLASS
 45 #define D_MOUNT (D_SUPER|D_CONFIG/*|D_WARNING */)
 46 #define PRINT_CMD CDEBUG
 47 
 48 #include <obd.h>
 49 #include <lvfs.h>
 50 #include <obd_class.h>
 51 #include <lustre/lustre_user.h>
 52 #include <lustre_log.h>
 53 #include <lustre_disk.h>
 54 #include <lustre_param.h>
 55 
 56 static int (*client_fill_super)(struct super_block *sb,
 57                                 struct vfsmount *mnt);
 58 
 59 static void (*kill_super_cb)(struct super_block *sb);
 60 
 61 /**************** config llog ********************/
 62 
 63 /** Get a config log from the MGS and process it.
 64  * This func is called for both clients and servers.
 65  * Continue to process new statements appended to the logs
 66  * (whenever the config lock is revoked) until lustre_end_log
 67  * is called.
 68  * @param sb The superblock is used by the MGC to write to the local copy of
 69  *   the config log
 70  * @param logname The name of the llog to replicate from the MGS
 71  * @param cfg Since the same mgc may be used to follow multiple config logs
 72  *   (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
 73  *   this log, and is added to the mgc's list of logs to follow.
 74  */
 75 int lustre_process_log(struct super_block *sb, char *logname,
 76                      struct config_llog_instance *cfg)
 77 {
 78         struct lustre_cfg *lcfg;
 79         struct lustre_cfg_bufs *bufs;
 80         struct lustre_sb_info *lsi = s2lsi(sb);
 81         struct obd_device *mgc = lsi->lsi_mgc;
 82         int rc;
 83 
 84         LASSERT(mgc);
 85         LASSERT(cfg);
 86 
 87         OBD_ALLOC_PTR(bufs);
 88         if (bufs == NULL)
 89                 return -ENOMEM;
 90 
 91         /* mgc_process_config */
 92         lustre_cfg_bufs_reset(bufs, mgc->obd_name);
 93         lustre_cfg_bufs_set_string(bufs, 1, logname);
 94         lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
 95         lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
 96         lcfg = lustre_cfg_new(LCFG_LOG_START, bufs);
 97         rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
 98         lustre_cfg_free(lcfg);
 99 
100         OBD_FREE_PTR(bufs);
101 
102         if (rc == -EINVAL)
103                 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s'"
104                                    "failed from the MGS (%d).  Make sure this "
105                                    "client and the MGS are running compatible "
106                                    "versions of Lustre.\n",
107                                    mgc->obd_name, logname, rc);
108 
109         if (rc)
110                 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' "
111                                    "failed (%d). This may be the result of "
112                                    "communication errors between this node and "
113                                    "the MGS, a bad configuration, or other "
114                                    "errors. See the syslog for more "
115                                    "information.\n", mgc->obd_name, logname,
116                                    rc);
117 
118         /* class_obd_list(); */
119         return rc;
120 }
121 EXPORT_SYMBOL(lustre_process_log);
122 
123 /* Stop watching this config log for updates */
124 int lustre_end_log(struct super_block *sb, char *logname,
125                        struct config_llog_instance *cfg)
126 {
127         struct lustre_cfg *lcfg;
128         struct lustre_cfg_bufs bufs;
129         struct lustre_sb_info *lsi = s2lsi(sb);
130         struct obd_device *mgc = lsi->lsi_mgc;
131         int rc;
132 
133         if (!mgc)
134                 return -ENOENT;
135 
136         /* mgc_process_config */
137         lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
138         lustre_cfg_bufs_set_string(&bufs, 1, logname);
139         if (cfg)
140                 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
141         lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
142         rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
143         lustre_cfg_free(lcfg);
144         return rc;
145 }
146 EXPORT_SYMBOL(lustre_end_log);
147 
148 /**************** obd start *******************/
149 
150 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
151  * lctl (and do for echo cli/srv.
152  */
153 int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
154             char *s1, char *s2, char *s3, char *s4)
155 {
156         struct lustre_cfg_bufs bufs;
157         struct lustre_cfg    * lcfg = NULL;
158         int rc;
159 
160         CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
161                cmd, s1, s2, s3, s4);
162 
163         lustre_cfg_bufs_reset(&bufs, cfgname);
164         if (s1)
165                 lustre_cfg_bufs_set_string(&bufs, 1, s1);
166         if (s2)
167                 lustre_cfg_bufs_set_string(&bufs, 2, s2);
168         if (s3)
169                 lustre_cfg_bufs_set_string(&bufs, 3, s3);
170         if (s4)
171                 lustre_cfg_bufs_set_string(&bufs, 4, s4);
172 
173         lcfg = lustre_cfg_new(cmd, &bufs);
174         lcfg->lcfg_nid = nid;
175         rc = class_process_config(lcfg);
176         lustre_cfg_free(lcfg);
177         return(rc);
178 }
179 EXPORT_SYMBOL(do_lcfg);
180 
181 /** Call class_attach and class_setup.  These methods in turn call
182  * obd type-specific methods.
183  */
184 int lustre_start_simple(char *obdname, char *type, char *uuid,
185                         char *s1, char *s2, char *s3, char *s4)
186 {
187         int rc;
188         CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
189 
190         rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
191         if (rc) {
192                 CERROR("%s attach error %d\n", obdname, rc);
193                 return rc;
194         }
195         rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
196         if (rc) {
197                 CERROR("%s setup error %d\n", obdname, rc);
198                 do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
199         }
200         return rc;
201 }
202 
203 DEFINE_MUTEX(mgc_start_lock);
204 
205 /** Set up a mgc obd to process startup logs
206  *
207  * \param sb [in] super block of the mgc obd
208  *
209  * \retval 0 success, otherwise error code
210  */
211 int lustre_start_mgc(struct super_block *sb)
212 {
213         struct obd_connect_data *data = NULL;
214         struct lustre_sb_info *lsi = s2lsi(sb);
215         struct obd_device *obd;
216         struct obd_export *exp;
217         struct obd_uuid *uuid;
218         class_uuid_t uuidc;
219         lnet_nid_t nid;
220         char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
221         char *ptr;
222         int recov_bk;
223         int rc = 0, i = 0, j, len;
224 
225         LASSERT(lsi->lsi_lmd);
226 
227         /* Find the first non-lo MGS nid for our MGC name */
228         if (IS_SERVER(lsi)) {
229                 /* mount -o mgsnode=nid */
230                 ptr = lsi->lsi_lmd->lmd_mgs;
231                 if (lsi->lsi_lmd->lmd_mgs &&
232                     (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
233                         i++;
234                 } else if (IS_MGS(lsi)) {
235                         lnet_process_id_t id;
236                         while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
237                                 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
238                                         continue;
239                                 nid = id.nid;
240                                 i++;
241                                 break;
242                         }
243                 }
244         } else { /* client */
245                 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
246                 ptr = lsi->lsi_lmd->lmd_dev;
247                 if (class_parse_nid(ptr, &nid, &ptr) == 0)
248                         i++;
249         }
250         if (i == 0) {
251                 CERROR("No valid MGS nids found.\n");
252                 return -EINVAL;
253         }
254 
255         mutex_lock(&mgc_start_lock);
256 
257         len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
258         OBD_ALLOC(mgcname, len);
259         OBD_ALLOC(niduuid, len + 2);
260         if (!mgcname || !niduuid)
261                 GOTO(out_free, rc = -ENOMEM);
262         sprintf(mgcname, "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
263 
264         mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
265 
266         OBD_ALLOC_PTR(data);
267         if (data == NULL)
268                 GOTO(out_free, rc = -ENOMEM);
269 
270         obd = class_name2obd(mgcname);
271         if (obd && !obd->obd_stopping) {
272                 rc = obd_set_info_async(NULL, obd->obd_self_export,
273                                         strlen(KEY_MGSSEC), KEY_MGSSEC,
274                                         strlen(mgssec), mgssec, NULL);
275                 if (rc)
276                         GOTO(out_free, rc);
277 
278                 /* Re-using an existing MGC */
279                 atomic_inc(&obd->u.cli.cl_mgc_refcount);
280 
281                 /* IR compatibility check, only for clients */
282                 if (lmd_is_client(lsi->lsi_lmd)) {
283                         int has_ir;
284                         int vallen = sizeof(*data);
285                         __u32 *flags = &lsi->lsi_lmd->lmd_flags;
286 
287                         rc = obd_get_info(NULL, obd->obd_self_export,
288                                           strlen(KEY_CONN_DATA), KEY_CONN_DATA,
289                                           &vallen, data, NULL);
290                         LASSERT(rc == 0);
291                         has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
292                         if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
293                                 /* LMD_FLG_NOIR is for test purpose only */
294                                 LCONSOLE_WARN(
295                                     "Trying to mount a client with IR setting "
296                                     "not compatible with current mgc. "
297                                     "Force to use current mgc setting that is "
298                                     "IR %s.\n",
299                                     has_ir ? "enabled" : "disabled");
300                                 if (has_ir)
301                                         *flags &= ~LMD_FLG_NOIR;
302                                 else
303                                         *flags |= LMD_FLG_NOIR;
304                         }
305                 }
306 
307                 recov_bk = 0;
308                 /* If we are restarting the MGS, don't try to keep the MGC's
309                    old connection, or registration will fail. */
310                 if (IS_MGS(lsi)) {
311                         CDEBUG(D_MOUNT, "New MGS with live MGC\n");
312                         recov_bk = 1;
313                 }
314 
315                 /* Try all connections, but only once (again).
316                    We don't want to block another target from starting
317                    (using its local copy of the log), but we do want to connect
318                    if at all possible. */
319                 recov_bk++;
320                 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,recov_bk);
321                 rc = obd_set_info_async(NULL, obd->obd_self_export,
322                                         sizeof(KEY_INIT_RECOV_BACKUP),
323                                         KEY_INIT_RECOV_BACKUP,
324                                         sizeof(recov_bk), &recov_bk, NULL);
325                 GOTO(out, rc = 0);
326         }
327 
328         CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
329 
330         /* Add the primary nids for the MGS */
331         i = 0;
332         sprintf(niduuid, "%s_%x", mgcname, i);
333         if (IS_SERVER(lsi)) {
334                 ptr = lsi->lsi_lmd->lmd_mgs;
335                 if (IS_MGS(lsi)) {
336                         /* Use local nids (including LO) */
337                         lnet_process_id_t id;
338                         while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
339                                 rc = do_lcfg(mgcname, id.nid,
340                                              LCFG_ADD_UUID, niduuid,
341                                              NULL, NULL, NULL);
342                         }
343                 } else {
344                         /* Use mgsnode= nids */
345                         /* mount -o mgsnode=nid */
346                         if (lsi->lsi_lmd->lmd_mgs) {
347                                 ptr = lsi->lsi_lmd->lmd_mgs;
348                         } else if (class_find_param(ptr, PARAM_MGSNODE,
349                                                     &ptr) != 0) {
350                                 CERROR("No MGS nids given.\n");
351                                 GOTO(out_free, rc = -EINVAL);
352                         }
353                         while (class_parse_nid(ptr, &nid, &ptr) == 0) {
354                                 rc = do_lcfg(mgcname, nid,
355                                              LCFG_ADD_UUID, niduuid,
356                                              NULL, NULL, NULL);
357                                 i++;
358                         }
359                 }
360         } else { /* client */
361                 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
362                 ptr = lsi->lsi_lmd->lmd_dev;
363                 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
364                         rc = do_lcfg(mgcname, nid,
365                                      LCFG_ADD_UUID, niduuid, NULL, NULL, NULL);
366                         i++;
367                         /* Stop at the first failover nid */
368                         if (*ptr == ':')
369                                 break;
370                 }
371         }
372         if (i == 0) {
373                 CERROR("No valid MGS nids found.\n");
374                 GOTO(out_free, rc = -EINVAL);
375         }
376         lsi->lsi_lmd->lmd_mgs_failnodes = 1;
377 
378         /* Random uuid for MGC allows easier reconnects */
379         OBD_ALLOC_PTR(uuid);
380         ll_generate_random_uuid(uuidc);
381         class_uuid_unparse(uuidc, uuid);
382 
383         /* Start the MGC */
384         rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
385                                  (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
386                                  niduuid, NULL, NULL);
387         OBD_FREE_PTR(uuid);
388         if (rc)
389                 GOTO(out_free, rc);
390 
391         /* Add any failover MGS nids */
392         i = 1;
393         while (ptr && ((*ptr == ':' ||
394                class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
395                 /* New failover node */
396                 sprintf(niduuid, "%s_%x", mgcname, i);
397                 j = 0;
398                 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
399                         j++;
400                         rc = do_lcfg(mgcname, nid,
401                                      LCFG_ADD_UUID, niduuid, NULL, NULL, NULL);
402                         if (*ptr == ':')
403                                 break;
404                 }
405                 if (j > 0) {
406                         rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
407                                      niduuid, NULL, NULL, NULL);
408                         i++;
409                 } else {
410                         /* at ":/fsname" */
411                         break;
412                 }
413         }
414         lsi->lsi_lmd->lmd_mgs_failnodes = i;
415 
416         obd = class_name2obd(mgcname);
417         if (!obd) {
418                 CERROR("Can't find mgcobd %s\n", mgcname);
419                 GOTO(out_free, rc = -ENOTCONN);
420         }
421 
422         rc = obd_set_info_async(NULL, obd->obd_self_export,
423                                 strlen(KEY_MGSSEC), KEY_MGSSEC,
424                                 strlen(mgssec), mgssec, NULL);
425         if (rc)
426                 GOTO(out_free, rc);
427 
428         /* Keep a refcount of servers/clients who started with "mount",
429            so we know when we can get rid of the mgc. */
430         atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
431 
432         /* Try all connections, but only once. */
433         recov_bk = 1;
434         rc = obd_set_info_async(NULL, obd->obd_self_export,
435                                 sizeof(KEY_INIT_RECOV_BACKUP),
436                                 KEY_INIT_RECOV_BACKUP,
437                                 sizeof(recov_bk), &recov_bk, NULL);
438         if (rc)
439                 /* nonfatal */
440                 CWARN("can't set %s %d\n", KEY_INIT_RECOV_BACKUP, rc);
441 
442         /* We connect to the MGS at setup, and don't disconnect until cleanup */
443         data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
444                                   OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
445                                   OBD_CONNECT_LVB_TYPE;
446 
447 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
448         data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
449 #else
450 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
451 #endif
452 
453         if (lmd_is_client(lsi->lsi_lmd) &&
454             lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
455                 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
456         data->ocd_version = LUSTRE_VERSION_CODE;
457         rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
458         if (rc) {
459                 CERROR("connect failed %d\n", rc);
460                 GOTO(out, rc);
461         }
462 
463         obd->u.cli.cl_mgc_mgsexp = exp;
464 
465 out:
466         /* Keep the mgc info in the sb. Note that many lsi's can point
467            to the same mgc.*/
468         lsi->lsi_mgc = obd;
469 out_free:
470         mutex_unlock(&mgc_start_lock);
471 
472         if (data)
473                 OBD_FREE_PTR(data);
474         if (mgcname)
475                 OBD_FREE(mgcname, len);
476         if (niduuid)
477                 OBD_FREE(niduuid, len + 2);
478         return rc;
479 }
480 
481 static int lustre_stop_mgc(struct super_block *sb)
482 {
483         struct lustre_sb_info *lsi = s2lsi(sb);
484         struct obd_device *obd;
485         char *niduuid = NULL, *ptr = NULL;
486         int i, rc = 0, len = 0;
487 
488         if (!lsi)
489                 return -ENOENT;
490         obd = lsi->lsi_mgc;
491         if (!obd)
492                 return -ENOENT;
493         lsi->lsi_mgc = NULL;
494 
495         mutex_lock(&mgc_start_lock);
496         LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
497         if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
498                 /* This is not fatal, every client that stops
499                    will call in here. */
500                 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
501                        atomic_read(&obd->u.cli.cl_mgc_refcount));
502                 GOTO(out, rc = -EBUSY);
503         }
504 
505         /* The MGC has no recoverable data in any case.
506          * force shutdown set in umount_begin */
507         obd->obd_no_recov = 1;
508 
509         if (obd->u.cli.cl_mgc_mgsexp) {
510                 /* An error is not fatal, if we are unable to send the
511                    disconnect mgs ping evictor cleans up the export */
512                 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
513                 if (rc)
514                         CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
515         }
516 
517         /* Save the obdname for cleaning the nid uuids, which are
518            obdname_XX */
519         len = strlen(obd->obd_name) + 6;
520         OBD_ALLOC(niduuid, len);
521         if (niduuid) {
522                 strcpy(niduuid, obd->obd_name);
523                 ptr = niduuid + strlen(niduuid);
524         }
525 
526         rc = class_manual_cleanup(obd);
527         if (rc)
528                 GOTO(out, rc);
529 
530         /* Clean the nid uuids */
531         if (!niduuid)
532                 GOTO(out, rc = -ENOMEM);
533 
534         for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
535                 sprintf(ptr, "_%x", i);
536                 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
537                              niduuid, NULL, NULL, NULL);
538                 if (rc)
539                         CERROR("del MDC UUID %s failed: rc = %d\n",
540                                niduuid, rc);
541         }
542 out:
543         if (niduuid)
544                 OBD_FREE(niduuid, len);
545 
546         /* class_import_put will get rid of the additional connections */
547         mutex_unlock(&mgc_start_lock);
548         return rc;
549 }
550 
551 /***************** lustre superblock **************/
552 
553 struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
554 {
555         struct lustre_sb_info *lsi;
556 
557         OBD_ALLOC_PTR(lsi);
558         if (!lsi)
559                 return NULL;
560         OBD_ALLOC_PTR(lsi->lsi_lmd);
561         if (!lsi->lsi_lmd) {
562                 OBD_FREE_PTR(lsi);
563                 return NULL;
564         }
565 
566         lsi->lsi_lmd->lmd_exclude_count = 0;
567         lsi->lsi_lmd->lmd_recovery_time_soft = 0;
568         lsi->lsi_lmd->lmd_recovery_time_hard = 0;
569         s2lsi_nocast(sb) = lsi;
570         /* we take 1 extra ref for our setup */
571         atomic_set(&lsi->lsi_mounts, 1);
572 
573         /* Default umount style */
574         lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
575 
576         return lsi;
577 }
578 
579 static int lustre_free_lsi(struct super_block *sb)
580 {
581         struct lustre_sb_info *lsi = s2lsi(sb);
582 
583         LASSERT(lsi != NULL);
584         CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
585 
586         /* someone didn't call server_put_mount. */
587         LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
588 
589         if (lsi->lsi_lmd != NULL) {
590                 if (lsi->lsi_lmd->lmd_dev != NULL)
591                         OBD_FREE(lsi->lsi_lmd->lmd_dev,
592                                  strlen(lsi->lsi_lmd->lmd_dev) + 1);
593                 if (lsi->lsi_lmd->lmd_profile != NULL)
594                         OBD_FREE(lsi->lsi_lmd->lmd_profile,
595                                  strlen(lsi->lsi_lmd->lmd_profile) + 1);
596                 if (lsi->lsi_lmd->lmd_mgssec != NULL)
597                         OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
598                                  strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
599                 if (lsi->lsi_lmd->lmd_opts != NULL)
600                         OBD_FREE(lsi->lsi_lmd->lmd_opts,
601                                  strlen(lsi->lsi_lmd->lmd_opts) + 1);
602                 if (lsi->lsi_lmd->lmd_exclude_count)
603                         OBD_FREE(lsi->lsi_lmd->lmd_exclude,
604                                  sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
605                                  lsi->lsi_lmd->lmd_exclude_count);
606                 if (lsi->lsi_lmd->lmd_mgs != NULL)
607                         OBD_FREE(lsi->lsi_lmd->lmd_mgs,
608                                  strlen(lsi->lsi_lmd->lmd_mgs) + 1);
609                 if (lsi->lsi_lmd->lmd_osd_type != NULL)
610                         OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
611                                  strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
612                 if (lsi->lsi_lmd->lmd_params != NULL)
613                         OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
614 
615                 OBD_FREE(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
616         }
617 
618         LASSERT(lsi->lsi_llsbi == NULL);
619         OBD_FREE(lsi, sizeof(*lsi));
620         s2lsi_nocast(sb) = NULL;
621 
622         return 0;
623 }
624 
625 /* The lsi has one reference for every server that is using the disk -
626    e.g. MDT, MGS, and potentially MGC */
627 int lustre_put_lsi(struct super_block *sb)
628 {
629         struct lustre_sb_info *lsi = s2lsi(sb);
630 
631         LASSERT(lsi != NULL);
632 
633         CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
634         if (atomic_dec_and_test(&lsi->lsi_mounts)) {
635                 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
636                         lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
637                         lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
638                         lsi->lsi_dt_dev = NULL;
639                         obd_disconnect(lsi->lsi_osd_exp);
640                         /* wait till OSD is gone */
641                         obd_zombie_barrier();
642                 }
643                 lustre_free_lsi(sb);
644                 return 1;
645         }
646         return 0;
647 }
648 
649 /*** SERVER NAME ***
650  * <FSNAME><SEPERATOR><TYPE><INDEX>
651  * FSNAME is between 1 and 8 characters (inclusive).
652  *      Excluded characters are '/' and ':'
653  * SEPERATOR is either ':' or '-'
654  * TYPE: "OST", "MDT", etc.
655  * INDEX: Hex representation of the index
656  */
657 
658 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
659  * @param [in] svname server name including type and index
660  * @param [out] fsname Buffer to copy filesystem name prefix into.
661  *  Must have at least 'strlen(fsname) + 1' chars.
662  * @param [out] endptr if endptr isn't NULL it is set to end of fsname
663  * rc < 0  on error
664  */
665 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
666 {
667         const char *dash;
668 
669         dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
670         for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
671                 ;
672         if (dash == svname)
673                 return -EINVAL;
674 
675         if (fsname != NULL) {
676                 strncpy(fsname, svname, dash - svname);
677                 fsname[dash - svname] = '\0';
678         }
679 
680         if (endptr != NULL)
681                 *endptr = dash;
682 
683         return 0;
684 }
685 EXPORT_SYMBOL(server_name2fsname);
686 
687 /**
688  * Get service name (svname) from string
689  * rc < 0 on error
690  * if endptr isn't NULL it is set to end of fsname *
691  */
692 int server_name2svname(const char *label, char *svname, const char **endptr,
693                        size_t svsize)
694 {
695         int rc;
696         const char *dash;
697 
698         /* We use server_name2fsname() just for parsing */
699         rc = server_name2fsname(label, NULL, &dash);
700         if (rc != 0)
701                 return rc;
702 
703         if (endptr != NULL)
704                 *endptr = dash;
705 
706         if (strlcpy(svname, dash + 1, svsize) >= svsize)
707                 return -E2BIG;
708 
709         return 0;
710 }
711 EXPORT_SYMBOL(server_name2svname);
712 
713 
714 /* Get the index from the obd name.
715    rc = server type, or
716    rc < 0  on error
717    if endptr isn't NULL it is set to end of name */
718 int server_name2index(const char *svname, __u32 *idx, const char **endptr)
719 {
720         unsigned long index;
721         int rc;
722         const char *dash;
723 
724         /* We use server_name2fsname() just for parsing */
725         rc = server_name2fsname(svname, NULL, &dash);
726         if (rc != 0)
727                 return rc;
728 
729         dash++;
730 
731         if (strncmp(dash, "MDT", 3) == 0)
732                 rc = LDD_F_SV_TYPE_MDT;
733         else if (strncmp(dash, "OST", 3) == 0)
734                 rc = LDD_F_SV_TYPE_OST;
735         else
736                 return -EINVAL;
737 
738         dash += 3;
739 
740         if (strncmp(dash, "all", 3) == 0) {
741                 if (endptr != NULL)
742                         *endptr = dash + 3;
743                 return rc | LDD_F_SV_ALL;
744         }
745 
746         index = simple_strtoul(dash, (char **)endptr, 16);
747         if (idx != NULL)
748                 *idx = index;
749 
750         /* Account for -mdc after index that is possible when specifying mdt */
751         if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
752                                       sizeof(LUSTRE_MDC_NAME)-1) == 0)
753                 *endptr += sizeof(LUSTRE_MDC_NAME);
754 
755         return rc;
756 }
757 EXPORT_SYMBOL(server_name2index);
758 
759 /*************** mount common between server and client ***************/
760 
761 /* Common umount */
762 int lustre_common_put_super(struct super_block *sb)
763 {
764         int rc;
765 
766         CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
767 
768         /* Drop a ref to the MGC */
769         rc = lustre_stop_mgc(sb);
770         if (rc && (rc != -ENOENT)) {
771                 if (rc != -EBUSY) {
772                         CERROR("Can't stop MGC: %d\n", rc);
773                         return rc;
774                 }
775                 /* BUSY just means that there's some other obd that
776                    needs the mgc.  Let him clean it up. */
777                 CDEBUG(D_MOUNT, "MGC still in use\n");
778         }
779         /* Drop a ref to the mounted disk */
780         lustre_put_lsi(sb);
781         lu_types_stop();
782         return rc;
783 }
784 EXPORT_SYMBOL(lustre_common_put_super);
785 
786 static void lmd_print(struct lustre_mount_data *lmd)
787 {
788         int i;
789 
790         PRINT_CMD(D_MOUNT, "  mount data:\n");
791         if (lmd_is_client(lmd))
792                 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
793         PRINT_CMD(D_MOUNT, "device:  %s\n", lmd->lmd_dev);
794         PRINT_CMD(D_MOUNT, "flags:   %x\n", lmd->lmd_flags);
795 
796         if (lmd->lmd_opts)
797                 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
798 
799         if (lmd->lmd_recovery_time_soft)
800                 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
801                           lmd->lmd_recovery_time_soft);
802 
803         if (lmd->lmd_recovery_time_hard)
804                 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
805                           lmd->lmd_recovery_time_hard);
806 
807         for (i = 0; i < lmd->lmd_exclude_count; i++) {
808                 PRINT_CMD(D_MOUNT, "exclude %d:  OST%04x\n", i,
809                           lmd->lmd_exclude[i]);
810         }
811 }
812 
813 /* Is this server on the exclusion list */
814 int lustre_check_exclusion(struct super_block *sb, char *svname)
815 {
816         struct lustre_sb_info *lsi = s2lsi(sb);
817         struct lustre_mount_data *lmd = lsi->lsi_lmd;
818         __u32 index;
819         int i, rc;
820 
821         rc = server_name2index(svname, &index, NULL);
822         if (rc != LDD_F_SV_TYPE_OST)
823                 /* Only exclude OSTs */
824                 return 0;
825 
826         CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
827                index, lmd->lmd_exclude_count, lmd->lmd_dev);
828 
829         for(i = 0; i < lmd->lmd_exclude_count; i++) {
830                 if (index == lmd->lmd_exclude[i]) {
831                         CWARN("Excluding %s (on exclusion list)\n", svname);
832                         return 1;
833                 }
834         }
835         return 0;
836 }
837 
838 /* mount -v  -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
839 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
840 {
841         const char *s1 = ptr, *s2;
842         __u32 index, *exclude_list;
843         int rc = 0, devmax;
844 
845         /* The shortest an ost name can be is 8 chars: -OST0000.
846            We don't actually know the fsname at this time, so in fact
847            a user could specify any fsname. */
848         devmax = strlen(ptr) / 8 + 1;
849 
850         /* temp storage until we figure out how many we have */
851         OBD_ALLOC(exclude_list, sizeof(index) * devmax);
852         if (!exclude_list)
853                 return -ENOMEM;
854 
855         /* we enter this fn pointing at the '=' */
856         while (*s1 && *s1 != ' ' && *s1 != ',') {
857                 s1++;
858                 rc = server_name2index(s1, &index, &s2);
859                 if (rc < 0) {
860                         CERROR("Can't parse server name '%s': rc = %d\n",
861                                s1, rc);
862                         break;
863                 }
864                 if (rc == LDD_F_SV_TYPE_OST)
865                         exclude_list[lmd->lmd_exclude_count++] = index;
866                 else
867                         CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
868                                (uint)(s2-s1), s1, rc);
869                 s1 = s2;
870                 /* now we are pointing at ':' (next exclude)
871                    or ',' (end of excludes) */
872                 if (lmd->lmd_exclude_count >= devmax)
873                         break;
874         }
875         if (rc >= 0) /* non-err */
876                 rc = 0;
877 
878         if (lmd->lmd_exclude_count) {
879                 /* permanent, freed in lustre_free_lsi */
880                 OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
881                           lmd->lmd_exclude_count);
882                 if (lmd->lmd_exclude) {
883                         memcpy(lmd->lmd_exclude, exclude_list,
884                                sizeof(index) * lmd->lmd_exclude_count);
885                 } else {
886                         rc = -ENOMEM;
887                         lmd->lmd_exclude_count = 0;
888                 }
889         }
890         OBD_FREE(exclude_list, sizeof(index) * devmax);
891         return rc;
892 }
893 
894 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
895 {
896         char   *tail;
897         int     length;
898 
899         if (lmd->lmd_mgssec != NULL) {
900                 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
901                 lmd->lmd_mgssec = NULL;
902         }
903 
904         tail = strchr(ptr, ',');
905         if (tail == NULL)
906                 length = strlen(ptr);
907         else
908                 length = tail - ptr;
909 
910         OBD_ALLOC(lmd->lmd_mgssec, length + 1);
911         if (lmd->lmd_mgssec == NULL)
912                 return -ENOMEM;
913 
914         memcpy(lmd->lmd_mgssec, ptr, length);
915         lmd->lmd_mgssec[length] = '\0';
916         return 0;
917 }
918 
919 static int lmd_parse_string(char **handle, char *ptr)
920 {
921         char   *tail;
922         int     length;
923 
924         if ((handle == NULL) || (ptr == NULL))
925                 return -EINVAL;
926 
927         if (*handle != NULL) {
928                 OBD_FREE(*handle, strlen(*handle) + 1);
929                 *handle = NULL;
930         }
931 
932         tail = strchr(ptr, ',');
933         if (tail == NULL)
934                 length = strlen(ptr);
935         else
936                 length = tail - ptr;
937 
938         OBD_ALLOC(*handle, length + 1);
939         if (*handle == NULL)
940                 return -ENOMEM;
941 
942         memcpy(*handle, ptr, length);
943         (*handle)[length] = '\0';
944 
945         return 0;
946 }
947 
948 /* Collect multiple values for mgsnid specifiers */
949 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
950 {
951         lnet_nid_t nid;
952         char *tail = *ptr;
953         char *mgsnid;
954         int   length;
955         int   oldlen = 0;
956 
957         /* Find end of nidlist */
958         while (class_parse_nid_quiet(tail, &nid, &tail) == 0) {}
959         length = tail - *ptr;
960         if (length == 0) {
961                 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
962                 return -EINVAL;
963         }
964 
965         if (lmd->lmd_mgs != NULL)
966                 oldlen = strlen(lmd->lmd_mgs) + 1;
967 
968         OBD_ALLOC(mgsnid, oldlen + length + 1);
969         if (mgsnid == NULL)
970                 return -ENOMEM;
971 
972         if (lmd->lmd_mgs != NULL) {
973                 /* Multiple mgsnid= are taken to mean failover locations */
974                 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
975                 mgsnid[oldlen - 1] = ':';
976                 OBD_FREE(lmd->lmd_mgs, oldlen);
977         }
978         memcpy(mgsnid + oldlen, *ptr, length);
979         mgsnid[oldlen + length] = '\0';
980         lmd->lmd_mgs = mgsnid;
981         *ptr = tail;
982 
983         return 0;
984 }
985 
986 /** Parse mount line options
987  * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
988  * dev is passed as device=uml1:/lustre by mount.lustre
989  */
990 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
991 {
992         char *s1, *s2, *devname = NULL;
993         struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
994         int rc = 0;
995 
996         LASSERT(lmd);
997         if (!options) {
998                 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that "
999                                    "/sbin/mount.lustre is installed.\n");
1000                 return -EINVAL;
1001         }
1002 
1003         /* Options should be a string - try to detect old lmd data */
1004         if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1005                 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of "
1006                                    "/sbin/mount.lustre.  Please install "
1007                                    "version %s\n", LUSTRE_VERSION_STRING);
1008                 return -EINVAL;
1009         }
1010         lmd->lmd_magic = LMD_MAGIC;
1011 
1012         OBD_ALLOC(lmd->lmd_params, 4096);
1013         if (lmd->lmd_params == NULL)
1014                 return -ENOMEM;
1015         lmd->lmd_params[0] = '\0';
1016 
1017         /* Set default flags here */
1018 
1019         s1 = options;
1020         while (*s1) {
1021                 int clear = 0;
1022                 int time_min = OBD_RECOVERY_TIME_MIN;
1023 
1024                 /* Skip whitespace and extra commas */
1025                 while (*s1 == ' ' || *s1 == ',')
1026                         s1++;
1027 
1028                 /* Client options are parsed in ll_options: eg. flock,
1029                    user_xattr, acl */
1030 
1031                 /* Parse non-ldiskfs options here. Rather than modifying
1032                    ldiskfs, we just zero these out here */
1033                 if (strncmp(s1, "abort_recov", 11) == 0) {
1034                         lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
1035                         clear++;
1036                 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
1037                         lmd->lmd_recovery_time_soft = max_t(int,
1038                                 simple_strtoul(s1 + 19, NULL, 10), time_min);
1039                         clear++;
1040                 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
1041                         lmd->lmd_recovery_time_hard = max_t(int,
1042                                 simple_strtoul(s1 + 19, NULL, 10), time_min);
1043                         clear++;
1044                 } else if (strncmp(s1, "noir", 4) == 0) {
1045                         lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
1046                         clear++;
1047                 } else if (strncmp(s1, "nosvc", 5) == 0) {
1048                         lmd->lmd_flags |= LMD_FLG_NOSVC;
1049                         clear++;
1050                 } else if (strncmp(s1, "nomgs", 5) == 0) {
1051                         lmd->lmd_flags |= LMD_FLG_NOMGS;
1052                         clear++;
1053                 } else if (strncmp(s1, "noscrub", 7) == 0) {
1054                         lmd->lmd_flags |= LMD_FLG_NOSCRUB;
1055                         clear++;
1056                 } else if (strncmp(s1, PARAM_MGSNODE,
1057                                    sizeof(PARAM_MGSNODE) - 1) == 0) {
1058                         s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
1059                         /* Assume the next mount opt is the first
1060                            invalid nid we get to. */
1061                         rc = lmd_parse_mgs(lmd, &s2);
1062                         if (rc)
1063                                 goto invalid;
1064                         clear++;
1065                 } else if (strncmp(s1, "writeconf", 9) == 0) {
1066                         lmd->lmd_flags |= LMD_FLG_WRITECONF;
1067                         clear++;
1068                 } else if (strncmp(s1, "update", 6) == 0) {
1069                         lmd->lmd_flags |= LMD_FLG_UPDATE;
1070                         clear++;
1071                 } else if (strncmp(s1, "virgin", 6) == 0) {
1072                         lmd->lmd_flags |= LMD_FLG_VIRGIN;
1073                         clear++;
1074                 } else if (strncmp(s1, "noprimnode", 10) == 0) {
1075                         lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
1076                         clear++;
1077                 } else if (strncmp(s1, "mgssec=", 7) == 0) {
1078                         rc = lmd_parse_mgssec(lmd, s1 + 7);
1079                         if (rc)
1080                                 goto invalid;
1081                         clear++;
1082                 /* ost exclusion list */
1083                 } else if (strncmp(s1, "exclude=", 8) == 0) {
1084                         rc = lmd_make_exclusion(lmd, s1 + 7);
1085                         if (rc)
1086                                 goto invalid;
1087                         clear++;
1088                 } else if (strncmp(s1, "mgs", 3) == 0) {
1089                         /* We are an MGS */
1090                         lmd->lmd_flags |= LMD_FLG_MGS;
1091                         clear++;
1092                 } else if (strncmp(s1, "svname=", 7) == 0) {
1093                         rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
1094                         if (rc)
1095                                 goto invalid;
1096                         clear++;
1097                 } else if (strncmp(s1, "param=", 6) == 0) {
1098                         int length;
1099                         char *tail = strchr(s1 + 6, ',');
1100                         if (tail == NULL)
1101                                 length = strlen(s1);
1102                         else
1103                                 length = tail - s1;
1104                         length -= 6;
1105                         strncat(lmd->lmd_params, s1 + 6, length);
1106                         strcat(lmd->lmd_params, " ");
1107                         clear++;
1108                 } else if (strncmp(s1, "osd=", 4) == 0) {
1109                         rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1110                         if (rc)
1111                                 goto invalid;
1112                         clear++;
1113                 }
1114                 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1115                    end of the options. */
1116                 else if (strncmp(s1, "device=", 7) == 0) {
1117                         devname = s1 + 7;
1118                         /* terminate options right before device.  device
1119                            must be the last one. */
1120                         *s1 = '\0';
1121                         break;
1122                 }
1123 
1124                 /* Find next opt */
1125                 s2 = strchr(s1, ',');
1126                 if (s2 == NULL) {
1127                         if (clear)
1128                                 *s1 = '\0';
1129                         break;
1130                 }
1131                 s2++;
1132                 if (clear)
1133                         memmove(s1, s2, strlen(s2) + 1);
1134                 else
1135                         s1 = s2;
1136         }
1137 
1138         if (!devname) {
1139                 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name "
1140                                    "(need mount option 'device=...')\n");
1141                 goto invalid;
1142         }
1143 
1144         s1 = strstr(devname, ":/");
1145         if (s1) {
1146                 ++s1;
1147                 lmd->lmd_flags |= LMD_FLG_CLIENT;
1148                 /* Remove leading /s from fsname */
1149                 while (*++s1 == '/') ;
1150                 /* Freed in lustre_free_lsi */
1151                 OBD_ALLOC(lmd->lmd_profile, strlen(s1) + 8);
1152                 if (!lmd->lmd_profile)
1153                         return -ENOMEM;
1154                 sprintf(lmd->lmd_profile, "%s-client", s1);
1155         }
1156 
1157         /* Freed in lustre_free_lsi */
1158         OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
1159         if (!lmd->lmd_dev)
1160                 return -ENOMEM;
1161         strcpy(lmd->lmd_dev, devname);
1162 
1163         /* Save mount options */
1164         s1 = options + strlen(options) - 1;
1165         while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1166                 *s1-- = 0;
1167         if (*options != 0) {
1168                 /* Freed in lustre_free_lsi */
1169                 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1170                 if (!lmd->lmd_opts)
1171                         return -ENOMEM;
1172                 strcpy(lmd->lmd_opts, options);
1173         }
1174 
1175         lmd_print(lmd);
1176         lmd->lmd_magic = LMD_MAGIC;
1177 
1178         return rc;
1179 
1180 invalid:
1181         CERROR("Bad mount options %s\n", options);
1182         return -EINVAL;
1183 }
1184 
1185 struct lustre_mount_data2 {
1186         void *lmd2_data;
1187         struct vfsmount *lmd2_mnt;
1188 };
1189 
1190 /** This is the entry point for the mount call into Lustre.
1191  * This is called when a server or client is mounted,
1192  * and this is where we start setting things up.
1193  * @param data Mount options (e.g. -o flock,abort_recov)
1194  */
1195 int lustre_fill_super(struct super_block *sb, void *data, int silent)
1196 {
1197         struct lustre_mount_data *lmd;
1198         struct lustre_mount_data2 *lmd2 = data;
1199         struct lustre_sb_info *lsi;
1200         int rc;
1201 
1202         CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1203 
1204         lsi = lustre_init_lsi(sb);
1205         if (!lsi)
1206                 return -ENOMEM;
1207         lmd = lsi->lsi_lmd;
1208 
1209         /*
1210          * Disable lockdep during mount, because mount locking patterns are
1211          * `special'.
1212          */
1213         lockdep_off();
1214 
1215         /*
1216          * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1217          */
1218         obd_zombie_barrier();
1219 
1220         /* Figure out the lmd from the mount options */
1221         if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
1222                 lustre_put_lsi(sb);
1223                 GOTO(out, rc = -EINVAL);
1224         }
1225 
1226         if (lmd_is_client(lmd)) {
1227                 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1228                 if (!client_fill_super) {
1229                         LCONSOLE_ERROR_MSG(0x165, "Nothing registered for "
1230                                            "client mount! Is the 'lustre' "
1231                                            "module loaded?\n");
1232                         lustre_put_lsi(sb);
1233                         rc = -ENODEV;
1234                 } else {
1235                         rc = lustre_start_mgc(sb);
1236                         if (rc) {
1237                                 lustre_put_lsi(sb);
1238                                 GOTO(out, rc);
1239                         }
1240                         /* Connect and start */
1241                         /* (should always be ll_fill_super) */
1242                         rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1243                         /* c_f_s will call lustre_common_put_super on failure */
1244                 }
1245         } else {
1246                 CERROR("This is client-side-only module, "
1247                        "cannot handle server mount.\n");
1248                 rc = -EINVAL;
1249         }
1250 
1251         /* If error happens in fill_super() call, @lsi will be killed there.
1252          * This is why we do not put it here. */
1253         GOTO(out, rc);
1254 out:
1255         if (rc) {
1256                 CERROR("Unable to mount %s (%d)\n",
1257                        s2lsi(sb) ? lmd->lmd_dev : "", rc);
1258         } else {
1259                 CDEBUG(D_SUPER, "Mount %s complete\n",
1260                        lmd->lmd_dev);
1261         }
1262         lockdep_on();
1263         return rc;
1264 }
1265 
1266 
1267 /* We can't call ll_fill_super by name because it lives in a module that
1268    must be loaded after this one. */
1269 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1270                                                   struct vfsmount *mnt))
1271 {
1272         client_fill_super = cfs;
1273 }
1274 EXPORT_SYMBOL(lustre_register_client_fill_super);
1275 
1276 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1277 {
1278         kill_super_cb = cfs;
1279 }
1280 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1281 
1282 /***************** FS registration ******************/
1283 struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1284                                 const char *devname, void *data)
1285 {
1286         struct lustre_mount_data2 lmd2 = { data, NULL };
1287 
1288         return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1289 }
1290 
1291 void lustre_kill_super(struct super_block *sb)
1292 {
1293         struct lustre_sb_info *lsi = s2lsi(sb);
1294 
1295         if (kill_super_cb && lsi && !IS_SERVER(lsi))
1296                 (*kill_super_cb)(sb);
1297 
1298         kill_anon_super(sb);
1299 }
1300 
1301 /** Register the "lustre" fs type
1302  */
1303 struct file_system_type lustre_fs_type = {
1304         .owner  = THIS_MODULE,
1305         .name    = "lustre",
1306         .mount  = lustre_mount,
1307         .kill_sb      = lustre_kill_super,
1308         .fs_flags     = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
1309                         FS_HAS_FIEMAP | FS_RENAME_DOES_D_MOVE,
1310 };
1311 
1312 int lustre_register_fs(void)
1313 {
1314         return register_filesystem(&lustre_fs_type);
1315 }
1316 
1317 int lustre_unregister_fs(void)
1318 {
1319         return unregister_filesystem(&lustre_fs_type);
1320 }
1321 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us