it = (struct osd_zap_it *)osd_index_it_init(env, dt, unused);
if (!IS_ERR(it))
- it->ozi_pos = 0;
+ it->ozi_pos = OZI_POS_INIT;
RETURN((struct dt_it *)it);
}
LASSERT(((const char *)key)[0] == 0);
if (name[0] == 0) {
- it->ozi_pos = 0;
+ it->ozi_pos = OZI_POS_INIT;
RETURN(1);
}
if (name[0] == '.') {
if (name[1] == 0) {
- it->ozi_pos = 1;
+ it->ozi_pos = OZI_POS_DOT;
GOTO(out, rc = 1);
} else if (name[1] == '.' && name[2] == 0) {
- it->ozi_pos = 2;
+ it->ozi_pos = OZI_POS_DOTDOT;
GOTO(out, rc = 1);
}
}
/* neither . nor .. - some real record */
- it->ozi_pos = 3;
+ it->ozi_pos = OZI_POS_REAL;
rc = +1;
out:
* the second ->next() moves the cursor to ..
* then we get to the real records and have to verify any exist
*/
- if (it->ozi_pos <= 2) {
+ if (it->ozi_pos <= OZI_POS_DOTDOT) {
it->ozi_pos++;
- if (it->ozi_pos <=2)
+ if (it->ozi_pos <= OZI_POS_DOTDOT)
RETURN(0);
} else {
int rc = 0;
ENTRY;
- if (it->ozi_pos <= 1) {
- it->ozi_pos = 1;
+ if (it->ozi_pos <= OZI_POS_DOT) {
+ it->ozi_pos = OZI_POS_DOT;
RETURN((struct dt_key *)".");
- } else if (it->ozi_pos == 2) {
+ } else if (it->ozi_pos == OZI_POS_DOTDOT) {
RETURN((struct dt_key *)"..");
}
int rc;
ENTRY;
- if (it->ozi_pos <= 1) {
- it->ozi_pos = 1;
+ if (it->ozi_pos <= OZI_POS_DOT) {
+ it->ozi_pos = OZI_POS_DOT;
RETURN(2);
- } else if (it->ozi_pos == 2) {
+ } else if (it->ozi_pos == OZI_POS_DOTDOT) {
RETURN(3);
}
ENTRY;
lde->lde_attrs = 0;
- if (it->ozi_pos <= 1) {
- lde->lde_hash = cpu_to_le64(1);
+ if (it->ozi_pos <= OZI_POS_DOT) {
+ /* notice hash=0 here, this is needed to avoid
+ * case when some real entry (after ./..) may
+ * have hash=0. in this case the client would
+ * be confused having records out of hash order. */
+ lde->lde_hash = cpu_to_le64(0);
strcpy(lde->lde_name, ".");
lde->lde_namelen = cpu_to_le16(1);
fid_cpu_to_le(&lde->lde_fid,
/* append lustre attributes */
osd_it_append_attrs(lde, attr, 1, IFTODT(S_IFDIR));
lde->lde_reclen = cpu_to_le16(lu_dirent_calc_size(1, attr));
- it->ozi_pos = 1;
+ it->ozi_pos = OZI_POS_DOT;
RETURN(0);
- } else if (it->ozi_pos == 2) {
- lde->lde_hash = cpu_to_le64(2);
+ } else if (it->ozi_pos == OZI_POS_DOTDOT) {
+ /* same as for . above */
+ lde->lde_hash = cpu_to_le64(0);
strcpy(lde->lde_name, "..");
lde->lde_namelen = cpu_to_le16(2);
rc = osd_find_parent_fid(env, &it->ozi_obj->oo_dt, fid, NULL);
int rc;
ENTRY;
- if (it->ozi_pos <= 1)
+ if (it->ozi_pos <= OZI_POS_DOT)
namelen = 1;
- else if (it->ozi_pos == 2)
+ else if (it->ozi_pos == OZI_POS_DOTDOT)
namelen = 2;
if (namelen > 0) {
__u64 pos;
ENTRY;
- if (it->ozi_pos <= 2)
- pos = it->ozi_pos;
+ if (it->ozi_pos <= OZI_POS_DOTDOT)
+ pos = 0;
else
pos = osd_zap_cursor_serialize(it->ozi_zc);
zap_cursor_fini(it->ozi_zc);
osd_obj_cursor_init_serialized(it->ozi_zc, obj, hash);
- if (hash <= 2) {
- it->ozi_pos = hash;
- rc = +1;
+ if (hash == 0) {
+ it->ozi_pos = OZI_POS_INIT;
+ rc = +1; /* there will be ./.. at least */
} else {
- it->ozi_pos = 3;
+ it->ozi_pos = OZI_POS_REAL;
/* to return whether the end has been reached */
rc = osd_index_retrieve_skip_dots(it, za);
if (rc == 0)
unsigned oiq_reset:1; /* 1 -- no need to advance */
};
+enum osd_zap_pos {
+ OZI_POS_INIT = 0,
+ OZI_POS_DOT = 1, /* cursor at . */
+ OZI_POS_DOTDOT = 2, /* cursor at .. */
+ OZI_POS_REAL = 3, /* cursor at real entries */
+};
+
/**
* Iterator's in-memory data structure for ZAPs
*
zap_cursor_t *ozi_zc;
struct osd_object *ozi_obj;
unsigned ozi_reset:1; /* 1 -- no need to advance */
- /* ozi_pos - position of the cursor:
- * 0 - before any record
- * 1 - "."
- * 2 - ".."
- * 3 - real records */
- unsigned ozi_pos:3;
+ /* ozi_pos - position of the cursor */
+ enum osd_zap_pos ozi_pos;
union {
char ozi_name[MAXNAMELEN]; /* file name for dir */
__u64 ozi_key; /* binary key for index files */