summaryrefslogtreecommitdiffstats
path: root/xlators/nfs/server/src/nfs3-helpers.c
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2010-05-31 22:43:52 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-06-01 00:23:46 -0700
commitda08199c57cedb3dc922ed6bec07932cd2aefabd (patch)
treea528dc8a8b4de1a3b9d4b21d038964919e066f50 /xlators/nfs/server/src/nfs3-helpers.c
parent5e03484d1d24ae93f7cad5fe575edd9ce8e0195b (diff)
nfs3: Funge . and .. ino/gen in readdir of root
In the readdir reply for the root of the export, replace the ino and gen number for the . and .. entries with 1 and 0 respectively. On clients which inspect this field, the client will error out due to the change in inode number of the root directory when see for "." .. also needs to be replaced because we do not have a concept of the parent directory of root. The return of 1 and 0 is the same as the behaviour of: stat /.. command. Signed-off-by: Shehjar Tikoo <shehjart@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 942 (NFS crashes as a vmware ESX data store) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=942
Diffstat (limited to 'xlators/nfs/server/src/nfs3-helpers.c')
-rw-r--r--xlators/nfs/server/src/nfs3-helpers.c82
1 files changed, 75 insertions, 7 deletions
diff --git a/xlators/nfs/server/src/nfs3-helpers.c b/xlators/nfs/server/src/nfs3-helpers.c
index feab7b5e8be..95e8601627d 100644
--- a/xlators/nfs/server/src/nfs3-helpers.c
+++ b/xlators/nfs/server/src/nfs3-helpers.c
@@ -702,11 +702,64 @@ nfs3_prep_readdir3args (readdir3args *ra, struct nfs3_fh *fh)
}
+int
+nfs3_is_dot_entry (char *entry)
+{
+ int ret = 0;
+
+ if (!entry)
+ return 0;
+
+ if (strcmp (entry, ".") == 0)
+ ret = 1;
+
+ return ret;
+}
+
+
+int
+nfs3_is_parentdir_entry (char *entry)
+{
+ int ret = 0;
+
+ if (!entry)
+ return 0;
+
+ if (strcmp (entry, "..") == 0)
+ ret = 1;
+
+ return ret;
+}
+
+
+void
+nfs3_funge_root_dotdot_dirent (gf_dirent_t *ent, struct nfs3_fh *dfh)
+{
+ if ((!ent) || (!dfh))
+ return;
+
+ if (nfs3_fh_is_root_fh (dfh) &&
+ nfs3_is_parentdir_entry (ent->d_name)) {
+ ent->d_ino = 1;
+ ent->d_stat.ia_ino = 1;
+ ent->d_stat.ia_gen = 0;
+ }
+
+ if (nfs3_fh_is_root_fh (dfh) &&
+ nfs3_is_dot_entry (ent->d_name)) {
+ ent->d_ino = 1;
+ ent->d_stat.ia_ino = 1;
+ ent->d_stat.ia_gen = 0;
+ }
+
+}
+
+
entry3 *
-nfs3_fill_entry3 (gf_dirent_t *entry)
+nfs3_fill_entry3 (gf_dirent_t *entry, struct nfs3_fh *dfh)
{
entry3 *ent = NULL;
- if (!entry)
+ if ((!entry) || (!dfh))
return NULL;
ent = GF_CALLOC (1, sizeof (*ent), gf_nfs_mt_entry3);
@@ -714,6 +767,14 @@ nfs3_fill_entry3 (gf_dirent_t *entry)
return NULL;
gf_log (GF_NFS3, GF_LOG_TRACE, "Entry: %s", entry->d_name);
+
+ /* If the entry is . or .., we need to replace the physical ino and gen
+ * with 1 and 0 respectively if the directory is root. This funging is
+ * needed because there is no parent directory of the root. In that
+ * sense the behavious we provide is similar to the output of the
+ * command: "stat /.."
+ */
+ nfs3_funge_root_dotdot_dirent (entry, dfh);
ent->fileid = entry->d_ino;
ent->cookie = entry->d_off;
ent->name = GF_CALLOC ((strlen (entry->d_name) + 1), sizeof (char),
@@ -775,6 +836,13 @@ nfs3_fill_entryp3 (gf_dirent_t *entry, struct nfs3_fh *dirfh)
if ((!entry) || (!dirfh))
return NULL;
+ /* If the entry is . or .., we need to replace the physical ino and gen
+ * with 1 and 0 respectively if the directory is root. This funging is
+ * needed because there is no parent directory of the root. In that
+ * sense the behavious we provide is similar to the output of the
+ * command: "stat /.."
+ */
+ nfs3_funge_root_dotdot_dirent (entry, dirfh);
gf_log (GF_NFS3, GF_LOG_TRACE, "Entry: %s, ino: %"PRIu64,
entry->d_name, entry->d_ino);
ent = GF_CALLOC (1, sizeof (*ent), gf_nfs_mt_entryp3);
@@ -802,9 +870,9 @@ err:
void
-nfs3_fill_readdir3res (readdir3res *res, nfsstat3 stat, uint64_t cverf,
- struct iatt *dirstat, gf_dirent_t *entries, count3 count,
- int is_eof, uint16_t xlid)
+nfs3_fill_readdir3res (readdir3res *res, nfsstat3 stat, struct nfs3_fh *dirfh,
+ uint64_t cverf, struct iatt *dirstat,
+ gf_dirent_t *entries, count3 count, int is_eof)
{
post_op_attr dirattr;
entry3 *ent = NULL;
@@ -818,7 +886,7 @@ nfs3_fill_readdir3res (readdir3res *res, nfsstat3 stat, uint64_t cverf,
if (stat != NFS3_OK)
return;
- nfs3_map_xlid_to_statdev (dirstat, xlid);
+ nfs3_map_xlid_to_statdev (dirstat, dirfh->xlatorid);
dirattr = nfs3_stat_to_post_op_attr (dirstat);
res->readdir3res_u.resok.dir_attributes = dirattr;
res->readdir3res_u.resok.reply.eof = (bool_t)is_eof;
@@ -834,7 +902,7 @@ nfs3_fill_readdir3res (readdir3res *res, nfsstat3 stat, uint64_t cverf,
(strcmp (entries->d_name, "..") == 0))
goto nextentry;
*/
- ent = nfs3_fill_entry3 (entries);
+ ent = nfs3_fill_entry3 (entries, dirfh);
if (!ent)
break;