X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmds%2Fmds_audit_path.c;h=637aeea31959af6881b392c50f7672557a316b6a;hb=b5745c153b081b42e3806f6aaf35b96ce1eb195f;hp=10a13a512509b233a2afbcec4d80c71a1298f68d;hpb=48fa8f1ce78826c86946cf9f34a0abc5ad07b8af;p=fs%2Flustre-release.git diff --git a/lustre/mds/mds_audit_path.c b/lustre/mds/mds_audit_path.c index 10a13a5..637aeea 100644 --- a/lustre/mds/mds_audit_path.c +++ b/lustre/mds/mds_audit_path.c @@ -74,7 +74,7 @@ static int filldir(void *__buf, const char *name, int namlen, LASSERT(sd != NULL); /* skip non-cross_ref entries if we need cross-ref */ - if (sd->cross_ref && d_type & 128) + if (sd->cross_ref && !(d_type & 128)) RETURN(0); if (ino == sd->i_num) { @@ -112,10 +112,11 @@ static int scan_name_in_parent(struct lustre_id *pid, struct lustre_id *id, sd.name = name; sd.cross_ref = cr; sd.rc = -ENOENT; - vfs_readdir(file, filldir, &sd); + rc = vfs_readdir(file, filldir, &sd); + if (!rc) + rc = sd.rc; filp_close(file, 0); - rc = sd.rc; out: OBD_FREE(pname, len); @@ -162,6 +163,7 @@ id2pid(struct obd_device *obd, struct lustre_id *id, struct lustre_id *pid, } else { *type = PP_SPLIT_SLAVE; *pid = mea->mea_ids[mea->mea_master]; + LASSERT(id_fid(pid)); } } else { @@ -198,14 +200,14 @@ static int local_parse_id(struct obd_device *obd, struct parseid_pkg *pkg) pkg->pp_type = 0; memset(pkg->pp_name, 0, sizeof(pkg->pp_name)); - //LASSERT(obd->u.mds.mds_num == id_group(&pkg->pp_id1)); - /* pp_id2 is present, which indicating we want to scan parent * dir(pp_id2) to find the cross-ref entry(pp_id1) */ if (id_fid(&pkg->pp_id2)) { + LASSERT(obd->u.mds.mds_num == id_group(&pkg->pp_id2)); pkg->pp_type = PP_DIR; cross_ref = 1; } else { + LASSERT(obd->u.mds.mds_num == id_group(&pkg->pp_id1)); rc = id2pid(obd, &pkg->pp_id1, &pkg->pp_id2, &pkg->pp_type); if (rc) GOTO(out, rc); @@ -275,12 +277,12 @@ static int parse_id(struct obd_device *obd, struct parseid_pkg *pkg) int mds_num = id_group(&pkg->pp_id1); ENTRY; - LASSERT(mds_num >= 0); - //for cross-ref dir we should send request to parent's MDS if (pkg->pp_type == PP_CROSS_DIR) mds_num = id_group(&pkg->pp_id2); + LASSERT(mds_num >= 0); + if (mds_num == obd->u.mds.mds_num) { rc = local_parse_id(obd, pkg); } else { @@ -297,7 +299,7 @@ static int parse_id(struct obd_device *obd, struct parseid_pkg *pkg) RETURN(rc); exp = lmv->tgts[mds_num].ltd_exp; - LASSERT(exp); + LASSERTF(exp, "No export for MDS #%i\n", mds_num); req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, MDS_PARSE_ID, 1, @@ -367,7 +369,7 @@ mds_id2name(struct obd_device *obd, struct lustre_id *id, INIT_LIST_HEAD(&item->link); list_add(&item->link, list); memcpy(item->name, pkg->pp_name, sizeof(item->name)); - + case PP_SPLIT_SLAVE: pkg->pp_id1 = pkg->pp_id2; memset(&pkg->pp_id2, 0, sizeof(struct lustre_id)); @@ -397,24 +399,23 @@ scan_audit_log_cb(struct llog_handle *llh, struct llog_rec_hdr *rec, void *data) CERROR("log is not plain\n"); RETURN(-EINVAL); } - if (rec->lrh_type != SMFS_AUDIT_NAME_REC && - rec->lrh_type != LLOG_GEN_REC) { + + if (rec->lrh_type != SMFS_AUDIT_NAME_REC) RETURN(0); - } - + ad_rec = (struct audit_record *)(rec + 1); - - if (ad_rec->result || - ad_rec->opcode != AUDIT_UNLINK || - ad_rec->opcode != AUDIT_RENAME) + if (ad_rec->result || + (ad_rec->opcode != AUDIT_UNLINK && + ad_rec->opcode != AUDIT_RENAME)) RETURN(0); cid_rec = (struct audit_id_record *)(ad_rec + 1); pid_rec = cid_rec + 1; nm_rec = (struct audit_name_record *)(pid_rec + 1); - + if (cid_rec->au_num == id_ino(&pkg->pp_id1) && cid_rec->au_gen == id_gen(&pkg->pp_id1)) { + LASSERT(pid_rec->au_fid); /* get parent id */ id_ino(&pkg->pp_id2) = pid_rec->au_num; id_gen(&pkg->pp_id2) = pid_rec->au_gen; @@ -424,7 +425,6 @@ scan_audit_log_cb(struct llog_handle *llh, struct llog_rec_hdr *rec, void *data) /* get name */ memcpy(pkg->pp_name, nm_rec->name, le32_to_cpu(nm_rec->name_len)); - RETURN(LLOG_PROC_BREAK); } RETURN(0); @@ -439,18 +439,23 @@ local_scan_audit_log(struct obd_device *obd, struct parseid_pkg *pkg) int rc = 0; ENTRY; + pkg->pp_rc = 0; if (ctxt) llh = ctxt->loc_handle; if (llh == NULL) - RETURN(-ENOENT); + GOTO(out, rc = -ENOENT); rc = llog_cat_process(llh, (llog_cb_t)&scan_audit_log_cb, (void *)pkg); if (rc != LLOG_PROC_BREAK) { CWARN("process catalog log failed: rc(%d)\n", rc); - RETURN(-ENOENT); + rc = -ENOENT; + } else { + rc = 0; } - RETURN(0); +out: + pkg->pp_rc = rc; + RETURN(rc); } static int @@ -485,7 +490,7 @@ scan_audit_log(struct obd_device *obd, struct lustre_id *cur_id, RETURN(rc); exp = lmv->tgts[mds_num].ltd_exp; - LASSERT(exp); + LASSERTF(exp, "No export for MDS #%i\n", mds_num); req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, MDS_PARSE_ID, 1, @@ -546,14 +551,18 @@ mds_audit_id2name(struct obd_device *obd, char **name, int *namelen, INIT_LIST_HEAD(&list); cur_id = *id; + if (!id_ino(&cur_id)) { + CERROR("Invalid id!\n"); + RETURN(-EINVAL); + } if (id_fid(&cur_id) == ROOT_FID) RETURN(0); + next: memset(&parent_id, 0, sizeof(parent_id)); rc = mds_id2name(obd, &cur_id, &list, &parent_id); if (rc == -ENOENT) { /* can't reconstruct name from id, turn to audit log */ - LASSERT(id_fid(&parent_id)); cur_id = parent_id; memset(&parent_id, 0, sizeof(parent_id)); @@ -576,18 +585,23 @@ next: item = list_entry(pos, struct name_item, link); *namelen += strlen(item->name) + 1; } + + (*namelen)++; /* for the ending '\0' of string */ OBD_ALLOC(*name, *namelen); if (*name == NULL) rc = -ENOMEM; out: list_for_each_safe (pos, n, &list) { item = list_entry(pos, struct name_item, link); + if (!rc) { strcat(*name, "/"); strcat(*name, item->name); } list_del_init(&item->link); OBD_FREE(item, sizeof(*item)); + if (*name) + LASSERT(strlen(*name) < *namelen); } RETURN(rc); }