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};
51 int rc, valsize, value;
54 if (IS_ERR(mds->mds_lmv_obd))
55 RETURN(PTR_ERR(mds->mds_lmv_obd));
60 mds->mds_lmv_obd = class_name2obd(lmv_name);
61 if (!mds->mds_lmv_obd) {
62 CERROR("MDS cannot locate LMV %s\n",
64 mds->mds_lmv_obd = ERR_PTR(-ENOTCONN);
68 rc = obd_connect(&conn, mds->mds_lmv_obd, &obd->obd_uuid);
70 CERROR("MDS cannot connect to LMV %s (%d)\n",
72 mds->mds_lmv_obd = ERR_PTR(rc);
75 mds->mds_lmv_exp = class_conn2export(&conn);
76 if (mds->mds_lmv_exp == NULL)
77 CERROR("can't get export!\n");
79 rc = obd_register_observer(mds->mds_lmv_obd, obd);
81 CERROR("MDS cannot register as observer of LMV %s, "
82 "rc = %d\n", lmv_name, rc);
86 /* retrieve size of EA */
87 rc = obd_get_info(mds->mds_lmv_exp, strlen("mdsize"), "mdsize",
92 if (value > mds->mds_max_mdsize)
93 mds->mds_max_mdsize = value;
95 /* find our number in LMV cluster */
96 rc = obd_get_info(mds->mds_lmv_exp, strlen("mdsnum"), "mdsnum",
101 mds->mds_num = value;
103 rc = obd_set_info(mds->mds_lmv_exp, strlen("inter_mds"),
104 "inter_mds", 0, NULL);
111 obd_register_observer(mds->mds_lmv_obd, NULL);
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;
125 if (mds->mds_lmv_exp)
126 rc = obd_init_ea_size(mds->mds_lmv_exp, mds->mds_max_mdsize,
127 mds->mds_max_cookiesize);
132 int mds_lmv_disconnect(struct obd_device *obd, int flags)
134 struct mds_obd *mds = &obd->u.mds;
138 if (!IS_ERR(mds->mds_lmv_obd) && mds->mds_lmv_exp != NULL) {
139 obd_register_observer(mds->mds_lmv_obd, NULL);
141 /* if obd_disconnect fails (probably because the export was
142 * disconnected by class_disconnect_exports) then we just need
143 * to drop our ref. */
144 rc = obd_disconnect(mds->mds_lmv_exp, flags);
146 class_export_put(mds->mds_lmv_exp);
148 mds->mds_lmv_exp = NULL;
149 mds->mds_lmv_obd = NULL;
155 int mds_get_lmv_attr(struct obd_device *obd, struct inode *inode,
156 struct mea **mea, int *mea_size)
158 struct mds_obd *mds = &obd->u.mds;
162 if (!mds->mds_lmv_obd)
165 /* first calculate mea size */
166 *mea_size = obd_alloc_diskmd(mds->mds_lmv_exp,
167 (struct lov_mds_md **)mea);
168 if (*mea_size < 0 || *mea == NULL)
169 return *mea_size < 0 ? *mea_size : -EINVAL;
172 rc = fsfilt_get_md(obd, inode, *mea, *mea_size);
176 OBD_FREE(*mea, *mea_size);
193 #define DIR_ROUND (DIR_PAD - 1)
194 #define DIR_REC_LEN(name_len) (((name_len) + 12 + DIR_ROUND) & ~DIR_ROUND)
196 /* this struct holds dir entries for particular MDS to be flushed */
198 struct list_head list;
203 struct brw_page brwc;
206 struct dirsplit_control {
207 struct obd_device *obd;
209 struct dentry *dentry;
211 struct dir_cache *cache;
214 static int dc_new_page_to_cache(struct dir_cache * dirc)
218 if (!list_empty(&dirc->list) && dirc->free > sizeof(__u16)) {
219 /* current page became full, mark the end */
220 struct dir_entry *de = dirc->cur;
224 page = alloc_page(GFP_KERNEL);
227 list_add_tail(&page->list, &dirc->list);
228 dirc->cur = page_address(page);
229 dirc->free = PAGE_SIZE;
233 static int retrieve_generation_numbers(struct dirsplit_control *dc, void *buf)
235 struct mds_obd *mds = &dc->obd->u.mds;
236 struct dir_entry *de;
237 struct dentry *dentry;
240 end = buf + PAGE_SIZE;
241 de = (struct dir_entry *) buf;
242 while ((char *) de < end && de->namelen) {
243 /* lookup an inode */
244 LASSERT(de->namelen <= 255);
245 dentry = ll_lookup_one_len(de->name, dc->dentry, de->namelen);
246 if (IS_ERR(dentry)) {
247 CERROR("can't lookup %*s: %d\n", de->namelen,
248 de->name, (int) PTR_ERR(dentry));
251 if (dentry->d_inode != NULL) {
252 de->mds = mds->mds_num;
253 de->ino = dentry->d_inode->i_ino;
254 de->generation = dentry->d_inode->i_generation;
255 } else if (dentry->d_flags & DCACHE_CROSS_REF) {
256 de->mds = dentry->d_mdsnum;
257 de->ino = dentry->d_inum;
258 de->generation = dentry->d_generation;
260 CERROR("can't lookup %*s\n", de->namelen, de->name);
266 de = (struct dir_entry *)
267 ((char *) de + DIR_REC_LEN(de->namelen));
272 static int flush_buffer_onto_mds(struct dirsplit_control *dc, int mdsnum)
274 struct mds_obd *mds = &dc->obd->u.mds;
275 struct list_head *cur, *tmp;
276 struct dir_cache *ca;
279 ca = dc->cache + mdsnum;
281 if (ca->free > sizeof(__u16)) {
282 /* current page became full, mark the end */
283 struct dir_entry *de = ca->cur;
287 list_for_each_safe(cur, tmp, &ca->list) {
290 page = list_entry(cur, struct page, list);
291 LASSERT(page != NULL);
293 retrieve_generation_numbers(dc, page_address(page));
297 ca->brwc.count = PAGE_SIZE;
299 ca->oa.o_mds = mdsnum;
300 rc = obd_brw(OBD_BRW_WRITE, mds->mds_lmv_exp, &ca->oa,
301 (struct lov_stripe_md *) dc->mea,
310 static int remove_entries_from_orig_dir(struct dirsplit_control *dc, int mdsnum)
312 struct list_head *cur, *tmp;
313 struct dentry *dentry;
314 struct dir_cache *ca;
315 struct dir_entry *de;
321 ca = dc->cache + mdsnum;
322 list_for_each_safe(cur, tmp, &ca->list) {
323 page = list_entry(cur, struct page, list);
324 buf = page_address(page);
325 end = buf + PAGE_SIZE;
327 de = (struct dir_entry *) buf;
328 while ((char *) de < end && de->namelen) {
329 /* lookup an inode */
330 LASSERT(de->namelen <= 255);
332 dentry = ll_lookup_one_len(de->name, dc->dentry,
334 if (IS_ERR(dentry)) {
335 CERROR("can't lookup %*s: %d\n", de->namelen,
336 de->name, (int) PTR_ERR(dentry));
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)
488 RETURN(MDS_NO_SPLITTABLE);
491 if (dentry->d_inode == NULL)
492 return MDS_NO_SPLITTABLE;
494 /* a dir can be splitted only */
495 if (!S_ISDIR(dentry->d_inode->i_mode))
496 return MDS_NO_SPLITTABLE;
498 /* don't split root directory */
499 if (dentry->d_inode->i_ino == mds->mds_rootfid.id)
500 return MDS_NO_SPLITTABLE;
502 /* large enough to be splitted? */
503 if (dentry->d_inode->i_size < MAX_DIR_SIZE)
504 return MDS_NO_SPLIT_EXPECTED;
506 mds_get_lmv_attr(obd, dentry->d_inode, &mea, &size);
508 /* already splitted or slave object: shouldn't be splitted */
509 rc = MDS_NO_SPLITTABLE;
511 /* may be splitted */
512 rc = MDS_EXPECT_SPLIT;
521 * must not be called on already splitted directories.
523 int mds_try_to_split_dir(struct obd_device *obd, struct dentry *dentry,
524 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 rc = mds_splitting_expected(obd, dentry);
536 if (rc == MDS_NO_SPLITTABLE)
538 if (rc == MDS_NO_SPLIT_EXPECTED && nstripes == 0)
541 LASSERT(mea == NULL || *mea == NULL);
543 CDEBUG(D_OTHER, "%s: split directory %u/%lu/%lu\n",
544 obd->obd_name, mds->mds_num, dir->i_ino,
545 (unsigned long) dir->i_generation);
549 mea_size = obd_size_diskmd(mds->mds_lmv_exp, NULL);
551 /* FIXME: Actually we may only want to allocate enough space for
552 * necessary amount of stripes, but on the other hand with this
553 * approach of allocating maximal possible amount of MDS slots,
554 * it would be easier to split the dir over more MDSes */
555 rc = obd_alloc_diskmd(mds->mds_lmv_exp, (void *)mea);
557 CERROR("obd_alloc_diskmd() failed, error %d.\n", rc);
563 (*mea)->mea_count = nstripes;
565 /* 1) create directory objects on slave MDS'es */
566 /* FIXME: should this be OBD method? */
571 oa->o_id = dir->i_ino;
572 oa->o_generation = dir->i_generation;
574 obdo_from_inode(oa, dir, OBD_MD_FLTYPE | OBD_MD_FLATIME |
575 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
576 OBD_MD_FLUID | OBD_MD_FLGID);
578 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
579 oa->o_valid |= OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
580 oa->o_mode = dir->i_mode;
582 CDEBUG(D_OTHER, "%s: create subdirs with mode %o, uid %u, gid %u\n",
583 obd->obd_name, dir->i_mode, dir->i_uid, dir->i_gid);
585 rc = obd_create(mds->mds_lmv_exp, oa,
586 (struct lov_stripe_md **)mea, NULL);
590 CDEBUG(D_OTHER, "%d dirobjects created\n", (int)(*mea)->mea_count);
592 /* 2) update dir attribute */
595 handle = fsfilt_start(obd, dir, FSFILT_OP_SETATTR, NULL);
596 if (IS_ERR(handle)) {
598 CERROR("fsfilt_start() failed: %d\n", (int) PTR_ERR(handle));
599 GOTO(err_oa, rc = PTR_ERR(handle));
602 rc = fsfilt_set_md(obd, dir, handle, *mea, mea_size);
605 CERROR("fsfilt_set_md() failed, error %d.\n", rc);
609 rc = fsfilt_commit(obd, mds->mds_sb, dir, handle, 0);
612 CERROR("fsfilt_commit() failed, error %d.\n", rc);
619 /* 3) read through the dir and distribute it over objects */
620 rc = scan_and_distribute(obd, dentry, *mea);
622 obd_free_diskmd(mds->mds_lmv_exp, (struct lov_mds_md **)mea);
624 CERROR("scan_and_distribute() failed, error %d.\n", rc);
635 static int filter_start_page_write(struct inode *inode,
636 struct niobuf_local *lnb)
638 struct page *page = alloc_pages(GFP_HIGHUSER, 0);
640 CERROR("no memory for a temp page\n");
641 RETURN(lnb->rc = -ENOMEM);
643 POISON_PAGE(page, 0xf1);
644 page->index = lnb->offset >> PAGE_SHIFT;
650 struct dentry *filter_fid2dentry(struct obd_device *obd,
651 struct dentry *dir_dentry,
652 obd_gr group, obd_id id);
654 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
655 int objcount, struct obd_ioobj *obj,
656 int niocount, struct niobuf_remote *nb,
657 struct niobuf_local *res,
658 struct obd_trans_info *oti)
660 struct mds_obd *mds = &exp->exp_obd->u.mds;
661 struct niobuf_remote *rnb;
662 struct niobuf_local *lnb = NULL;
663 int rc = 0, i, tot_bytes = 0;
664 unsigned long now = jiffies;
665 struct dentry *dentry;
668 LASSERT(objcount == 1);
669 LASSERT(obj->ioo_bufcnt > 0);
671 memset(res, 0, niocount * sizeof(*res));
673 fid.id = obj->ioo_id;
674 fid.generation = obj->ioo_gr;
675 dentry = mds_fid2dentry(mds, &fid, NULL);
676 if (IS_ERR(dentry)) {
677 CERROR("can't get dentry for %lu/%lu: %d\n",
678 (unsigned long) fid.id,
679 (unsigned long) fid.generation, (int) PTR_ERR(dentry));
680 GOTO(cleanup, rc = (int) PTR_ERR(dentry));
683 if (dentry->d_inode == NULL) {
684 CERROR("trying to BRW to non-existent file "LPU64"\n",
687 GOTO(cleanup, rc = -ENOENT);
690 if (time_after(jiffies, now + 15 * HZ))
691 CERROR("slow preprw_write setup %lus\n", (jiffies - now) / HZ);
693 CDEBUG(D_INFO, "preprw_write setup: %lu jiffies\n",
696 for (i = 0, rnb = nb, lnb = res; i < obj->ioo_bufcnt;
698 lnb->dentry = dentry;
699 lnb->offset = rnb->offset;
701 lnb->flags = rnb->flags;
703 rc = filter_start_page_write(dentry->d_inode, lnb);
705 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR, "page err %u@"
706 LPU64" %u/%u %p: rc %d\n", lnb->len, lnb->offset,
707 i, obj->ioo_bufcnt, dentry, rc);
709 __free_pages(lnb->page, 0);
713 tot_bytes += lnb->len;
716 if (time_after(jiffies, now + 15 * HZ))
717 CERROR("slow start_page_write %lus\n", (jiffies - now) / HZ);
719 CDEBUG(D_INFO, "start_page_write: %lu jiffies\n",
727 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
728 int objcount, struct obd_ioobj *obj, int niocount,
729 struct niobuf_local *res, struct obd_trans_info *oti,
732 struct obd_device *obd = exp->exp_obd;
733 struct niobuf_local *lnb;
734 struct inode *inode = NULL;
735 int rc = 0, i, cleanup_phase = 0, err, entries = 0;
738 LASSERT(objcount == 1);
739 LASSERT(current->journal_info == NULL);
742 inode = res->dentry->d_inode;
744 for (i = 0, lnb = res; i < obj->ioo_bufcnt; i++, lnb++) {
746 struct dir_entry *de;
748 buf = kmap(lnb->page);
749 LASSERT(buf != NULL);
750 end = buf + lnb->len;
751 de = (struct dir_entry *) buf;
752 while ((char *) de < end && de->namelen) {
753 err = fsfilt_add_dir_entry(obd, res->dentry, de->name,
754 de->namelen, de->ino,
755 de->generation, de->mds);
757 de = (struct dir_entry *)
758 ((char *) de + DIR_REC_LEN(de->namelen));
764 for (i = 0, lnb = res; i < obj->ioo_bufcnt; i++, lnb++)
765 __free_page(lnb->page);
771 int mds_choose_mdsnum(struct obd_device *obd, const char *name, int len, int flags)
774 struct mds_obd *mds = &obd->u.mds;
775 int i = mds->mds_num;
777 if (flags & REC_REINT_CREATE) {
779 } else if (mds->mds_lmv_exp) {
780 lmv = &mds->mds_lmv_exp->exp_obd->u.lmv;
781 i = raw_name2idx(lmv->desc.ld_tgt_count, name, len);
786 int mds_lock_slave_objs(struct obd_device *obd, struct dentry *dentry,
787 struct lustre_handle **rlockh)
789 struct mds_obd *mds = &obd->u.mds;
790 struct mdc_op_data op_data;
791 struct lookup_intent it;
792 struct mea *mea = NULL;
795 LASSERT(rlockh != NULL);
796 LASSERT(dentry != NULL);
797 LASSERT(dentry->d_inode != NULL);
800 if (!mds->mds_lmv_obd)
803 /* a dir can be splitted only */
804 if (!S_ISDIR(dentry->d_inode->i_mode))
807 rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size);
813 if (mea->mea_count == 0) {
814 /* this is slave object */
815 GOTO(cleanup, rc = 0);
818 CDEBUG(D_OTHER, "%s: lock slaves for %lu/%lu\n", obd->obd_name,
819 (unsigned long) dentry->d_inode->i_ino,
820 (unsigned long) dentry->d_inode->i_generation);
822 OBD_ALLOC(*rlockh, sizeof(struct lustre_handle) * mea->mea_count);
824 GOTO(cleanup, rc = -ENOMEM);
825 memset(*rlockh, 0, sizeof(struct lustre_handle) * mea->mea_count);
827 memset(&op_data, 0, sizeof(op_data));
829 it.it_op = IT_UNLINK;
830 rc = md_enqueue(mds->mds_lmv_exp, LDLM_IBITS, &it, LCK_EX, &op_data,
831 *rlockh, NULL, 0, ldlm_completion_ast, mds_blocking_ast,
834 OBD_FREE(mea, mea_size);
838 void mds_unlock_slave_objs(struct obd_device *obd, struct dentry *dentry,
839 struct lustre_handle *lockh)
841 struct mds_obd *mds = &obd->u.mds;
842 struct mea *mea = NULL;
848 LASSERT(mds->mds_lmv_obd != NULL);
849 LASSERT(S_ISDIR(dentry->d_inode->i_mode));
851 rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size);
853 CERROR("locks are leaked\n");
856 LASSERT(mea_size != 0);
857 LASSERT(mea != NULL);
858 LASSERT(mea->mea_count != 0);
860 CDEBUG(D_OTHER, "%s: unlock slaves for %lu/%lu\n", obd->obd_name,
861 (unsigned long) dentry->d_inode->i_ino,
862 (unsigned long) dentry->d_inode->i_generation);
864 for (i = 0; i < mea->mea_count; i++) {
865 if (lockh[i].cookie != 0)
866 ldlm_lock_decref(lockh + i, LCK_EX);
869 OBD_FREE(lockh, sizeof(struct lustre_handle) * mea->mea_count);
870 OBD_FREE(mea, mea_size);
874 int mds_unlink_slave_objs(struct obd_device *obd, struct dentry *dentry)
876 struct mds_obd *mds = &obd->u.mds;
877 struct ptlrpc_request *req = NULL;
878 struct mdc_op_data op_data;
879 struct mea *mea = NULL;
883 if (!mds->mds_lmv_obd)
886 /* a dir can be splitted only */
887 if (!S_ISDIR(dentry->d_inode->i_mode))
890 rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size);
896 if (mea->mea_count == 0)
897 GOTO(cleanup, rc = 0);
899 CDEBUG(D_OTHER, "%s: unlink slaves for %lu/%lu\n", obd->obd_name,
900 (unsigned long) dentry->d_inode->i_ino,
901 (unsigned long) dentry->d_inode->i_generation);
903 memset(&op_data, 0, sizeof(op_data));
905 rc = md_unlink(mds->mds_lmv_exp, &op_data, &req);
906 LASSERT(req == NULL);
908 OBD_FREE(mea, mea_size);
912 struct ide_tracking {
917 int mds_ide_filldir(void *__buf, const char *name, int namelen,
918 loff_t offset, ino_t ino, unsigned int d_type)
920 struct ide_tracking *it = __buf;
930 if (name[0] == '.' && namelen == 1)
932 if (name[0] == '.' && name[1] == '.' && namelen == 2)
939 int mds_is_dir_empty(struct obd_device *obd, struct dentry *dentry)
941 struct ide_tracking it;
949 nlen = strlen("__iopen__/") + 10 + 1;
950 OBD_ALLOC(file_name, nlen);
953 i = sprintf(file_name, "__iopen__/0x%lx", dentry->d_inode->i_ino);
955 file = filp_open(file_name, O_RDONLY, 0);
957 CERROR("can't open directory %s: %d\n",
958 file_name, (int) PTR_ERR(file));
959 GOTO(cleanup, rc = PTR_ERR(file));
962 rc = vfs_readdir(file, mds_ide_filldir, &it);
965 if (it.empty && rc == 0)
971 OBD_FREE(file_name, nlen);
975 int mds_lock_and_check_slave(int offset, struct ptlrpc_request *req,
976 struct lustre_handle *lockh)
978 struct obd_device *obd = req->rq_export->exp_obd;
979 struct dentry *dentry = NULL;
980 struct lvfs_run_ctxt saved;
981 int cleanup_phase = 0;
982 struct mds_body *body;
983 struct lvfs_ucred uc;
987 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
988 lustre_swab_mds_body);
990 CERROR("Can't swab mds_body\n");
991 GOTO(cleanup, rc = -EFAULT);
993 CDEBUG(D_OTHER, "%s: check slave %lu/%lu\n", obd->obd_name,
994 (unsigned long) body->fid1.id,
995 (unsigned long) body->fid1.generation);
996 dentry = mds_fid2locked_dentry(obd, &body->fid1, NULL, LCK_EX, lockh,
997 &update_mode, NULL, 0,
998 MDS_INODELOCK_UPDATE);
999 if (IS_ERR(dentry)) {
1000 CERROR("can't find inode: %d\n", (int) PTR_ERR(dentry));
1001 GOTO(cleanup, rc = PTR_ERR(dentry));
1005 LASSERT(S_ISDIR(dentry->d_inode->i_mode));
1007 uc.luc_fsuid = body->fsuid;
1008 uc.luc_fsgid = body->fsgid;
1009 uc.luc_cap = body->capability;
1010 uc.luc_suppgid1 = body->suppgid;
1011 uc.luc_suppgid2 = -1;
1012 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1015 if (!mds_is_dir_empty(obd, dentry))
1019 switch(cleanup_phase) {
1022 ldlm_lock_decref(lockh, LCK_EX);
1024 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);