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 LASSERT(dentry->d_inode != NULL);
340 rc = fsfilt_del_dir_entry(dc->obd, dentry);
343 de = (struct dir_entry *)
344 ((char *) de + DIR_REC_LEN(de->namelen));
350 static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
351 ino_t ino, unsigned int d_type)
353 struct dirsplit_control *dc = __buf;
354 struct mds_obd *mds = &dc->obd->u.mds;
355 struct dir_cache *ca;
356 struct dir_entry *de;
361 if (name[0] == '.' && (namlen == 1 ||
362 (namlen == 2 && name[1] == '.'))) {
363 /* skip special entries */
368 newmds = mea_name2idx(dc->mea, (char *) name, namlen);
370 if (newmds == mds->mds_num) {
371 /* this entry remains on the current MDS, skip moving */
375 OBD_ALLOC(n, namlen + 1);
376 memcpy(n, name, namlen);
377 n[namlen] = (char) 0;
379 OBD_FREE(n, namlen + 1);
381 /* check for space in buffer for new entry */
382 ca = dc->cache + newmds;
383 if (DIR_REC_LEN(namlen) > ca->free) {
384 int err = dc_new_page_to_cache(ca);
388 /* insert found entry into buffer to be flushed later */
389 /* NOTE: we'll fill generations number later, because we
390 * it's stored in inode, thus we need to lookup an entry,
391 * but directory is locked for readdir(), so we delay this */
395 de->namelen = namlen;
396 memcpy(de->name, name, namlen);
397 ca->cur += DIR_REC_LEN(namlen);
398 ca->free -= DIR_REC_LEN(namlen);
404 int scan_and_distribute(struct obd_device *obd, struct dentry *dentry,
407 struct inode *dir = dentry->d_inode;
408 struct dirsplit_control dc;
413 nlen = strlen("__iopen__/") + 10 + 1;
414 OBD_ALLOC(file_name, nlen);
417 i = sprintf(file_name, "__iopen__/0x%lx", dentry->d_inode->i_ino);
419 file = filp_open(file_name, O_RDONLY, 0);
421 CERROR("can't open directory %s: %d\n",
422 file_name, (int) PTR_ERR(file));
423 OBD_FREE(file_name, nlen);
424 RETURN(PTR_ERR(file));
427 memset(&dc, 0, sizeof(dc));
432 OBD_ALLOC(dc.cache, sizeof(struct dir_cache) * mea->mea_count);
433 LASSERT(dc.cache != NULL);
434 for (i = 0; i < mea->mea_count; i++) {
435 INIT_LIST_HEAD(&dc.cache[i].list);
436 dc.cache[i].free = 0;
437 dc.cache[i].cached = 0;
440 err = vfs_readdir(file, filldir, &dc);
445 for (i = 0; i < mea->mea_count; i++) {
446 if (!dc.cache[i].cached)
448 err = flush_buffer_onto_mds(&dc, i);
453 for (i = 0; i < mea->mea_count; i++) {
454 if (!dc.cache[i].cached)
456 err = remove_entries_from_orig_dir(&dc, i);
462 for (i = 0; i < mea->mea_count; i++) {
463 struct list_head *cur, *tmp;
464 if (!dc.cache[i].cached)
466 list_for_each_safe(cur, tmp, &dc.cache[i].list) {
468 page = list_entry(cur, struct page, list);
469 list_del(&page->list);
473 OBD_FREE(dc.cache, sizeof(struct dir_cache) * mea->mea_count);
474 OBD_FREE(file_name, nlen);
479 #define MAX_DIR_SIZE (64 * 1024)
481 int mds_splitting_expected(struct obd_device *obd, struct dentry *dentry)
483 struct mds_obd *mds = &obd->u.mds;
484 struct mea *mea = NULL;
488 if (!mds->mds_lmv_obd)
489 RETURN(MDS_NO_SPLITTABLE);
492 if (dentry->d_inode == NULL)
493 return MDS_NO_SPLITTABLE;
495 /* a dir can be splitted only */
496 if (!S_ISDIR(dentry->d_inode->i_mode))
497 return MDS_NO_SPLITTABLE;
499 /* don't split root directory */
500 if (dentry->d_inode->i_ino == mds->mds_rootfid.id)
501 return MDS_NO_SPLITTABLE;
503 /* large enough to be splitted? */
504 if (dentry->d_inode->i_size < MAX_DIR_SIZE)
505 return MDS_NO_SPLIT_EXPECTED;
507 mds_get_lmv_attr(obd, dentry->d_inode, &mea, &size);
509 /* already splitted or slave object: shouldn't be splitted */
510 rc = MDS_NO_SPLITTABLE;
512 /* may be splitted */
513 rc = MDS_EXPECT_SPLIT;
522 * must not be called on already splitted directories.
524 int mds_try_to_split_dir(struct obd_device *obd, struct dentry *dentry,
525 struct mea **mea, int nstripes)
527 struct inode *dir = dentry->d_inode;
528 struct mds_obd *mds = &obd->u.mds;
529 struct mea *tmea = NULL;
530 struct obdo *oa = NULL;
531 int rc, mea_size = 0;
535 /* TODO: optimization possible - we already may have mea here */
536 if (mds_splitting_expected(obd, dentry) != MDS_EXPECT_SPLIT)
539 LASSERT(mea == NULL || *mea == NULL);
541 CDEBUG(D_OTHER, "%s: split directory %u/%lu/%lu\n",
542 obd->obd_name, mds->mds_num, dir->i_ino,
543 (unsigned long) dir->i_generation);
547 mea_size = obd_size_diskmd(mds->mds_lmv_exp, NULL);
549 /* FIXME: Actually we may only want to allocate enough space for
550 * necessary amount of stripes, but on the other hand with this
551 * approach of allocating maximal possible amount of MDS slots,
552 * it would be easier to split the dir over more MDSes */
553 rc = obd_alloc_diskmd(mds->mds_lmv_exp, (void *)mea);
555 CERROR("obd_alloc_diskmd() failed, error %d.\n", rc);
561 (*mea)->mea_count = nstripes;
563 /* 1) create directory objects on slave MDS'es */
564 /* FIXME: should this be OBD method? */
569 oa->o_id = dir->i_ino;
570 oa->o_generation = dir->i_generation;
572 obdo_from_inode(oa, dir, OBD_MD_FLTYPE | OBD_MD_FLATIME |
573 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
574 OBD_MD_FLUID | OBD_MD_FLGID);
576 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
577 oa->o_valid |= OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
578 oa->o_mode = dir->i_mode;
580 CDEBUG(D_OTHER, "%s: create subdirs with mode %o, uid %u, gid %u\n",
581 obd->obd_name, dir->i_mode, dir->i_uid, dir->i_gid);
583 rc = obd_create(mds->mds_lmv_exp, oa,
584 (struct lov_stripe_md **)mea, NULL);
588 CDEBUG(D_OTHER, "%d dirobjects created\n", (int)(*mea)->mea_count);
590 /* 2) update dir attribute */
593 handle = fsfilt_start(obd, dir, FSFILT_OP_SETATTR, NULL);
594 if (IS_ERR(handle)) {
596 CERROR("fsfilt_start() failed, error %d.\n",
598 GOTO(err_oa, rc = PTR_ERR(handle));
601 rc = fsfilt_set_md(obd, dir, handle, *mea, mea_size);
604 CERROR("fsfilt_set_md() failed, error %d.\n", rc);
608 rc = fsfilt_commit(obd, mds->mds_sb, dir, handle, 0);
611 CERROR("fsfilt_commit() failed, error %d.\n", rc);
618 /* 3) read through the dir and distribute it over objects */
619 rc = scan_and_distribute(obd, dentry, *mea);
621 CERROR("scan_and_distribute() failed, error %d.\n",
627 obd_free_diskmd(mds->mds_lmv_exp,
628 (struct lov_mds_md **)mea);
636 static int filter_start_page_write(struct inode *inode,
637 struct niobuf_local *lnb)
639 struct page *page = alloc_pages(GFP_HIGHUSER, 0);
641 CERROR("no memory for a temp page\n");
642 RETURN(lnb->rc = -ENOMEM);
644 POISON_PAGE(page, 0xf1);
645 page->index = lnb->offset >> PAGE_SHIFT;
651 struct dentry *filter_fid2dentry(struct obd_device *obd,
652 struct dentry *dir_dentry,
653 obd_gr group, obd_id id);
655 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
656 int objcount, struct obd_ioobj *obj,
657 int niocount, struct niobuf_remote *nb,
658 struct niobuf_local *res,
659 struct obd_trans_info *oti)
661 struct mds_obd *mds = &exp->exp_obd->u.mds;
662 struct niobuf_remote *rnb;
663 struct niobuf_local *lnb = NULL;
664 int rc = 0, i, tot_bytes = 0;
665 unsigned long now = jiffies;
666 struct dentry *dentry;
669 LASSERT(objcount == 1);
670 LASSERT(obj->ioo_bufcnt > 0);
672 memset(res, 0, niocount * sizeof(*res));
674 fid.id = obj->ioo_id;
675 fid.generation = obj->ioo_gr;
676 dentry = mds_fid2dentry(mds, &fid, NULL);
677 LASSERT(!IS_ERR(dentry));
679 if (dentry->d_inode == NULL) {
680 CERROR("trying to BRW to non-existent file "LPU64"\n",
683 GOTO(cleanup, rc = -ENOENT);
686 if (time_after(jiffies, now + 15 * HZ))
687 CERROR("slow preprw_write setup %lus\n", (jiffies - now) / HZ);
689 CDEBUG(D_INFO, "preprw_write setup: %lu jiffies\n",
692 for (i = 0, rnb = nb, lnb = res; i < obj->ioo_bufcnt;
694 lnb->dentry = dentry;
695 lnb->offset = rnb->offset;
697 lnb->flags = rnb->flags;
699 rc = filter_start_page_write(dentry->d_inode, lnb);
701 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR, "page err %u@"
702 LPU64" %u/%u %p: rc %d\n", lnb->len, lnb->offset,
703 i, obj->ioo_bufcnt, dentry, rc);
705 __free_pages(lnb->page, 0);
709 tot_bytes += lnb->len;
712 if (time_after(jiffies, now + 15 * HZ))
713 CERROR("slow start_page_write %lus\n", (jiffies - now) / HZ);
715 CDEBUG(D_INFO, "start_page_write: %lu jiffies\n",
723 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
724 int objcount, struct obd_ioobj *obj, int niocount,
725 struct niobuf_local *res, struct obd_trans_info *oti,
728 struct obd_device *obd = exp->exp_obd;
729 struct niobuf_local *lnb;
730 struct inode *inode = NULL;
731 int rc = 0, i, cleanup_phase = 0, err, entries = 0;
734 LASSERT(objcount == 1);
735 LASSERT(current->journal_info == NULL);
738 inode = res->dentry->d_inode;
740 for (i = 0, lnb = res; i < obj->ioo_bufcnt; i++, lnb++) {
742 struct dir_entry *de;
744 buf = kmap(lnb->page);
745 LASSERT(buf != NULL);
746 end = buf + lnb->len;
747 de = (struct dir_entry *) buf;
748 while ((char *) de < end && de->namelen) {
749 err = fsfilt_add_dir_entry(obd, res->dentry, de->name,
750 de->namelen, de->ino,
751 de->generation, de->mds);
753 de = (struct dir_entry *)
754 ((char *) de + DIR_REC_LEN(de->namelen));
760 for (i = 0, lnb = res; i < obj->ioo_bufcnt; i++, lnb++)
761 __free_page(lnb->page);
767 int mds_choose_mdsnum(struct obd_device *obd, const char *name, int len, int flags)
770 struct mds_obd *mds = &obd->u.mds;
771 int i = mds->mds_num;
773 if (flags & REC_REINT_CREATE) {
775 } else if (mds->mds_lmv_exp) {
776 lmv = &mds->mds_lmv_exp->exp_obd->u.lmv;
777 i = raw_name2idx(lmv->desc.ld_tgt_count, name, len);
782 int mds_lock_slave_objs(struct obd_device *obd, struct dentry *dentry,
783 struct lustre_handle **rlockh)
785 struct mds_obd *mds = &obd->u.mds;
786 struct mdc_op_data op_data;
787 struct lookup_intent it;
788 struct mea *mea = NULL;
791 LASSERT(rlockh != NULL);
792 LASSERT(dentry != NULL);
793 LASSERT(dentry->d_inode != NULL);
796 if (!mds->mds_lmv_obd)
799 /* a dir can be splitted only */
800 if (!S_ISDIR(dentry->d_inode->i_mode))
803 rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size);
809 if (mea->mea_count == 0) {
810 /* this is slave object */
811 GOTO(cleanup, rc = 0);
814 CDEBUG(D_OTHER, "%s: lock slaves for %lu/%lu\n", obd->obd_name,
815 (unsigned long) dentry->d_inode->i_ino,
816 (unsigned long) dentry->d_inode->i_generation);
818 OBD_ALLOC(*rlockh, sizeof(struct lustre_handle) * mea->mea_count);
820 GOTO(cleanup, rc = -ENOMEM);
821 memset(*rlockh, 0, sizeof(struct lustre_handle) * mea->mea_count);
823 memset(&op_data, 0, sizeof(op_data));
825 it.it_op = IT_UNLINK;
826 rc = md_enqueue(mds->mds_lmv_exp, LDLM_IBITS, &it, LCK_EX, &op_data,
827 *rlockh, NULL, 0, ldlm_completion_ast, mds_blocking_ast,
830 OBD_FREE(mea, mea_size);
834 void mds_unlock_slave_objs(struct obd_device *obd, struct dentry *dentry,
835 struct lustre_handle *lockh)
837 struct mds_obd *mds = &obd->u.mds;
838 struct mea *mea = NULL;
844 LASSERT(mds->mds_lmv_obd != NULL);
845 LASSERT(S_ISDIR(dentry->d_inode->i_mode));
847 rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size);
849 CERROR("locks are leaked\n");
852 LASSERT(mea_size != 0);
853 LASSERT(mea != NULL);
854 LASSERT(mea->mea_count != 0);
856 CDEBUG(D_OTHER, "%s: unlock slaves for %lu/%lu\n", obd->obd_name,
857 (unsigned long) dentry->d_inode->i_ino,
858 (unsigned long) dentry->d_inode->i_generation);
860 for (i = 0; i < mea->mea_count; i++) {
861 if (lockh[i].cookie != 0)
862 ldlm_lock_decref(lockh + i, LCK_EX);
865 OBD_FREE(lockh, sizeof(struct lustre_handle) * mea->mea_count);
866 OBD_FREE(mea, mea_size);
870 int mds_unlink_slave_objs(struct obd_device *obd, struct dentry *dentry)
872 struct mds_obd *mds = &obd->u.mds;
873 struct ptlrpc_request *req = NULL;
874 struct mdc_op_data op_data;
875 struct mea *mea = NULL;
879 if (!mds->mds_lmv_obd)
882 /* a dir can be splitted only */
883 if (!S_ISDIR(dentry->d_inode->i_mode))
886 rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size);
892 if (mea->mea_count == 0)
893 GOTO(cleanup, rc = 0);
895 CDEBUG(D_OTHER, "%s: unlink slaves for %lu/%lu\n", obd->obd_name,
896 (unsigned long) dentry->d_inode->i_ino,
897 (unsigned long) dentry->d_inode->i_generation);
899 memset(&op_data, 0, sizeof(op_data));
901 rc = md_unlink(mds->mds_lmv_exp, &op_data, &req);
902 LASSERT(req == NULL);
904 OBD_FREE(mea, mea_size);
908 struct ide_tracking {
913 int mds_ide_filldir(void *__buf, const char *name, int namelen,
914 loff_t offset, ino_t ino, unsigned int d_type)
916 struct ide_tracking *it = __buf;
926 if (name[0] == '.' && namelen == 1)
928 if (name[0] == '.' && name[1] == '.' && namelen == 2)
935 int mds_is_dir_empty(struct obd_device *obd, struct dentry *dentry)
937 struct ide_tracking it;
945 nlen = strlen("__iopen__/") + 10 + 1;
946 OBD_ALLOC(file_name, nlen);
949 i = sprintf(file_name, "__iopen__/0x%lx", dentry->d_inode->i_ino);
951 file = filp_open(file_name, O_RDONLY, 0);
953 CERROR("can't open directory %s: %d\n",
954 file_name, (int) PTR_ERR(file));
955 GOTO(cleanup, rc = PTR_ERR(file));
958 rc = vfs_readdir(file, mds_ide_filldir, &it);
961 if (it.empty && rc == 0)
967 OBD_FREE(file_name, nlen);
971 int mds_lock_and_check_slave(int offset, struct ptlrpc_request *req,
972 struct lustre_handle *lockh)
974 struct obd_device *obd = req->rq_export->exp_obd;
975 struct dentry *dentry = NULL;
976 struct lvfs_run_ctxt saved;
977 int cleanup_phase = 0;
978 struct mds_body *body;
979 struct lvfs_ucred uc;
983 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
984 lustre_swab_mds_body);
986 CERROR("Can't swab mds_body\n");
987 GOTO(cleanup, rc = -EFAULT);
989 CDEBUG(D_OTHER, "%s: check slave %lu/%lu\n", obd->obd_name,
990 (unsigned long) body->fid1.id,
991 (unsigned long) body->fid1.generation);
992 dentry = mds_fid2locked_dentry(obd, &body->fid1, NULL, LCK_EX, lockh,
993 &update_mode, NULL, 0,
994 MDS_INODELOCK_UPDATE);
995 if (IS_ERR(dentry)) {
996 CERROR("can't find inode: %d\n", (int) PTR_ERR(dentry));
997 GOTO(cleanup, rc = PTR_ERR(dentry));
1001 LASSERT(S_ISDIR(dentry->d_inode->i_mode));
1003 uc.luc_fsuid = body->fsuid;
1004 uc.luc_fsgid = body->fsgid;
1005 uc.luc_cap = body->capability;
1006 uc.luc_suppgid1 = body->suppgid;
1007 uc.luc_suppgid2 = -1;
1008 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1011 if (!mds_is_dir_empty(obd, dentry))
1015 switch(cleanup_phase) {
1018 ldlm_lock_decref(lockh, LCK_EX);
1020 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);