From cad39264b6651b6f2824c46ea73d77764235f3d9 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Fri, 29 Sep 2023 16:16:49 -0500 Subject: [PATCH] fs: Get parent dir cell for 'fs getfid -literal' After we get the fid for the requested path, 'fs getfid' then gets the cell for the path: GetCell(ti->data, cell); But ti->data is the full path requested, whether -literal was given or not. If the given path ends with a broken symlink/mountpoint or nonexistent fid, we've already gotten the fid (if -literal was given) but we'll still exit with an (often confusing) error: $ fs getfid symlink.broken -literal fs: no such cell as 'symlink.broken' In addition, if we use 'fs getfid -literal' to get the fid of a cross-cell mountpoint object, we'll get the wrong cell. We'll report the cell of the mountpoint's target, instead of the cell of the reported fid: $ fs getfid /afs/example.com -literal File /afs/example.com (1.16777244.1) located in cell example.com To fix these, pass 'parent_dir' to GetCell() when -literal is given. To do this, we need to not free parent_dir until later, so reorganize the 'parent_dir' and 'last_component' vars to be freed at the end of the loop, and change the 'continue' code paths to goto the end of the loop instead. With this, the cell is now reported properly for these cases: $ fs getfid symlink.broken -literal File symlink.broken (536871063.22.865) located in cell example.com $ fs getfid /afs/example.com -literal File /afs/example.com (1.16777244.1) located in cell dynroot Change-Id: I8ec297dae84f677d530b6f7c39786f18c2a9c50f Reviewed-on: https://gerrit.openafs.org/15584 Reviewed-by: Mark Vitale Reviewed-by: Marcio Brito Barbosa Reviewed-by: Cheyenne Wills Reviewed-by: Andrew Deason Tested-by: BuildBot --- src/venus/fs.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/venus/fs.c b/src/venus/fs.c index e07a07f6e3..d4a512fd41 100644 --- a/src/venus/fs.c +++ b/src/venus/fs.c @@ -4261,50 +4261,54 @@ GetFidCmd(struct cmd_syndesc *as, void *arock) } for (ti = as->parms[0].items; ti; ti = ti->next) { struct VenusFid vfid; + char *parent_dir = NULL; + char *last_component = NULL; blob.out_size = sizeof(struct VenusFid); blob.out = (char *) &vfid; blob.in_size = 0; if (literal) { - char *parent_dir = NULL; - char *last_component = NULL; - if (GetLastComponent(ti->data, &parent_dir, &last_component, NULL, literal) != 0) { error = 1; - continue; + goto next_item; } blob.in = last_component; blob.in_size = strlen(last_component) + 1; code = pioctl(parent_dir, VIOC_GETLITERALFID, &blob, 1); - free(parent_dir); - free(last_component); } else { code = pioctl(ti->data, VIOCGETFID, &blob, 1); } if (code) { Die(errno,ti->data); error = 1; - continue; + goto next_item; } - code = GetCell(ti->data, cell); + if (literal) { + code = GetCell(parent_dir, cell); + } else { + code = GetCell(ti->data, cell); + } if (code) { if (errno == ENOENT) fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data); else Die(errno, ti->data); error = 1; - continue; + goto next_item; } printf("File %s (%u.%u.%u) located in cell %s\n", ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique, cell); + next_item: + free(parent_dir); + free(last_component); } return error;