X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmds%2Fmds_lmv.c;h=c99a387cdf1f84cd8b34fdbe6d689382a37d2f91;hb=30964bcc157e3ad76714b7e55491112c3ae8ebad;hp=228cbfc5630b71a40ca10613e3a22998db629f3d;hpb=4fd42f6ef396a71405578687276fb750f7829e73;p=fs%2Flustre-release.git diff --git a/lustre/mds/mds_lmv.c b/lustre/mds/mds_lmv.c index 228cbfc..c99a387 100644 --- a/lustre/mds/mds_lmv.c +++ b/lustre/mds/mds_lmv.c @@ -28,64 +28,75 @@ #define DEBUG_SUBSYSTEM S_MDS #include +#include +#include +#include +#include +#include +#include #include #include #include #include #include #include +#include #include "mds_internal.h" - /* * TODO: * - magic in mea struct - * - error handling is totally missed */ - -int mds_lmv_connect(struct obd_device *obd, char * lmv_name) +int mds_md_connect(struct obd_device *obd, char *md_name) { struct mds_obd *mds = &obd->u.mds; struct lustre_handle conn = {0}; int rc, valsize, value; ENTRY; - if (IS_ERR(mds->mds_lmv_obd)) - RETURN(PTR_ERR(mds->mds_lmv_obd)); + if (IS_ERR(mds->mds_md_obd)) + RETURN(PTR_ERR(mds->mds_md_obd)); - if (mds->mds_lmv_obd) + if (mds->mds_md_connected) RETURN(0); - mds->mds_lmv_obd = class_name2obd(lmv_name); - if (!mds->mds_lmv_obd) { - CERROR("MDS cannot locate LMV %s\n", - lmv_name); - mds->mds_lmv_obd = ERR_PTR(-ENOTCONN); - RETURN(-ENOTCONN); + down(&mds->mds_md_sem); + if (mds->mds_md_connected) { + up(&mds->mds_md_sem); + RETURN(0); } - rc = obd_connect(&conn, mds->mds_lmv_obd, &obd->obd_uuid); + mds->mds_md_obd = class_name2obd(md_name); + if (!mds->mds_md_obd) { + CERROR("MDS cannot locate MD(LMV) %s\n", + md_name); + mds->mds_md_obd = ERR_PTR(-ENOTCONN); + GOTO(err_last, rc = -ENOTCONN); + } + + rc = obd_connect(&conn, mds->mds_md_obd, &obd->obd_uuid, NULL, + OBD_OPT_MDS_CONNECTION); if (rc) { - CERROR("MDS cannot connect to LMV %s (%d)\n", - lmv_name, rc); - mds->mds_lmv_obd = ERR_PTR(rc); - RETURN(rc); + CERROR("MDS cannot connect to MD(LMV) %s (%d)\n", + md_name, rc); + mds->mds_md_obd = ERR_PTR(rc); + GOTO(err_last, rc); } - mds->mds_lmv_exp = class_conn2export(&conn); - if (mds->mds_lmv_exp == NULL) + mds->mds_md_exp = class_conn2export(&conn); + if (mds->mds_md_exp == NULL) CERROR("can't get export!\n"); - rc = obd_register_observer(mds->mds_lmv_obd, obd); + rc = obd_register_observer(mds->mds_md_obd, obd); if (rc) { - CERROR("MDS cannot register as observer of LMV %s, " - "rc = %d\n", lmv_name, rc); + CERROR("MDS cannot register as observer of MD(LMV) %s, " + "rc = %d\n", md_name, rc); GOTO(err_discon, rc); } /* retrieve size of EA */ - rc = obd_get_info(mds->mds_lmv_exp, strlen("mdsize"), "mdsize", - &valsize, &value); + rc = obd_get_info(mds->mds_md_exp, strlen("mdsize"), + "mdsize", &valsize, &value); if (rc) GOTO(err_reg, rc); @@ -93,91 +104,158 @@ int mds_lmv_connect(struct obd_device *obd, char * lmv_name) mds->mds_max_mdsize = value; /* find our number in LMV cluster */ - rc = obd_get_info(mds->mds_lmv_exp, strlen("mdsnum"), "mdsnum", - &valsize, &value); + rc = obd_get_info(mds->mds_md_exp, strlen("mdsnum"), + "mdsnum", &valsize, &value); if (rc) GOTO(err_reg, rc); mds->mds_num = value; - rc = obd_set_info(mds->mds_lmv_exp, strlen("inter_mds"), + rc = obd_set_info(mds->mds_md_exp, strlen("inter_mds"), "inter_mds", 0, NULL); if (rc) GOTO(err_reg, rc); - + + if (mds->mds_mds_sec) { + rc = obd_set_info(mds->mds_md_exp, strlen("sec"), "sec", + strlen(mds->mds_mds_sec), mds->mds_mds_sec); + if (rc) + GOTO(err_reg, rc); + } + + mds->mds_md_connected = 1; + up(&mds->mds_md_sem); RETURN(0); err_reg: - obd_register_observer(mds->mds_lmv_obd, NULL); + obd_register_observer(mds->mds_md_obd, NULL); err_discon: - obd_disconnect(mds->mds_lmv_exp, 0); - mds->mds_lmv_exp = NULL; - mds->mds_lmv_obd = ERR_PTR(rc); - RETURN(rc); + obd_disconnect(mds->mds_md_exp, 0); + mds->mds_md_exp = NULL; + mds->mds_md_obd = ERR_PTR(rc); +err_last: + up(&mds->mds_md_sem); + return rc; } -int mds_lmv_postsetup(struct obd_device *obd) +int mds_md_postsetup(struct obd_device *obd) { struct mds_obd *mds = &obd->u.mds; int rc = 0; ENTRY; - if (mds->mds_lmv_exp) - rc = obd_init_ea_size(mds->mds_lmv_exp, mds->mds_max_mdsize, + if (mds->mds_md_exp) { + rc = obd_init_ea_size(mds->mds_md_exp, + mds->mds_max_mdsize, mds->mds_max_cookiesize); + } RETURN(rc); } -int mds_lmv_disconnect(struct obd_device *obd, int flags) +int mds_md_disconnect(struct obd_device *obd, int flags) { struct mds_obd *mds = &obd->u.mds; int rc = 0; ENTRY; - if (!IS_ERR(mds->mds_lmv_obd) && mds->mds_lmv_exp != NULL) { - obd_register_observer(mds->mds_lmv_obd, NULL); + if (!mds->mds_md_connected) + RETURN(0); - /* if obd_disconnect fails (probably because the export was - * disconnected by class_disconnect_exports) then we just need - * to drop our ref. */ - rc = obd_disconnect(mds->mds_lmv_exp, flags); - if (rc) - class_export_put(mds->mds_lmv_exp); + down(&mds->mds_md_sem); + if (!IS_ERR(mds->mds_md_obd) && mds->mds_md_exp != NULL) { + LASSERT(mds->mds_md_connected); - mds->mds_lmv_exp = NULL; - mds->mds_lmv_obd = NULL; - } + obd_register_observer(mds->mds_md_obd, NULL); + if (flags & OBD_OPT_FORCE) { + struct obd_device *lmv_obd; + struct obd_ioctl_data ioc_data = { 0 }; + + lmv_obd = class_exp2obd(mds->mds_md_exp); + if (lmv_obd == NULL) + GOTO(out, rc = 0); + + /* + * making disconnecting lmv stuff do not send anything + * to all remote MDSs from LMV. This is needed to + * prevent possible hanging with endless recovery, when + * MDS sends disconnect to already disconnected + * target. Probably this is wrong, but client does the + * same in --force mode and I do not see why can't we do + * it here. --umka. + */ + lmv_obd->obd_no_recov = 1; + obd_iocontrol(IOC_OSC_SET_ACTIVE, mds->mds_md_exp, + sizeof(ioc_data), &ioc_data, NULL); + } + + /* + * if obd_disconnect() fails (probably because the export was + * disconnected by class_disconnect_exports()) then we just need + * to drop our ref. + */ + mds->mds_md_connected = 0; + rc = obd_disconnect(mds->mds_md_exp, flags); + if (rc) + class_export_put(mds->mds_md_exp); + + out: + mds->mds_md_exp = NULL; + mds->mds_md_obd = NULL; + } + up(&mds->mds_md_sem); RETURN(rc); } -int mds_get_lmv_attr(struct obd_device *obd, struct inode *inode, - struct mea **mea, int *mea_size) +int mds_md_reconnect(struct obd_device *obd) +{ + struct mds_obd *mds = &obd->u.mds; + struct obd_statfs osfs; + int err; + ENTRY; + + /* We don't know state of connections to another MDSes + * before the failure. If MDS we were connected to before + * the failure gets failed, then it will wait for us to + * reconnect and will timed recovery out. bug 4920 */ + if (mds->mds_md_connected == 0) + RETURN(0); + if (mds->mds_md_obd == NULL) + RETURN(0); + + err = obd_statfs(mds->mds_md_obd, &osfs, jiffies - HZ); + if (err) + CERROR("can't reconnect to MDSes after recovery: %d\n", err); + RETURN(0); +} + +int mds_md_get_attr(struct obd_device *obd, struct inode *inode, + struct mea **mea, int *mea_size) { struct mds_obd *mds = &obd->u.mds; int rc; ENTRY; - if (!mds->mds_lmv_obd) + if (!mds->mds_md_obd) RETURN(0); + if (!S_ISDIR(inode->i_mode)) + RETURN(0); /* first calculate mea size */ - *mea_size = obd_alloc_diskmd(mds->mds_lmv_exp, + *mea_size = obd_alloc_diskmd(mds->mds_md_exp, (struct lov_mds_md **)mea); if (*mea_size < 0 || *mea == NULL) return *mea_size < 0 ? *mea_size : -EINVAL; - down(&inode->i_sem); - rc = fsfilt_get_md(obd, inode, *mea, *mea_size); - up(&inode->i_sem); + rc = mds_get_md(obd, inode, *mea, mea_size, 1, 1); if (rc <= 0) { OBD_FREE(*mea, *mea_size); *mea = NULL; } else rc = 0; - + RETURN(rc); } @@ -186,12 +264,13 @@ struct dir_entry { __u16 mds; __u32 ino; __u32 generation; + __u32 fid; char name[0]; }; #define DIR_PAD 4 #define DIR_ROUND (DIR_PAD - 1) -#define DIR_REC_LEN(name_len) (((name_len) + 12 + DIR_ROUND) & ~DIR_ROUND) +#define DIR_REC_LEN(name_len) (((name_len) + 16 + DIR_ROUND) & ~DIR_ROUND) /* this struct holds dir entries for particular MDS to be flushed */ struct dir_cache { @@ -224,7 +303,7 @@ static int dc_new_page_to_cache(struct dir_cache * dirc) page = alloc_page(GFP_KERNEL); if (page == NULL) return -ENOMEM; - list_add_tail(&page->list, &dirc->list); + list_add_tail(&page->lru, &dirc->list); dirc->cur = page_address(page); dirc->free = PAGE_SIZE; return 0; @@ -235,26 +314,43 @@ static int retrieve_generation_numbers(struct dirsplit_control *dc, void *buf) struct mds_obd *mds = &dc->obd->u.mds; struct dir_entry *de; struct dentry *dentry; - char * end; + char *end; end = buf + PAGE_SIZE; de = (struct dir_entry *) buf; while ((char *) de < end && de->namelen) { /* lookup an inode */ LASSERT(de->namelen <= 255); - dentry = ll_lookup_one_len(de->name, dc->dentry, de->namelen); + dentry = ll_lookup_one_len(de->name, dc->dentry, + de->namelen); if (IS_ERR(dentry)) { CERROR("can't lookup %*s: %d\n", de->namelen, de->name, (int) PTR_ERR(dentry)); goto next; } if (dentry->d_inode != NULL) { + int rc; + struct lustre_id sid; + + down(&dentry->d_inode->i_sem); + rc = mds_read_inode_sid(dc->obd, + dentry->d_inode, &sid); + up(&dentry->d_inode->i_sem); + if (rc) { + CERROR("Can't read inode self id, " + "inode %lu, rc %d\n", + dentry->d_inode->i_ino, rc); + goto next; + } + + de->fid = id_fid(&sid); de->mds = mds->mds_num; de->ino = dentry->d_inode->i_ino; de->generation = dentry->d_inode->i_generation; } else if (dentry->d_flags & DCACHE_CROSS_REF) { - de->mds = dentry->d_mdsnum; + de->fid = dentry->d_fid; de->ino = dentry->d_inum; + de->mds = dentry->d_mdsnum; de->generation = dentry->d_generation; } else { CERROR("can't lookup %*s\n", de->namelen, de->name); @@ -287,17 +383,17 @@ static int flush_buffer_onto_mds(struct dirsplit_control *dc, int mdsnum) list_for_each_safe(cur, tmp, &ca->list) { struct page *page; - page = list_entry(cur, struct page, list); + page = list_entry(cur, struct page, lru); LASSERT(page != NULL); retrieve_generation_numbers(dc, page_address(page)); ca->brwc.pg = page; - ca->brwc.off = 0; + ca->brwc.disk_offset = ca->brwc.page_offset = 0; ca->brwc.count = PAGE_SIZE; ca->brwc.flag = 0; ca->oa.o_mds = mdsnum; - rc = obd_brw(OBD_BRW_WRITE, mds->mds_lmv_exp, &ca->oa, + rc = obd_brw(OBD_BRW_WRITE, mds->mds_md_exp, &ca->oa, (struct lov_stripe_md *) dc->mea, 1, &ca->brwc, NULL); if (rc) @@ -320,7 +416,7 @@ static int remove_entries_from_orig_dir(struct dirsplit_control *dc, int mdsnum) ca = dc->cache + mdsnum; list_for_each_safe(cur, tmp, &ca->list) { - page = list_entry(cur, struct page, list); + page = list_entry(cur, struct page, lru); buf = page_address(page); end = buf + PAGE_SIZE; @@ -329,11 +425,11 @@ static int remove_entries_from_orig_dir(struct dirsplit_control *dc, int mdsnum) /* lookup an inode */ LASSERT(de->namelen <= 255); - dentry = ll_lookup_one_len(de->name, dc->dentry, + dentry = ll_lookup_one_len(de->name, dc->dentry, de->namelen); if (IS_ERR(dentry)) { CERROR("can't lookup %*s: %d\n", de->namelen, - de->name, (int) PTR_ERR(dentry)); + de->name, (int) PTR_ERR(dentry)); goto next; } rc = fsfilt_del_dir_entry(dc->obd, dentry); @@ -346,8 +442,8 @@ next: RETURN(0); } -static int filldir(void * __buf, const char * name, int namlen, loff_t offset, - ino_t ino, unsigned int d_type) +static int filldir(void * __buf, const char * name, int namlen, + loff_t offset, ino_t ino, unsigned int d_type) { struct dirsplit_control *dc = __buf; struct mds_obd *mds = &dc->obd->u.mds; @@ -357,8 +453,8 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset, char *n; ENTRY; - if (name[0] == '.' && (namlen == 1 || - (namlen == 2 && name[1] == '.'))) { + if (name[0] == '.' && + (namlen == 1 || (namlen == 2 && name[1] == '.'))) { /* skip special entries */ RETURN(0); } @@ -401,7 +497,7 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset, } int scan_and_distribute(struct obd_device *obd, struct dentry *dentry, - struct mea *mea) + struct mea *mea) { struct inode *dir = dentry->d_inode; struct dirsplit_control dc; @@ -413,7 +509,9 @@ int scan_and_distribute(struct obd_device *obd, struct dentry *dentry, OBD_ALLOC(file_name, nlen); if (!file_name) RETURN(-ENOMEM); - i = sprintf(file_name, "__iopen__/0x%lx", dentry->d_inode->i_ino); + + i = sprintf(file_name, "__iopen__/0x%lx", + dentry->d_inode->i_ino); file = filp_open(file_name, O_RDONLY, 0); if (IS_ERR(file)) { @@ -457,6 +555,7 @@ int scan_and_distribute(struct obd_device *obd, struct dentry *dentry, GOTO(cleanup, err); } + EXIT; cleanup: for (i = 0; i < mea->mea_count; i++) { struct list_head *cur, *tmp; @@ -464,18 +563,19 @@ cleanup: continue; list_for_each_safe(cur, tmp, &dc.cache[i].list) { struct page *page; - page = list_entry(cur, struct page, list); - list_del(&page->list); + page = list_entry(cur, struct page, lru); + list_del(&page->lru); __free_page(page); } } OBD_FREE(dc.cache, sizeof(struct dir_cache) * mea->mea_count); OBD_FREE(file_name, nlen); - RETURN(err); + return err; } -#define MAX_DIR_SIZE (64 * 1024) +#define MAX_DIR_SIZE (64 * 1024) +#define I_NON_SPLITTABLE (256) int mds_splitting_expected(struct obd_device *obd, struct dentry *dentry) { @@ -484,8 +584,8 @@ int mds_splitting_expected(struct obd_device *obd, struct dentry *dentry) int rc, size; /* clustered MD ? */ - if (!mds->mds_lmv_obd) - RETURN(MDS_NO_SPLITTABLE); + if (!mds->mds_md_obd) + return MDS_NO_SPLITTABLE; /* inode exist? */ if (dentry->d_inode == NULL) @@ -495,73 +595,81 @@ int mds_splitting_expected(struct obd_device *obd, struct dentry *dentry) if (!S_ISDIR(dentry->d_inode->i_mode)) return MDS_NO_SPLITTABLE; + /* already splittied or slave directory (part of splitted dir) */ + if (dentry->d_inode->i_flags & I_NON_SPLITTABLE) + return MDS_NO_SPLITTABLE; + /* don't split root directory */ - if (dentry->d_inode->i_ino == mds->mds_rootfid.id) + if (dentry->d_inode->i_ino == id_ino(&mds->mds_rootid)) return MDS_NO_SPLITTABLE; /* large enough to be splitted? */ if (dentry->d_inode->i_size < MAX_DIR_SIZE) return MDS_NO_SPLIT_EXPECTED; - mds_get_lmv_attr(obd, dentry->d_inode, &mea, &size); + mds_md_get_attr(obd, dentry->d_inode, &mea, &size); if (mea) { /* already splitted or slave object: shouldn't be splitted */ rc = MDS_NO_SPLITTABLE; + /* mark to skip subsequent checks */ + dentry->d_inode->i_flags |= I_NON_SPLITTABLE; + OBD_FREE(mea, size); } else { /* may be splitted */ rc = MDS_EXPECT_SPLIT; } - if (mea) - OBD_FREE(mea, size); - RETURN(rc); + return rc; } /* * must not be called on already splitted directories. */ int mds_try_to_split_dir(struct obd_device *obd, struct dentry *dentry, - struct mea **mea, int nstripes) + struct mea **mea, int nstripes, int update_mode) { struct inode *dir = dentry->d_inode; struct mds_obd *mds = &obd->u.mds; struct mea *tmea = NULL; struct obdo *oa = NULL; int rc, mea_size = 0; + struct lustre_id id; void *handle; ENTRY; + if (update_mode != LCK_EX) + return 0; + /* TODO: optimization possible - we already may have mea here */ rc = mds_splitting_expected(obd, dentry); if (rc == MDS_NO_SPLITTABLE) return 0; if (rc == MDS_NO_SPLIT_EXPECTED && nstripes == 0) return 0; + if (nstripes && nstripes == 1) + return 0; LASSERT(mea == NULL || *mea == NULL); CDEBUG(D_OTHER, "%s: split directory %u/%lu/%lu\n", obd->obd_name, mds->mds_num, dir->i_ino, (unsigned long) dir->i_generation); - CDEBUG(D_ERROR, "%s: split directory %u/%lu/%lu\n", - obd->obd_name, mds->mds_num, dir->i_ino, - (unsigned long) dir->i_generation); if (mea == NULL) mea = &tmea; - mea_size = obd_size_diskmd(mds->mds_lmv_exp, NULL); + mea_size = obd_size_diskmd(mds->mds_md_exp, NULL); /* FIXME: Actually we may only want to allocate enough space for * necessary amount of stripes, but on the other hand with this * approach of allocating maximal possible amount of MDS slots, * it would be easier to split the dir over more MDSes */ - rc = obd_alloc_diskmd(mds->mds_lmv_exp, (void *)mea); + rc = obd_alloc_diskmd(mds->mds_md_exp, (void *)mea); if (rc < 0) { CERROR("obd_alloc_diskmd() failed, error %d.\n", rc); RETURN(rc); } if (*mea == NULL) - RETURN(-EINVAL); + RETURN(-ENOMEM); (*mea)->mea_count = nstripes; @@ -571,7 +679,6 @@ int mds_try_to_split_dir(struct obd_device *obd, struct dentry *dentry, if (!oa) RETURN(-ENOMEM); - oa->o_id = dir->i_ino; oa->o_generation = dir->i_generation; obdo_from_inode(oa, dir, OBD_MD_FLTYPE | OBD_MD_FLATIME | @@ -582,14 +689,37 @@ int mds_try_to_split_dir(struct obd_device *obd, struct dentry *dentry, oa->o_valid |= OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP; oa->o_mode = dir->i_mode; + /* + * until lmv_obd_create() properly rewritten, it is important to have + * here oa->o_id = dir->i_ino, as otherwise master object will have + * invalid store cookie (zero inode num), what will lead to -ESTALE in + * mds_open() or somewhere else. + */ + oa->o_id = dir->i_ino; + + down(&dir->i_sem); + rc = mds_read_inode_sid(obd, dir, &id); + up(&dir->i_sem); + if (rc) { + CERROR("Can't read inode self id, inode %lu, " + "rc %d.\n", dir->i_ino, rc); + GOTO(err_oa, rc); + } + oa->o_fid = id_fid(&id); + oa->o_mds = mds->mds_num; + LASSERT(oa->o_fid != 0); + CDEBUG(D_OTHER, "%s: create subdirs with mode %o, uid %u, gid %u\n", - obd->obd_name, dir->i_mode, dir->i_uid, dir->i_gid); + obd->obd_name, dir->i_mode, dir->i_uid, dir->i_gid); - rc = obd_create(mds->mds_lmv_exp, oa, + rc = obd_create(mds->mds_md_exp, oa, NULL, 0, (struct lov_stripe_md **)mea, NULL); - if (rc) + if (rc) { + CERROR("Can't create remote inode, rc = %d\n", rc); GOTO(err_oa, rc); + } + LASSERT(id_fid(&(*mea)->mea_ids[0])); CDEBUG(D_OTHER, "%d dirobjects created\n", (int)(*mea)->mea_count); /* 2) update dir attribute */ @@ -601,8 +731,8 @@ int mds_try_to_split_dir(struct obd_device *obd, struct dentry *dentry, CERROR("fsfilt_start() failed: %d\n", (int) PTR_ERR(handle)); GOTO(err_oa, rc = PTR_ERR(handle)); } - - rc = fsfilt_set_md(obd, dir, handle, *mea, mea_size); + + rc = fsfilt_set_md(obd, dir, handle, *mea, mea_size, EA_MEA); if (rc) { up(&dir->i_sem); CERROR("fsfilt_set_md() failed, error %d.\n", rc); @@ -622,7 +752,7 @@ int mds_try_to_split_dir(struct obd_device *obd, struct dentry *dentry, /* 3) read through the dir and distribute it over objects */ rc = scan_and_distribute(obd, dentry, *mea); if (mea == &tmea) - obd_free_diskmd(mds->mds_lmv_exp, (struct lov_mds_md **)mea); + obd_free_diskmd(mds->mds_md_exp, (struct lov_mds_md **)mea); if (rc) { CERROR("scan_and_distribute() failed, error %d.\n", rc); RETURN(rc); @@ -632,7 +762,7 @@ int mds_try_to_split_dir(struct obd_device *obd, struct dentry *dentry, err_oa: obdo_free(oa); - RETURN(rc); + return rc; } static int filter_start_page_write(struct inode *inode, @@ -641,18 +771,17 @@ static int filter_start_page_write(struct inode *inode, struct page *page = alloc_pages(GFP_HIGHUSER, 0); if (page == NULL) { CERROR("no memory for a temp page\n"); - RETURN(lnb->rc = -ENOMEM); + return lnb->rc = -ENOMEM; } POISON_PAGE(page, 0xf1); page->index = lnb->offset >> PAGE_SHIFT; lnb->page = page; - return 0; } -struct dentry *filter_fid2dentry(struct obd_device *obd, - struct dentry *dir_dentry, - obd_gr group, obd_id id); +struct dentry *filter_id2dentry(struct obd_device *obd, + struct dentry *dir_dentry, + obd_gr group, obd_id id); int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa, int objcount, struct obd_ioobj *obj, @@ -660,25 +789,29 @@ int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa, struct niobuf_local *res, struct obd_trans_info *oti) { - struct mds_obd *mds = &exp->exp_obd->u.mds; struct niobuf_remote *rnb; struct niobuf_local *lnb = NULL; int rc = 0, i, tot_bytes = 0; unsigned long now = jiffies; struct dentry *dentry; - struct ll_fid fid; + struct lustre_id id; ENTRY; + LASSERT(objcount == 1); LASSERT(obj->ioo_bufcnt > 0); memset(res, 0, niocount * sizeof(*res)); - fid.id = obj->ioo_id; - fid.generation = obj->ioo_gr; - dentry = mds_fid2dentry(mds, &fid, NULL); + id_fid(&id) = 0; + id_group(&id) = 0; + id_ino(&id) = obj->ioo_id; + id_gen(&id) = obj->ioo_gr; + + dentry = mds_id2dentry(exp->exp_obd, &id, NULL); if (IS_ERR(dentry)) { CERROR("can't get dentry for "LPU64"/%u: %d\n", - fid.id, fid.generation, (int) PTR_ERR(dentry)); + id.li_stc.u.e3s.l3s_ino, id.li_stc.u.e3s.l3s_gen, + (int)PTR_ERR(dentry)); GOTO(cleanup, rc = (int) PTR_ERR(dentry)); } @@ -754,12 +887,12 @@ int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa, while ((char *) de < end && de->namelen) { err = fsfilt_add_dir_entry(obd, res->dentry, de->name, de->namelen, de->ino, - de->generation, de->mds); + de->generation, de->mds, + de->fid); if (err) { CERROR("can't add dir entry %*s->%u/%u/%u" - " to %lu/%u: %d\n", - de->namelen, de->name, - de->mds, (unsigned) de->ino, + " to %lu/%u: %d\n", de->namelen, + de->name, de->mds, (unsigned)de->ino, (unsigned) de->generation, res->dentry->d_inode->i_ino, res->dentry->d_inode->i_generation, @@ -790,9 +923,9 @@ int mds_choose_mdsnum(struct obd_device *obd, const char *name, int len, int fla if (flags & REC_REINT_CREATE) { i = mds->mds_num; - } else if (mds->mds_lmv_exp) { - lmv = &mds->mds_lmv_exp->exp_obd->u.lmv; - i = raw_name2idx(lmv->desc.ld_tgt_count, name, len); + } else if (mds->mds_md_exp) { + lmv = &mds->mds_md_exp->exp_obd->u.lmv; + i = raw_name2idx(MEA_MAGIC_LAST_CHAR, lmv->desc.ld_tgt_count, name, len); } RETURN(i); } @@ -801,70 +934,92 @@ int mds_lock_slave_objs(struct obd_device *obd, struct dentry *dentry, struct lustre_handle **rlockh) { struct mds_obd *mds = &obd->u.mds; - struct mdc_op_data op_data; + struct mdc_op_data *op_data; struct lookup_intent it; struct mea *mea = NULL; int mea_size, rc; + int handle_size; + ENTRY; LASSERT(rlockh != NULL); LASSERT(dentry != NULL); LASSERT(dentry->d_inode != NULL); /* clustered MD ? */ - if (!mds->mds_lmv_obd) - return 0; + if (!mds->mds_md_obd) + RETURN(0); /* a dir can be splitted only */ if (!S_ISDIR(dentry->d_inode->i_mode)) - return 0; + RETURN(0); - rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size); + rc = mds_md_get_attr(obd, dentry->d_inode, + &mea, &mea_size); if (rc) - return rc; + RETURN(rc); if (mea == NULL) - return 0; - if (mea->mea_count == 0) { + RETURN(0); + + if (mea->mea_count == 0) /* this is slave object */ GOTO(cleanup, rc = 0); - } - CDEBUG(D_OTHER, "%s: lock slaves for %lu/%lu\n", obd->obd_name, - (unsigned long) dentry->d_inode->i_ino, - (unsigned long) dentry->d_inode->i_generation); + CDEBUG(D_OTHER, "%s: lock slaves for %lu/%lu\n", + obd->obd_name, (unsigned long)dentry->d_inode->i_ino, + (unsigned long)dentry->d_inode->i_generation); - OBD_ALLOC(*rlockh, sizeof(struct lustre_handle) * mea->mea_count); + handle_size = sizeof(struct lustre_handle) * + mea->mea_count; + + OBD_ALLOC(*rlockh, handle_size); if (*rlockh == NULL) GOTO(cleanup, rc = -ENOMEM); - memset(*rlockh, 0, sizeof(struct lustre_handle) * mea->mea_count); - memset(&op_data, 0, sizeof(op_data)); - op_data.mea1 = mea; + memset(*rlockh, 0, handle_size); + OBD_ALLOC(op_data, sizeof(*op_data)); + if (op_data == NULL) { + OBD_FREE(*rlockh, handle_size); + RETURN(-ENOMEM); + } + memset(op_data, 0, sizeof(*op_data)); + + op_data->mea1 = mea; it.it_op = IT_UNLINK; - rc = md_enqueue(mds->mds_lmv_exp, LDLM_IBITS, &it, LCK_EX, &op_data, - *rlockh, NULL, 0, ldlm_completion_ast, mds_blocking_ast, - NULL); + + OBD_ALLOC(it.d.fs_data, sizeof(struct lustre_intent_data)); + + rc = md_enqueue(mds->mds_md_exp, LDLM_IBITS, &it, LCK_EX, + op_data, *rlockh, NULL, 0, ldlm_completion_ast, + mds_blocking_ast, NULL); + OBD_FREE(op_data, sizeof(*op_data)); + OBD_FREE(it.d.fs_data, sizeof(struct lustre_intent_data)); + EXIT; cleanup: OBD_FREE(mea, mea_size); - RETURN(rc); + return rc; } void mds_unlock_slave_objs(struct obd_device *obd, struct dentry *dentry, - struct lustre_handle *lockh) + struct lustre_handle *lockh) { struct mds_obd *mds = &obd->u.mds; struct mea *mea = NULL; int mea_size, rc, i; + ENTRY; - if (lockh == NULL) + if (lockh == NULL) { + EXIT; return; + } - LASSERT(mds->mds_lmv_obd != NULL); + LASSERT(mds->mds_md_obd != NULL); LASSERT(S_ISDIR(dentry->d_inode->i_mode)); - rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size); + rc = mds_md_get_attr(obd, dentry->d_inode, &mea, &mea_size); if (rc) { CERROR("locks are leaked\n"); + EXIT; return; } LASSERT(mea_size != 0); @@ -882,45 +1037,53 @@ void mds_unlock_slave_objs(struct obd_device *obd, struct dentry *dentry, OBD_FREE(lockh, sizeof(struct lustre_handle) * mea->mea_count); OBD_FREE(mea, mea_size); - return; + EXIT; } int mds_unlink_slave_objs(struct obd_device *obd, struct dentry *dentry) { struct mds_obd *mds = &obd->u.mds; struct ptlrpc_request *req = NULL; - struct mdc_op_data op_data; + struct mdc_op_data *op_data; struct mea *mea = NULL; int mea_size, rc; + ENTRY; /* clustered MD ? */ - if (!mds->mds_lmv_obd) - return 0; + if (!mds->mds_md_obd) + RETURN(0); /* a dir can be splitted only */ if (!S_ISDIR(dentry->d_inode->i_mode)) RETURN(0); - rc = mds_get_lmv_attr(obd, dentry->d_inode, &mea, &mea_size); + rc = mds_md_get_attr(obd, dentry->d_inode, &mea, &mea_size); if (rc) RETURN(rc); if (mea == NULL) - return 0; + RETURN(0); + if (mea->mea_count == 0) GOTO(cleanup, rc = 0); CDEBUG(D_OTHER, "%s: unlink slaves for %lu/%lu\n", obd->obd_name, - (unsigned long) dentry->d_inode->i_ino, - (unsigned long) dentry->d_inode->i_generation); + (unsigned long)dentry->d_inode->i_ino, + (unsigned long)dentry->d_inode->i_generation); - memset(&op_data, 0, sizeof(op_data)); - op_data.mea1 = mea; - rc = md_unlink(mds->mds_lmv_exp, &op_data, &req); + OBD_ALLOC(op_data, sizeof(*op_data)); + if (op_data == NULL) + RETURN(-ENOMEM); + + memset(op_data, 0, sizeof(*op_data)); + op_data->mea1 = mea; + rc = md_unlink(mds->mds_md_exp, op_data, &req); + OBD_FREE(op_data, sizeof(*op_data)); LASSERT(req == NULL); + EXIT; cleanup: OBD_FREE(mea, mea_size); - RETURN(rc); + return rc; } struct ide_tracking { @@ -950,6 +1113,7 @@ noempty: return -ENOTEMPTY; } +/* checks if passed dentry points to empty dir. */ int mds_is_dir_empty(struct obd_device *obd, struct dentry *dentry) { struct ide_tracking it; @@ -964,7 +1128,10 @@ int mds_is_dir_empty(struct obd_device *obd, struct dentry *dentry) OBD_ALLOC(file_name, nlen); if (!file_name) RETURN(-ENOMEM); - i = sprintf(file_name, "__iopen__/0x%lx", dentry->d_inode->i_ino); + + LASSERT(dentry->d_inode != NULL); + i = sprintf(file_name, "__iopen__/0x%lx", + dentry->d_inode->i_ino); file = filp_open(file_name, O_RDONLY, 0); if (IS_ERR(file)) { @@ -993,52 +1160,119 @@ int mds_lock_and_check_slave(int offset, struct ptlrpc_request *req, struct dentry *dentry = NULL; struct lvfs_run_ctxt saved; int cleanup_phase = 0; + struct mds_req_sec_desc *rsd; struct mds_body *body; struct lvfs_ucred uc; int rc, update_mode; ENTRY; + rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF); + if (!rsd) { + CERROR("Can't unpack security desc\n"); + GOTO(cleanup, rc = -EFAULT); + } + body = lustre_swab_reqbuf(req, offset, sizeof(*body), lustre_swab_mds_body); if (body == NULL) { CERROR("Can't swab mds_body\n"); GOTO(cleanup, rc = -EFAULT); } - CDEBUG(D_OTHER, "%s: check slave %lu/%lu\n", obd->obd_name, - (unsigned long) body->fid1.id, - (unsigned long) body->fid1.generation); - dentry = mds_fid2locked_dentry(obd, &body->fid1, NULL, LCK_EX, lockh, - &update_mode, NULL, 0, - MDS_INODELOCK_UPDATE); + CDEBUG(D_OTHER, "%s: check slave "DLID4"\n", obd->obd_name, + OLID4(&body->id1)); + + dentry = mds_id2locked_dentry(obd, &body->id1, NULL, LCK_EX, + lockh, &update_mode, NULL, 0, + MDS_INODELOCK_UPDATE); if (IS_ERR(dentry)) { CERROR("can't find inode: %d\n", (int) PTR_ERR(dentry)); GOTO(cleanup, rc = PTR_ERR(dentry)); } cleanup_phase = 1; - LASSERT(S_ISDIR(dentry->d_inode->i_mode)); + /* + * handling the case when remote MDS checks if dir is empty + * before rename. But it also does it for all entries, because + * inode is stored here and remote MDS does not know if rename + * point to dir or to reg file. So we check it here. + */ + if (!S_ISDIR(dentry->d_inode->i_mode)) + GOTO(cleanup, rc = 0); - uc.luc_fsuid = body->fsuid; - uc.luc_fsgid = body->fsgid; - uc.luc_cap = body->capability; - uc.luc_suppgid1 = body->suppgid; - uc.luc_suppgid2 = -1; - push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc); + rc = mds_init_ucred(&uc, req, rsd); + if (rc) { + GOTO(cleanup, rc); + } - rc = 0; - if (!mds_is_dir_empty(obd, dentry)) - rc = -ENOTEMPTY; + push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc); + rc = mds_is_dir_empty(obd, dentry) ? 0 : -ENOTEMPTY; + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc); + mds_exit_ucred(&uc); + EXIT; cleanup: switch(cleanup_phase) { case 1: if (rc) ldlm_lock_decref(lockh, LCK_EX); l_dput(dentry); - pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc); default: break; } - RETURN(rc); + return rc; +} + +int mds_convert_mea_ea(struct obd_device *obd, struct inode *inode, + struct lov_mds_md *lmm, int lmm_size) +{ + struct lov_stripe_md *lsm = NULL; + struct mea_old *old; + struct mea *mea; + void *handle; + int rc, err; + ENTRY; + + mea = (struct mea *)lmm; + old = (struct mea_old *)lmm; + + if (mea->mea_magic == MEA_MAGIC_LAST_CHAR || + mea->mea_magic == MEA_MAGIC_ALL_CHARS) + RETURN(0); + + /* + * making MDS try LOV EA converting in the non-LMV configuration + * cases. + */ + if (!obd->u.mds.mds_md_exp) + RETURN(-EINVAL); + + CDEBUG(D_INODE, "converting MEA EA on %lu/%u from V0 to V1 (%u/%u)\n", + inode->i_ino, inode->i_generation, old->mea_count, + old->mea_master); + + rc = obd_unpackmd(obd->u.mds.mds_md_exp, &lsm, lmm, lmm_size); + if (rc < 0) + GOTO(conv_end, rc); + + rc = obd_packmd(obd->u.mds.mds_md_exp, &lmm, lsm); + if (rc < 0) + GOTO(conv_free, rc); + lmm_size = rc; + + handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL); + if (IS_ERR(handle)) { + rc = PTR_ERR(handle); + GOTO(conv_free, rc); + } + + rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_MEA); + err = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 0); + if (!rc) + rc = err ? err : lmm_size; + GOTO(conv_free, rc); +conv_free: + obd_free_memmd(obd->u.mds.mds_md_exp, &lsm); +conv_end: + return rc; }