1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre Metadata Server (mds) handling of striped file data
7 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
26 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_MDS
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>
38 #include "mds_internal.h"
43 * - magic in mea struct
44 * - error handling is totally missed
47 int mds_lmv_connect(struct obd_device *obd, char * lmv_name)
49 struct mds_obd *mds = &obd->u.mds;
50 struct lustre_handle conn = {0,};
55 if (IS_ERR(mds->mds_lmv_obd))
56 RETURN(PTR_ERR(mds->mds_lmv_obd));
61 mds->mds_lmv_obd = class_name2obd(lmv_name);
62 if (!mds->mds_lmv_obd) {
63 CERROR("MDS cannot locate LMV %s\n",
65 mds->mds_lmv_obd = ERR_PTR(-ENOTCONN);
69 rc = obd_connect(&conn, mds->mds_lmv_obd, &obd->obd_uuid);
71 CERROR("MDS cannot connect to LMV %s (%d)\n",
73 mds->mds_lmv_obd = ERR_PTR(rc);
76 mds->mds_lmv_exp = class_conn2export(&conn);
77 if (mds->mds_lmv_exp == NULL)
78 CERROR("can't get export!\n");
80 rc = obd_register_observer(mds->mds_lmv_obd, obd);
82 CERROR("MDS cannot register as observer of LMV %s (%d)\n",
87 /* retrieve size of EA */
88 rc = obd_get_info(mds->mds_lmv_exp, strlen("mdsize"), "mdsize",
92 if (mdsize > mds->mds_max_mdsize)
93 mds->mds_max_mdsize = mdsize;
95 /* find our number in LMV cluster */
96 rc = obd_get_info(mds->mds_lmv_exp, strlen("mdsnum"), "mdsnum",
100 mds->mds_num = mdsize;
102 rc = obd_set_info(mds->mds_lmv_exp, strlen("inter_mds"),
103 "inter_mds", 0, NULL);
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);
119 int mds_lmv_postsetup(struct obd_device *obd)
121 struct mds_obd *mds = &obd->u.mds;
123 if (mds->mds_lmv_exp)
124 obd_init_ea_size(mds->mds_lmv_exp, mds->mds_max_mdsize,
125 mds->mds_max_cookiesize);
129 int mds_lmv_disconnect(struct obd_device *obd, int flags)
131 struct mds_obd *mds = &obd->u.mds;
135 if (!IS_ERR(mds->mds_lmv_obd) && mds->mds_lmv_exp != NULL) {
137 obd_register_observer(mds->mds_lmv_obd, NULL);
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. */
144 class_export_put(mds->mds_lmv_exp);
145 mds->mds_lmv_exp = NULL;
146 mds->mds_lmv_obd = NULL;
153 int mds_get_lmv_attr(struct obd_device *obd, struct inode *inode,
154 struct mea **mea, int *mea_size)
156 struct mds_obd *mds = &obd->u.mds;
160 if (!mds->mds_lmv_obd)
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);
170 rc = fsfilt_get_md(obd, inode, *mea, *mea_size);
172 /* FIXME: error handling here */
174 OBD_FREE(*mea, *mea_size);
192 #define DIR_ROUND (DIR_PAD - 1)
193 #define DIR_REC_LEN(name_len) (((name_len) + 12 + DIR_ROUND) & ~DIR_ROUND)
195 /* this struct holds dir entries for particular MDS to be flushed */
197 struct list_head list;
202 struct brw_page brwc;
205 struct dirsplit_control {
206 struct obd_device *obd;
208 struct dentry *dentry;
210 struct dir_cache *cache;
213 static int dc_new_page_to_cache(struct dir_cache * dirc)
217 if (!list_empty(&dirc->list) && dirc->free > sizeof(__u16)) {
218 /* current page became full, mark the end */
219 struct dir_entry *de = dirc->cur;
223 page = alloc_page(GFP_KERNEL);
226 list_add_tail(&page->list, &dirc->list);
227 dirc->cur = page_address(page);
228 dirc->free = PAGE_SIZE;
232 static int retrieve_generation_numbers(struct dirsplit_control *dc, void *buf)
234 struct mds_obd *mds = &dc->obd->u.mds;
235 struct dir_entry *de;
236 struct dentry *dentry;
239 end = buf + PAGE_SIZE;
240 de = (struct dir_entry *) buf;
241 while ((char *) de < end && de->namelen) {
242 /* lookup an inode */
243 LASSERT(de->namelen <= 255);
244 dentry = ll_lookup_one_len(de->name, dc->dentry, de->namelen);
245 if (IS_ERR(dentry)) {
246 CERROR("can't lookup %*s: %d\n", de->namelen,
247 de->name, (int) PTR_ERR(dentry));
250 if (dentry->d_inode != NULL) {
251 de->mds = mds->mds_num;
252 de->ino = dentry->d_inode->i_ino;
253 de->generation = dentry->d_inode->i_generation;
254 } else if (dentry->d_flags & DCACHE_CROSS_REF) {
255 de->mds = dentry->d_mdsnum;
256 de->ino = dentry->d_inum;
257 de->generation = dentry->d_generation;
259 CERROR("can't lookup %*s\n", de->namelen, de->name);
265 de = (struct dir_entry *)
266 ((char *) de + DIR_REC_LEN(de->namelen));
271 static int flush_buffer_onto_mds(struct dirsplit_control *dc, int mdsnum)
273 struct mds_obd *mds = &dc->obd->u.mds;
274 struct list_head *cur, *tmp;
275 struct dir_cache *ca;
278 ca = dc->cache + mdsnum;
280 if (ca->free > sizeof(__u16)) {
281 /* current page became full, mark the end */
282 struct dir_entry *de = ca->cur;
286 list_for_each_safe(cur, tmp, &ca->list) {
289 page = list_entry(cur, struct page, list);
290 LASSERT(page != NULL);
292 retrieve_generation_numbers(dc, page_address(page));
296 ca->brwc.count = PAGE_SIZE;
298 ca->oa.o_mds = mdsnum;
299 rc = obd_brw(OBD_BRW_WRITE, mds->mds_lmv_exp, &ca->oa,
300 (struct lov_stripe_md *) dc->mea,
309 static int remove_entries_from_orig_dir(struct dirsplit_control *dc, int mdsnum)
311 struct list_head *cur, *tmp;
312 struct dentry *dentry;
313 struct dir_cache *ca;
314 struct dir_entry *de;
320 ca = dc->cache + mdsnum;
321 list_for_each_safe(cur, tmp, &ca->list) {
322 page = list_entry(cur, struct page, list);
323 buf = page_address(page);
324 end = buf + PAGE_SIZE;
326 de = (struct dir_entry *) buf;
327 while ((char *) de < end && de->namelen) {
328 /* lookup an inode */
329 LASSERT(de->namelen <= 255);
331 dentry = ll_lookup_one_len(de->name, dc->dentry,
333 if (IS_ERR(dentry)) {
334 CERROR("can't lookup %*s: %d\n", de->namelen,
335 de->name, (int) PTR_ERR(dentry));
338 LASSERT(dentry->d_inode != NULL);
339 rc = fsfilt_del_dir_entry(dc->obd, dentry);
342 de = (struct dir_entry *)
343 ((char *) de + DIR_REC_LEN(de->namelen));
349 static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
350 ino_t ino, unsigned int d_type)
352 struct dirsplit_control *dc = __buf;
353 struct mds_obd *mds = &dc->obd->u.mds;
354 struct dir_cache *ca;
355 struct dir_entry *de;
360 if (name[0] == '.' && (namlen == 1 ||
361 (namlen == 2 && name[1] == '.'))) {
362 /* skip special entries */
367 newmds = mea_name2idx(dc->mea, (char *) name, namlen);
369 if (newmds == mds->mds_num) {
370 /* this entry remains on the current MDS, skip moving */
374 OBD_ALLOC(n, namlen + 1);
375 memcpy(n, name, namlen);
376 n[namlen] = (char) 0;
378 OBD_FREE(n, namlen + 1);
380 /* check for space in buffer for new entry */
381 ca = dc->cache + newmds;
382 if (DIR_REC_LEN(namlen) > ca->free) {
383 int err = dc_new_page_to_cache(ca);
387 /* insert found entry into buffer to be flushed later */
388 /* NOTE: we'll fill generations number later, because we
389 * it's stored in inode, thus we need to lookup an entry,
390 * but directory is locked for readdir(), so we delay this */
394 de->namelen = namlen;
395 memcpy(de->name, name, namlen);
396 ca->cur += DIR_REC_LEN(namlen);
397 ca->free -= DIR_REC_LEN(namlen);
403 int scan_and_distribute(struct obd_device *obd, struct dentry *dentry,
406 struct inode *dir = dentry->d_inode;
407 struct dirsplit_control dc;
412 nlen = strlen("__iopen__/") + 10 + 1;
413 OBD_ALLOC(file_name, nlen);
416 i = sprintf(file_name, "__iopen__/0x%lx", dentry->d_inode->i_ino);
418 file = filp_open(file_name, O_RDONLY, 0);
420 CERROR("can't open directory %s: %d\n",
421 file_name, (int) PTR_ERR(file));
422 OBD_FREE(file_name, nlen);
423 RETURN(PTR_ERR(file));
426 memset(&dc, 0, sizeof(dc));
431 OBD_ALLOC(dc.cache, sizeof(struct dir_cache) * mea->mea_count);
432 LASSERT(dc.cache != NULL);
433 for (i = 0; i < mea->mea_count; i++) {
434 INIT_LIST_HEAD(&dc.cache[i].list);
435 dc.cache[i].free = 0;
436 dc.cache[i].cached = 0;
439 err = vfs_readdir(file, filldir, &dc);
444 for (i = 0; i < mea->mea_count; i++) {
445 if (!dc.cache[i].cached)
447 err = flush_buffer_onto_mds(&dc, i);
452 for (i = 0; i < mea->mea_count; i++) {
453 if (!dc.cache[i].cached)
455 err = remove_entries_from_orig_dir(&dc, i);
461 for (i = 0; i < mea->mea_count; i++) {
462 struct list_head *cur, *tmp;
463 if (!dc.cache[i].cached)
465 list_for_each_safe(cur, tmp, &dc.cache[i].list) {
467 page = list_entry(cur, struct page, list);
468 list_del(&page->list);
472 OBD_FREE(dc.cache, sizeof(struct dir_cache) * mea->mea_count);
473 OBD_FREE(file_name, nlen);
478 #define MAX_DIR_SIZE (64 * 1024)
480 int mds_splitting_expected(struct obd_device *obd, struct dentry *dentry)
482 struct mds_obd *mds = &obd->u.mds;
483 struct mea *mea = NULL;
487 if (!mds->mds_lmv_obd)
491 if (dentry->d_inode == NULL)
494 /* a dir can be splitted only */
495 if (!S_ISDIR(dentry->d_inode->i_mode))
498 /* large enough to be splitted? */
499 if (dentry->d_inode->i_size < MAX_DIR_SIZE)
502 /* don't split root directory */
503 if (dentry->d_inode->i_ino == mds->mds_rootfid.id)
506 mds_get_lmv_attr(obd, dentry->d_inode, &mea, &size);
508 /* already splitted or slave object: shouldn't be splitted */
511 /* may be splitted */
521 * must not be called on already splitted directories
523 int mds_try_to_split_dir(struct obd_device *obd,
524 struct dentry *dentry, struct mea **mea, int nstripes)
526 struct inode *dir = dentry->d_inode;
527 struct mds_obd *mds = &obd->u.mds;
528 struct mea *tmea = NULL;
529 struct obdo *oa = NULL;
530 int rc, mea_size = 0;
534 /* TODO: optimization possible - we already may have mea here */
535 if (!mds_splitting_expected(obd, dentry))
537 LASSERT(mea == NULL || *mea == NULL);
539 CDEBUG(D_OTHER, "%s: split directory %u/%lu/%lu\n",
540 obd->obd_name, mds->mds_num, dir->i_ino,
541 (unsigned long) dir->i_generation);
545 mea_size = obd_size_diskmd(mds->mds_lmv_exp, NULL);
547 /* FIXME: Actually we may only want to allocate enough space for
548 * necessary amount of stripes, but on the other hand with this
549 * approach of allocating maximal possible amount of MDS slots,
550 * it would be easier to split the dir over more MDSes */
551 rc = obd_alloc_diskmd(mds->mds_lmv_exp, (void *) mea);
554 (*mea)->mea_count = nstripes;
556 /* 1) create directory objects on slave MDS'es */
557 /* FIXME: should this be OBD method? */
559 /* FIXME: error handling here */
561 oa->o_id = dir->i_ino;
562 oa->o_generation = dir->i_generation;
563 obdo_from_inode(oa, dir, OBD_MD_FLTYPE | OBD_MD_FLATIME |
564 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
565 OBD_MD_FLUID | OBD_MD_FLGID);
566 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
567 oa->o_valid |= OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
568 oa->o_mode = dir->i_mode;
569 CDEBUG(D_OTHER, "%s: create subdirs with mode %o, uid %u, gid %u\n",
570 obd->obd_name, dir->i_mode, dir->i_uid, dir->i_gid);
572 rc = obd_create(mds->mds_lmv_exp, oa,
573 (struct lov_stripe_md **) mea, NULL);
574 /* FIXME: error handling here */
576 CDEBUG(D_OTHER, "%d dirobjects created\n",
577 (int) (*mea)->mea_count);
579 /* 2) update dir attribute */
581 handle = fsfilt_start(obd, dir, FSFILT_OP_SETATTR, NULL);
582 LASSERT(!IS_ERR(handle));
583 rc = fsfilt_set_md(obd, dir, handle, *mea, mea_size);
585 fsfilt_commit(obd, mds->mds_sb, dir, handle, 0);
590 /* 3) read through the dir and distribute it over objects */
591 scan_and_distribute(obd, dentry, *mea);
594 obd_free_diskmd(mds->mds_lmv_exp,
595 (struct lov_mds_md **) mea);
599 static int filter_start_page_write(struct inode *inode,
600 struct niobuf_local *lnb)
602 struct page *page = alloc_pages(GFP_HIGHUSER, 0);
604 CERROR("no memory for a temp page\n");
605 RETURN(lnb->rc = -ENOMEM);
607 POISON_PAGE(page, 0xf1);
608 page->index = lnb->offset >> PAGE_SHIFT;
614 struct dentry *filter_fid2dentry(struct obd_device *obd,
615 struct dentry *dir_dentry,
616 obd_gr group, obd_id id);
618 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
619 int objcount, struct obd_ioobj *obj,
620 int niocount, struct niobuf_remote *nb,
621 struct niobuf_local *res,
622 struct obd_trans_info *oti)
624 struct mds_obd *mds = &exp->exp_obd->u.mds;
625 struct niobuf_remote *rnb;
626 struct niobuf_local *lnb = NULL;
627 int rc = 0, i, tot_bytes = 0;
628 unsigned long now = jiffies;
629 struct dentry *dentry;
632 LASSERT(objcount == 1);
633 LASSERT(obj->ioo_bufcnt > 0);
635 memset(res, 0, niocount * sizeof(*res));
637 fid.id = obj->ioo_id;
638 fid.generation = obj->ioo_gr;
639 dentry = mds_fid2dentry(mds, &fid, NULL);
640 LASSERT(!IS_ERR(dentry));
642 if (dentry->d_inode == NULL) {
643 CERROR("trying to BRW to non-existent file "LPU64"\n",
646 GOTO(cleanup, rc = -ENOENT);
649 if (time_after(jiffies, now + 15 * HZ))
650 CERROR("slow preprw_write setup %lus\n", (jiffies - now) / HZ);
652 CDEBUG(D_INFO, "preprw_write setup: %lu jiffies\n",
655 for (i = 0, rnb = nb, lnb = res; i < obj->ioo_bufcnt;
657 lnb->dentry = dentry;
658 lnb->offset = rnb->offset;
660 lnb->flags = rnb->flags;
662 rc = filter_start_page_write(dentry->d_inode, lnb);
664 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR, "page err %u@"
665 LPU64" %u/%u %p: rc %d\n", lnb->len, lnb->offset,
666 i, obj->ioo_bufcnt, dentry, rc);
668 __free_pages(lnb->page, 0);
672 tot_bytes += lnb->len;
675 if (time_after(jiffies, now + 15 * HZ))
676 CERROR("slow start_page_write %lus\n", (jiffies - now) / HZ);
678 CDEBUG(D_INFO, "start_page_write: %lu jiffies\n",
686 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
687 int objcount, struct obd_ioobj *obj, int niocount,
688 struct niobuf_local *res, struct obd_trans_info *oti,
691 struct obd_device *obd = exp->exp_obd;
692 struct niobuf_local *lnb;
693 struct inode *inode = NULL;
694 int rc = 0, i, cleanup_phase = 0, err, entries = 0;
697 LASSERT(objcount == 1);
698 LASSERT(current->journal_info == NULL);
701 inode = res->dentry->d_inode;
703 for (i = 0, lnb = res; i < obj->ioo_bufcnt; i++, lnb++) {
705 struct dir_entry *de;
707 buf = kmap(lnb->page);
708 LASSERT(buf != NULL);
709 end = buf + lnb->len;
710 de = (struct dir_entry *) buf;
711 while ((char *) de < end && de->namelen) {
712 err = fsfilt_add_dir_entry(obd, res->dentry, de->name,
713 de->namelen, de->ino,
714 de->generation, de->mds);
716 de = (struct dir_entry *)
717 ((char *) de + DIR_REC_LEN(de->namelen));
723 for (i = 0, lnb = res; i < obj->ioo_bufcnt; i++, lnb++)
724 __free_page(lnb->page);
730 int mds_choose_mdsnum(struct obd_device *obd, const char *name, int len, int flags)
733 struct mds_obd *mds = &obd->u.mds;
734 int i = mds->mds_num;
736 if (flags & REC_REINT_CREATE) {
738 } else if (mds->mds_lmv_exp) {
739 lmv = &mds->mds_lmv_exp->exp_obd->u.lmv;
740 i = raw_name2idx(lmv->desc.ld_tgt_count, name, len);
745 int mds_lock_slave_objs(struct obd_device *obd, struct dentry *dentry,
746 struct lustre_handle **rlockh)
748 struct mds_obd *mds = &obd->u.mds;
749 struct mdc_op_data op_data;
750 struct lookup_intent it;
751 struct mea *mea = NULL;
754 LASSERT(rlockh != NULL);
755 LASSERT(dentry != NULL);
756 LASSERT(dentry->d_inode != NULL);
759 if (!mds->mds_lmv_obd)
762 /* a dir can be splitted only */
763 if (!S_ISDIR(dentry->d_inode->i_mode))
766 rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size);
772 if (mea->mea_count == 0) {
773 /* this is slave object */
774 GOTO(cleanup, rc = 0);
777 CDEBUG(D_OTHER, "%s: lock slaves for %lu/%lu\n", obd->obd_name,
778 (unsigned long) dentry->d_inode->i_ino,
779 (unsigned long) dentry->d_inode->i_generation);
781 OBD_ALLOC(*rlockh, sizeof(struct lustre_handle) * mea->mea_count);
783 GOTO(cleanup, rc = -ENOMEM);
784 memset(*rlockh, 0, sizeof(struct lustre_handle) * mea->mea_count);
786 memset(&op_data, 0, sizeof(op_data));
788 it.it_op = IT_UNLINK;
789 rc = md_enqueue(mds->mds_lmv_exp, LDLM_IBITS, &it, LCK_EX, &op_data,
790 *rlockh, NULL, 0, ldlm_completion_ast, mds_blocking_ast,
793 OBD_FREE(mea, mea_size);
797 void mds_unlock_slave_objs(struct obd_device *obd, struct dentry *dentry,
798 struct lustre_handle *lockh)
800 struct mds_obd *mds = &obd->u.mds;
801 struct mea *mea = NULL;
807 LASSERT(mds->mds_lmv_obd != NULL);
808 LASSERT(S_ISDIR(dentry->d_inode->i_mode));
810 rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size);
812 CERROR("locks are leaked\n");
815 LASSERT(mea_size != 0);
816 LASSERT(mea != NULL);
817 LASSERT(mea->mea_count != 0);
819 CDEBUG(D_OTHER, "%s: unlock slaves for %lu/%lu\n", obd->obd_name,
820 (unsigned long) dentry->d_inode->i_ino,
821 (unsigned long) dentry->d_inode->i_generation);
823 for (i = 0; i < mea->mea_count; i++) {
824 if (lockh[i].cookie != 0)
825 ldlm_lock_decref(lockh + i, LCK_EX);
828 OBD_FREE(lockh, sizeof(struct lustre_handle) * mea->mea_count);
829 OBD_FREE(mea, mea_size);
833 int mds_unlink_slave_objs(struct obd_device *obd, struct dentry *dentry)
835 struct mds_obd *mds = &obd->u.mds;
836 struct ptlrpc_request *req = NULL;
837 struct mdc_op_data op_data;
838 struct mea *mea = NULL;
842 if (!mds->mds_lmv_obd)
845 /* a dir can be splitted only */
846 if (!S_ISDIR(dentry->d_inode->i_mode))
849 rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size);
855 if (mea->mea_count == 0)
856 GOTO(cleanup, rc = 0);
858 CDEBUG(D_OTHER, "%s: unlink slaves for %lu/%lu\n", obd->obd_name,
859 (unsigned long) dentry->d_inode->i_ino,
860 (unsigned long) dentry->d_inode->i_generation);
862 memset(&op_data, 0, sizeof(op_data));
864 rc = md_unlink(mds->mds_lmv_exp, &op_data, &req);
865 LASSERT(req == NULL);
867 OBD_FREE(mea, mea_size);
871 struct ide_tracking {
876 int mds_ide_filldir(void *__buf, const char *name, int namelen,
877 loff_t offset, ino_t ino, unsigned int d_type)
879 struct ide_tracking *it = __buf;
889 if (name[0] == '.' && namelen == 1)
891 if (name[0] == '.' && name[1] == '.' && namelen == 2)
898 int mds_is_dir_empty(struct obd_device *obd, struct dentry *dentry)
900 struct ide_tracking it;
908 nlen = strlen("__iopen__/") + 10 + 1;
909 OBD_ALLOC(file_name, nlen);
912 i = sprintf(file_name, "__iopen__/0x%lx", dentry->d_inode->i_ino);
914 file = filp_open(file_name, O_RDONLY, 0);
916 CERROR("can't open directory %s: %d\n",
917 file_name, (int) PTR_ERR(file));
918 GOTO(cleanup, rc = PTR_ERR(file));
921 rc = vfs_readdir(file, mds_ide_filldir, &it);
924 if (it.empty && rc == 0)
930 OBD_FREE(file_name, nlen);
934 int mds_lock_and_check_slave(int offset, struct ptlrpc_request *req,
935 struct lustre_handle *lockh)
937 struct obd_device *obd = req->rq_export->exp_obd;
938 struct dentry *dentry = NULL;
939 struct lvfs_run_ctxt saved;
940 int cleanup_phase = 0;
941 struct mds_body *body;
942 struct lvfs_ucred uc;
946 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
947 lustre_swab_mds_body);
949 CERROR("Can't swab mds_body\n");
950 GOTO(cleanup, rc = -EFAULT);
952 CDEBUG(D_OTHER, "%s: check slave %lu/%lu\n", obd->obd_name,
953 (unsigned long) body->fid1.id,
954 (unsigned long) body->fid1.generation);
955 dentry = mds_fid2locked_dentry(obd, &body->fid1, NULL, LCK_EX, lockh,
956 &update_mode, NULL, 0,
957 MDS_INODELOCK_UPDATE);
958 if (IS_ERR(dentry)) {
959 CERROR("can't find inode: %d\n", (int) PTR_ERR(dentry));
960 GOTO(cleanup, rc = PTR_ERR(dentry));
964 LASSERT(S_ISDIR(dentry->d_inode->i_mode));
966 uc.luc_fsuid = body->fsuid;
967 uc.luc_fsgid = body->fsgid;
968 uc.luc_cap = body->capability;
969 uc.luc_suppgid1 = body->suppgid;
970 uc.luc_suppgid2 = -1;
971 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
974 if (!mds_is_dir_empty(obd, dentry))
978 switch(cleanup_phase) {
981 ldlm_lock_decref(lockh, LCK_EX);
983 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);