Whamcloud - gitweb
changes to protect directory splitting from concurrent modifies/lookups:
[fs/lustre-release.git] / lustre / mds / mds_lmv.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  linux/mds/mds_lov.c
5  *  Lustre Metadata Server (mds) handling of striped file data
6  *
7  *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
11  *   Lustre is free software; you can redistribute it and/or
12  *   modify it under the terms of version 2 of the GNU General Public
13  *   License as published by the Free Software Foundation.
14  *
15  *   Lustre is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with Lustre; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 #ifndef EXPORT_SYMTAB
26 # define EXPORT_SYMTAB
27 #endif
28 #define DEBUG_SUBSYSTEM S_MDS
29
30 #include <linux/module.h>
31 #include <linux/lustre_mds.h>
32 #include <linux/lustre_idl.h>
33 #include <linux/obd_class.h>
34 #include <linux/obd_lov.h>
35 #include <linux/lustre_lib.h>
36 #include <linux/lustre_fsfilt.h>
37
38 #include "mds_internal.h"
39
40
41 /*
42  * TODO:
43  *   - magic in mea struct
44  *   - error handling is totally missed
45  */
46
47 int mds_lmv_connect(struct obd_device *obd, char * lmv_name)
48 {
49         struct mds_obd *mds = &obd->u.mds;
50         struct lustre_handle conn = {0,};
51         int valsize, mdsize;
52         int rc;
53         ENTRY;
54
55         if (IS_ERR(mds->mds_lmv_obd))
56                 RETURN(PTR_ERR(mds->mds_lmv_obd));
57
58         if (mds->mds_lmv_obd)
59                 RETURN(0);
60
61         mds->mds_lmv_obd = class_name2obd(lmv_name);
62         if (!mds->mds_lmv_obd) {
63                 CERROR("MDS cannot locate LMV %s\n",
64                        lmv_name);
65                 mds->mds_lmv_obd = ERR_PTR(-ENOTCONN);
66                 RETURN(-ENOTCONN);
67         }
68
69         rc = obd_connect(&conn, mds->mds_lmv_obd, &obd->obd_uuid);
70         if (rc) {
71                 CERROR("MDS cannot connect to LMV %s (%d)\n",
72                        lmv_name, rc);
73                 mds->mds_lmv_obd = ERR_PTR(rc);
74                 RETURN(rc);
75         }
76         mds->mds_lmv_exp = class_conn2export(&conn);
77         if (mds->mds_lmv_exp == NULL)
78                 CERROR("can't get export!\n");
79
80         rc = obd_register_observer(mds->mds_lmv_obd, obd);
81         if (rc) {
82                 CERROR("MDS cannot register as observer of LMV %s (%d)\n",
83                        lmv_name, rc);
84                 GOTO(err_discon, rc);
85         }
86
87         /* retrieve size of EA */
88         rc = obd_get_info(mds->mds_lmv_exp, strlen("mdsize"), "mdsize", 
89                           &valsize, &mdsize);
90         if (rc) 
91                 GOTO(err_reg, rc);
92         if (mdsize > mds->mds_max_mdsize)
93                 mds->mds_max_mdsize = mdsize;
94
95         /* find our number in LMV cluster */
96         rc = obd_get_info(mds->mds_lmv_exp, strlen("mdsnum"), "mdsnum", 
97                           &valsize, &mdsize);
98         if (rc) 
99                 GOTO(err_reg, rc);
100         mds->mds_num = mdsize;
101
102         rc = obd_set_info(mds->mds_lmv_exp, strlen("inter_mds"),
103                                 "inter_mds", 0, NULL);
104         if (rc)
105                 GOTO(err_reg, rc);
106         RETURN(0);
107
108 err_reg:
109         RETURN(rc);
110
111 err_discon:
112         /* FIXME: cleanups here! */
113         obd_disconnect(mds->mds_lmv_exp, 0);
114         mds->mds_lmv_exp = NULL;
115         mds->mds_lmv_obd = ERR_PTR(rc);
116         RETURN(rc);
117 }
118
119 int mds_lmv_postsetup(struct obd_device *obd)
120 {
121         struct mds_obd *mds = &obd->u.mds;
122         ENTRY;
123         if (mds->mds_lmv_exp)
124                 obd_init_ea_size(mds->mds_lmv_exp, mds->mds_max_mdsize,
125                                  mds->mds_max_cookiesize);
126         RETURN(0);
127 }
128
129 int mds_lmv_disconnect(struct obd_device *obd, int flags)
130 {
131         struct mds_obd *mds = &obd->u.mds;
132         int rc = 0;
133         ENTRY;
134
135         if (!IS_ERR(mds->mds_lmv_obd) && mds->mds_lmv_exp != NULL) {
136
137                 obd_register_observer(mds->mds_lmv_obd, NULL);
138
139                 rc = obd_disconnect(mds->mds_lmv_exp, flags);
140                 /* if obd_disconnect fails (probably because the
141                  * export was disconnected by class_disconnect_exports)
142                  * then we just need to drop our ref. */
143                 if (rc != 0)
144                         class_export_put(mds->mds_lmv_exp);
145                 mds->mds_lmv_exp = NULL;
146                 mds->mds_lmv_obd = NULL;
147         }
148
149         RETURN(rc);
150 }
151
152
153 int mds_get_lmv_attr(struct obd_device *obd, struct inode *inode,
154                         struct mea **mea, int *mea_size)
155 {
156         struct mds_obd *mds = &obd->u.mds;
157         int rc;
158         ENTRY;
159
160         if (!mds->mds_lmv_obd)
161                 RETURN(0);
162
163         /* first calculate mea size */
164         *mea_size = obd_alloc_diskmd(mds->mds_lmv_exp,
165                                      (struct lov_mds_md **)mea);
166         /* FIXME: error handling here */
167         LASSERT(*mea != NULL);
168
169         down(&inode->i_sem);
170         rc = fsfilt_get_md(obd, inode, *mea, *mea_size);
171         up(&inode->i_sem);
172         /* FIXME: error handling here */
173         if (rc <= 0) {
174                 OBD_FREE(*mea, *mea_size);
175                 *mea = NULL;
176         }
177         if (rc > 0)
178                 rc = 0;
179         RETURN(rc);
180 }
181
182 struct dir_entry {
183         __u16   namelen;
184         __u16   mds;
185         __u32   ino;
186         __u32   generation;
187         char    name[0];
188 };
189
190 #define DIR_PAD                 4
191 #define DIR_ROUND               (DIR_PAD - 1)
192 #define DIR_REC_LEN(name_len)   (((name_len) + 12 + DIR_ROUND) & ~DIR_ROUND)
193
194 /* this struct holds dir entries for particular MDS to be flushed */
195 struct dir_cache {
196         struct list_head list;
197         void *cur;
198         int free;
199         int cached;
200         struct obdo oa;
201         struct brw_page brwc;
202 };
203
204 struct dirsplit_control {
205         struct obd_device *obd;
206         struct inode *dir;
207         struct dentry *dentry;
208         struct mea *mea;
209         struct dir_cache *cache;
210 };
211
212 static int dc_new_page_to_cache(struct dir_cache * dirc)
213 {
214         struct page *page;
215
216         if (!list_empty(&dirc->list) && dirc->free > sizeof(__u16)) {
217                 /* current page became full, mark the end */
218                 struct dir_entry *de = dirc->cur;
219                 de->namelen = 0;
220         }
221
222         page = alloc_page(GFP_KERNEL);
223         if (page == NULL)
224                 return -ENOMEM;
225         list_add_tail(&page->list, &dirc->list);
226         dirc->cur = page_address(page);
227         dirc->free = PAGE_SIZE;
228         return 0;
229 }
230
231 static int retrieve_generation_numbers(struct dirsplit_control *dc, void *buf)
232 {
233         struct mds_obd *mds = &dc->obd->u.mds;
234         struct dir_entry *de;
235         struct dentry *dentry;
236         char * end;
237         
238         end = buf + PAGE_SIZE;
239         de = (struct dir_entry *) buf;
240         while ((char *) de < end && de->namelen) {
241                 /* lookup an inode */
242                 LASSERT(de->namelen <= 255);
243                 dentry = ll_lookup_one_len(de->name, dc->dentry, de->namelen);
244                 if (IS_ERR(dentry)) {
245                         CERROR("can't lookup %*s: %d\n", de->namelen,
246                                de->name, (int) PTR_ERR(dentry));
247                         goto next;
248                 }
249                 if (dentry->d_inode != NULL) {
250                         de->mds = mds->mds_num;
251                         de->ino = dentry->d_inode->i_ino;
252                         de->generation = dentry->d_inode->i_generation;
253                 } else if (dentry->d_flags & DCACHE_CROSS_REF) {
254                         de->mds = dentry->d_mdsnum;
255                         de->ino = dentry->d_inum;
256                         de->generation = dentry->d_generation;
257                 } else {
258                         CERROR("can't lookup %*s\n", de->namelen, de->name);
259                         goto next;
260                 }
261                 l_dput(dentry);
262
263 next:
264                 de = (struct dir_entry *)
265                         ((char *) de + DIR_REC_LEN(de->namelen));
266         }
267         return 0;
268 }
269
270 static int flush_buffer_onto_mds(struct dirsplit_control *dc, int mdsnum)
271 {
272         struct mds_obd *mds = &dc->obd->u.mds;
273         struct dir_cache *ca;
274         struct list_head *cur, *tmp;
275         ENTRY; 
276         ca = dc->cache + mdsnum;
277
278         if (ca->free > sizeof(__u16)) {
279                 /* current page became full, mark the end */
280                 struct dir_entry *de = ca->cur;
281                 de->namelen = 0;
282         }
283
284         list_for_each_safe(cur, tmp, &ca->list) {
285                 struct page *page;
286
287                 page = list_entry(cur, struct page, list);
288                 LASSERT(page != NULL);
289
290                 retrieve_generation_numbers(dc, page_address(page));
291
292                 ca->brwc.pg = page;
293                 ca->brwc.off = 0;
294                 ca->brwc.count = PAGE_SIZE;
295                 ca->brwc.flag = 0;
296                 ca->oa.o_mds = mdsnum;
297                 obd_brw(OBD_BRW_WRITE, mds->mds_lmv_exp, &ca->oa,
298                                 (struct lov_stripe_md *) dc->mea,
299                                 1, &ca->brwc, NULL);
300
301                 list_del(&page->list);
302                 __free_page(page);
303         }
304         RETURN(0);
305 }
306
307 static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
308                    ino_t ino, unsigned int d_type)
309 {
310         struct dirsplit_control *dc = __buf;
311         struct mds_obd *mds = &dc->obd->u.mds;
312         struct dir_cache *ca;
313         struct dir_entry *de;
314         int newmds;
315         char *n;
316         ENTRY;
317
318         if (name[0] == '.' && (namlen == 1 ||
319                                 (namlen == 2 && name[1] == '.'))) {
320                 /* skip special entries */
321                 RETURN(0);
322         }
323
324         LASSERT(dc != NULL);
325         newmds = mea_name2idx(dc->mea, (char *) name, namlen);
326
327         if (newmds == mds->mds_num) {
328                 /* this entry remains on the current MDS, skip moving */
329                 RETURN(0);
330         }
331         
332         OBD_ALLOC(n, namlen + 1);
333         memcpy(n, name, namlen);
334         n[namlen] = (char) 0;
335         
336         OBD_FREE(n, namlen + 1);
337
338         /* check for space in buffer for new entry */
339         ca = dc->cache + newmds;
340         if (DIR_REC_LEN(namlen) > ca->free) {
341                 int err = dc_new_page_to_cache(ca);
342                 LASSERT(err == 0);
343         }
344         
345         /* insert found entry into buffer to be flushed later */
346         /* NOTE: we'll fill generations number later, because we
347          * it's stored in inode, thus we need to lookup an entry,
348          * but directory is locked for readdir(), so we delay this */
349         de = ca->cur;
350         de->ino = ino;
351         de->mds = d_type;
352         de->namelen = namlen;
353         memcpy(de->name, name, namlen);
354         ca->cur += DIR_REC_LEN(namlen);
355         ca->free -= DIR_REC_LEN(namlen);
356         ca->cached++;
357
358         RETURN(0);
359 }
360
361 int scan_and_distribute(struct obd_device *obd, struct dentry *dentry,
362                                 struct mea *mea)
363 {
364         struct inode *dir = dentry->d_inode;
365         struct dirsplit_control dc;
366         struct file * file;
367         int err, i, nlen;
368         char *file_name;
369
370         nlen = strlen("__iopen__/") + 10 + 1;
371         OBD_ALLOC(file_name, nlen);
372         if (!file_name)
373                 RETURN(-ENOMEM);
374         i = sprintf(file_name, "__iopen__/0x%lx", dentry->d_inode->i_ino);
375
376         file = filp_open(file_name, O_RDONLY, 0);
377         if (IS_ERR(file)) {
378                 CERROR("can't open directory %s: %d\n",
379                                 file_name, (int) PTR_ERR(file));
380                 OBD_FREE(file_name, nlen);
381                 RETURN(PTR_ERR(file));
382         }
383
384         memset(&dc, 0, sizeof(dc));
385         dc.obd = obd;
386         dc.dir = dir;
387         dc.dentry = dentry;
388         dc.mea = mea;
389         OBD_ALLOC(dc.cache, sizeof(struct dir_cache) * mea->mea_count);
390         LASSERT(dc.cache != NULL);
391         for (i = 0; i < mea->mea_count; i++) {
392                 INIT_LIST_HEAD(&dc.cache[i].list);
393                 dc.cache[i].free = 0;
394                 dc.cache[i].cached = 0;
395         }
396
397         err = vfs_readdir(file, filldir, &dc);
398         
399         filp_close(file, 0);
400
401         for (i = 0; i < mea->mea_count; i++) {
402                 if (dc.cache[i].cached)
403                         flush_buffer_onto_mds(&dc, i);
404         }
405
406         OBD_FREE(dc.cache, sizeof(struct dir_cache) * mea->mea_count);
407         OBD_FREE(file_name, nlen);
408
409         return 0;
410 }
411
412 #define MAX_DIR_SIZE    (64 * 1024)
413
414 int mds_splitting_expected(struct obd_device *obd, struct dentry *dentry)
415 {
416         struct mds_obd *mds = &obd->u.mds;
417         struct mea *mea = NULL;
418         int rc, size;
419
420         /* clustered MD ? */
421         if (!mds->mds_lmv_obd)
422                 RETURN(0);
423
424         /* inode exist? */
425         if (dentry->d_inode == NULL)
426                 return 0;
427
428         /* a dir can be splitted only */
429         if (!S_ISDIR(dentry->d_inode->i_mode))
430                 return 0;
431
432         /* large enough to be splitted? */
433         if (dentry->d_inode->i_size < MAX_DIR_SIZE)
434                 return 0;
435
436         /* don't split root directory */
437         if (dentry->d_inode->i_ino == mds->mds_rootfid.id)
438                 return 0;
439
440         mds_get_lmv_attr(obd, dentry->d_inode, &mea, &size);
441         if (mea) {
442                 /* already splitted or slave object: shouldn't be splitted */
443                 rc = 0;
444         } else {
445                 /* may be splitted */
446                 rc = 1;
447         }
448
449         if (mea)
450                 OBD_FREE(mea, size);
451         RETURN(rc);
452 }
453
454 /*
455  * must not be called on already splitted directories
456  */
457 int mds_try_to_split_dir(struct obd_device *obd,
458                          struct dentry *dentry, struct mea **mea, int nstripes)
459 {
460         struct inode *dir = dentry->d_inode;
461         struct mds_obd *mds = &obd->u.mds;
462         struct mea *tmea = NULL;
463         struct obdo *oa = NULL;
464         int rc, mea_size = 0;
465         void *handle;
466         ENTRY;
467
468         /* TODO: optimization possible - we already may have mea here */
469         if (!mds_splitting_expected(obd, dentry))
470                 RETURN(0);
471         LASSERT(mea == NULL || *mea == NULL);
472
473         CDEBUG(D_OTHER, "%s: split directory %u/%lu/%lu\n",
474                obd->obd_name, mds->mds_num, dir->i_ino,
475                (unsigned long) dir->i_generation);
476
477         if (mea == NULL)
478                 mea = &tmea;
479         mea_size = obd_size_diskmd(mds->mds_lmv_exp, NULL);
480
481         /* FIXME: Actually we may only want to allocate enough space for
482          * necessary amount of stripes, but on the other hand with this
483          * approach of allocating maximal possible amount of MDS slots,
484          * it would be easier to split the dir over more MDSes */
485         rc = obd_alloc_diskmd(mds->mds_lmv_exp, (void *) mea);
486         if (!(*mea))
487                 RETURN(-ENOMEM);
488         (*mea)->mea_count = nstripes;
489        
490         /* 1) create directory objects on slave MDS'es */
491         /* FIXME: should this be OBD method? */
492         oa = obdo_alloc();
493         /* FIXME: error handling here */
494         LASSERT(oa != NULL);
495         oa->o_id = dir->i_ino;
496         oa->o_generation = dir->i_generation;
497         obdo_from_inode(oa, dir, OBD_MD_FLTYPE | OBD_MD_FLATIME |
498                         OBD_MD_FLMTIME | OBD_MD_FLCTIME |
499                         OBD_MD_FLUID | OBD_MD_FLGID);
500         oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
501         oa->o_valid |= OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
502         oa->o_mode = dir->i_mode;
503         CDEBUG(D_OTHER, "%s: create subdirs with mode %o, uid %u, gid %u\n",
504                         obd->obd_name, dir->i_mode, dir->i_uid, dir->i_gid);
505                         
506         rc = obd_create(mds->mds_lmv_exp, oa,
507                         (struct lov_stripe_md **) mea, NULL);
508         /* FIXME: error handling here */
509         LASSERT(rc == 0);
510         CDEBUG(D_OTHER, "%d dirobjects created\n",
511                (int) (*mea)->mea_count);
512
513         /* 2) update dir attribute */
514         down(&dir->i_sem);
515         handle = fsfilt_start(obd, dir, FSFILT_OP_SETATTR, NULL);
516         LASSERT(!IS_ERR(handle));
517         rc = fsfilt_set_md(obd, dir, handle, *mea, mea_size);
518         LASSERT(rc == 0);
519         fsfilt_commit(obd, dir, handle, 0);
520         LASSERT(rc == 0);
521         up(&dir->i_sem);
522         obdo_free(oa);
523
524         /* 3) read through the dir and distribute it over objects */
525         scan_and_distribute(obd, dentry, *mea);
526
527         if (mea == &tmea)
528                 obd_free_diskmd(mds->mds_lmv_exp,
529                                 (struct lov_mds_md **) mea);
530         RETURN(1);
531 }
532
533 static int filter_start_page_write(struct inode *inode,
534                                    struct niobuf_local *lnb)
535 {
536         struct page *page = alloc_pages(GFP_HIGHUSER, 0);
537         if (page == NULL) {
538                 CERROR("no memory for a temp page\n");
539                 RETURN(lnb->rc = -ENOMEM);
540         }
541         POISON_PAGE(page, 0xf1);
542         page->index = lnb->offset >> PAGE_SHIFT;
543         lnb->page = page;
544
545         return 0;
546 }
547
548 struct dentry *filter_fid2dentry(struct obd_device *obd,
549                                  struct dentry *dir_dentry,
550                                  obd_gr group, obd_id id);
551
552 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
553                 int objcount, struct obd_ioobj *obj,
554                 int niocount, struct niobuf_remote *nb,
555                 struct niobuf_local *res,
556                 struct obd_trans_info *oti)
557 {
558         struct mds_obd *mds = &exp->exp_obd->u.mds;
559         struct niobuf_remote *rnb;
560         struct niobuf_local *lnb = NULL;
561         int rc = 0, i, tot_bytes = 0;
562         unsigned long now = jiffies;
563         struct dentry *dentry;
564         struct ll_fid fid;
565         ENTRY;
566         LASSERT(objcount == 1);
567         LASSERT(obj->ioo_bufcnt > 0);
568
569         memset(res, 0, niocount * sizeof(*res));
570
571         fid.id = obj->ioo_id;
572         fid.generation = obj->ioo_gr;
573         dentry = mds_fid2dentry(mds, &fid, NULL);
574         LASSERT(!IS_ERR(dentry));
575
576         if (dentry->d_inode == NULL) {
577                 CERROR("trying to BRW to non-existent file "LPU64"\n",
578                        obj->ioo_id);
579                 l_dput(dentry);
580                 GOTO(cleanup, rc = -ENOENT);
581         }
582
583         if (time_after(jiffies, now + 15 * HZ))
584                 CERROR("slow preprw_write setup %lus\n", (jiffies - now) / HZ);
585         else
586                 CDEBUG(D_INFO, "preprw_write setup: %lu jiffies\n",
587                        (jiffies - now));
588
589         for (i = 0, rnb = nb, lnb = res; i < obj->ioo_bufcnt;
590              i++, lnb++, rnb++) {
591                 lnb->dentry = dentry;
592                 lnb->offset = rnb->offset;
593                 lnb->len    = rnb->len;
594                 lnb->flags  = rnb->flags;
595
596                 rc = filter_start_page_write(dentry->d_inode, lnb);
597                 if (rc) {
598                         CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR, "page err %u@"
599                                LPU64" %u/%u %p: rc %d\n", lnb->len, lnb->offset,
600                                i, obj->ioo_bufcnt, dentry, rc);
601                         while (lnb-- > res)
602                                 __free_pages(lnb->page, 0);
603                         l_dput(dentry);
604                         GOTO(cleanup, rc);
605                 }
606                 tot_bytes += lnb->len;
607         }
608
609         if (time_after(jiffies, now + 15 * HZ))
610                 CERROR("slow start_page_write %lus\n", (jiffies - now) / HZ);
611         else
612                 CDEBUG(D_INFO, "start_page_write: %lu jiffies\n",
613                        (jiffies - now));
614
615         EXIT;
616 cleanup:
617         return rc;
618 }
619
620 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
621                  int objcount, struct obd_ioobj *obj, int niocount,
622                  struct niobuf_local *res, struct obd_trans_info *oti,
623                  int retcode)
624 {
625         struct obd_device *obd = exp->exp_obd;
626         struct niobuf_local *lnb;
627         struct inode *inode = NULL;
628         int rc = 0, i, cleanup_phase = 0, err, entries = 0;
629         ENTRY;
630
631         LASSERT(objcount == 1);
632         LASSERT(current->journal_info == NULL);
633
634         cleanup_phase = 1;
635         inode = res->dentry->d_inode;
636
637         for (i = 0, lnb = res; i < obj->ioo_bufcnt; i++, lnb++) {
638                 char *end, *buf;
639                 struct dir_entry *de;
640
641                 buf = kmap(lnb->page);
642                 LASSERT(buf != NULL);
643                 end = buf + lnb->len;
644                 de = (struct dir_entry *) buf;
645                 while ((char *) de < end && de->namelen) {
646                         err = fsfilt_add_dir_entry(obd, res->dentry, de->name,
647                                                    de->namelen, de->ino,
648                                                    de->generation, de->mds);
649                         /* FIXME: remove entries from the original dir */
650 #warning "removing entries from the original dir"
651                         LASSERT(err == 0);
652                         de = (struct dir_entry *)
653                                 ((char *) de + DIR_REC_LEN(de->namelen));
654                         entries++;
655                 }
656                 kunmap(buf);
657         }
658
659         for (i = 0, lnb = res; i < obj->ioo_bufcnt; i++, lnb++)
660                 __free_page(lnb->page);
661         l_dput(res->dentry);
662
663         RETURN(rc);
664 }
665
666 int mds_choose_mdsnum(struct obd_device *obd, const char *name, int len, int flags)
667 {
668         struct lmv_obd *lmv;
669         struct mds_obd *mds = &obd->u.mds;
670         int i = mds->mds_num;
671
672         if (flags & REC_REINT_CREATE) { 
673                 i = mds->mds_num;
674         } else if (mds->mds_lmv_exp) {
675                 lmv = &mds->mds_lmv_exp->exp_obd->u.lmv;
676                 i = raw_name2idx(lmv->count, name, len);
677         }
678         RETURN(i);
679 }
680