Version:  2.0.40 2.2.26 2.4.37 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 3.17 3.18 3.19

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

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