Whamcloud - gitweb
b=9729
[fs/lustre-release.git] / lustre / mds / mds_audit_path.c
index 4f1a927..637aeea 100644 (file)
@@ -73,6 +73,10 @@ 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))
+                RETURN(0);
+
         if (ino == sd->i_num) {
                 strncpy(sd->name, name, namlen);
                 sd->rc = 0;
@@ -108,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);
@@ -158,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 {
@@ -194,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);
@@ -271,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 {
@@ -293,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, 
@@ -363,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));
@@ -393,25 +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 *)((char *)rec + sizeof(*rec));
-
-        if (ad_rec->result || 
-            ad_rec->opcode != AUDIT_UNLINK ||
-            ad_rec->opcode != AUDIT_RENAME)
+        
+        ad_rec = (struct audit_record *)(rec + 1);
+        if (ad_rec->result ||
+            (ad_rec->opcode != AUDIT_UNLINK &&
+             ad_rec->opcode != AUDIT_RENAME))
                 RETURN(0);
 
-        cid_rec = (struct audit_id_record *)((char *)ad_rec + sizeof(*ad_rec));
+        cid_rec = (struct audit_id_record *)(ad_rec + 1);
         pid_rec = cid_rec + 1;
-        nm_rec = (struct audit_name_record *)
-                ((char *)pid_rec + sizeof(*pid_rec));
-        
+        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;
@@ -421,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);
@@ -436,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 
@@ -482,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, 
@@ -543,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));
 
@@ -573,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);
 }