Skip to content

Commit 48e370f

Browse files
kvaneeshericvh
authored andcommitted
fs/9p: add 9P2000.L unlinkat operation
unlinkat - Remove a directory entry size[4] Tunlinkat tag[2] dirfid[4] name[s] flag[4] size[4] Runlinkat tag[2] older Tremove have the below request format size[4] Tremove tag[2] fid[4] The remove message is used to remove a directory entry either file or directory The remove opreation is actually a directory opertation and should ideally have dirfid, if not we cannot represent the fid on server with anything other than name. We will have to derive the directory name from fid in the Tremove request. NOTE: The operation doesn't clunk the unlink fid. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
1 parent 9e8fb38 commit 48e370f

4 files changed

Lines changed: 56 additions & 18 deletions

File tree

‎fs/9p/vfs_inode.c‎

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -534,38 +534,50 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
534534
/**
535535
* v9fs_remove - helper function to remove files and directories
536536
* @dir: directory inode that is being deleted
537-
* @file: dentry that is being deleted
537+
* @dentry: dentry that is being deleted
538538
* @rmdir: removing a directory
539539
*
540540
*/
541541

542-
static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
542+
static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags)
543543
{
544-
int retval;
545-
struct p9_fid *v9fid;
546-
struct inode *file_inode;
547-
548-
P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
549-
rmdir);
544+
struct inode *inode;
545+
int retval = -EOPNOTSUPP;
546+
struct p9_fid *v9fid, *dfid;
547+
struct v9fs_session_info *v9ses;
550548

551-
file_inode = file->d_inode;
552-
v9fid = v9fs_fid_clone(file);
553-
if (IS_ERR(v9fid))
554-
return PTR_ERR(v9fid);
549+
P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %x\n",
550+
dir, dentry, flags);
555551

556-
retval = p9_client_remove(v9fid);
552+
v9ses = v9fs_inode2v9ses(dir);
553+
inode = dentry->d_inode;
554+
dfid = v9fs_fid_lookup(dentry->d_parent);
555+
if (IS_ERR(dfid)) {
556+
retval = PTR_ERR(dfid);
557+
P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", retval);
558+
return retval;
559+
}
560+
if (v9fs_proto_dotl(v9ses))
561+
retval = p9_client_unlinkat(dfid, dentry->d_name.name, flags);
562+
if (retval == -EOPNOTSUPP) {
563+
/* Try the one based on path */
564+
v9fid = v9fs_fid_clone(dentry);
565+
if (IS_ERR(v9fid))
566+
return PTR_ERR(v9fid);
567+
retval = p9_client_remove(v9fid);
568+
}
557569
if (!retval) {
558570
/*
559571
* directories on unlink should have zero
560572
* link count
561573
*/
562-
if (rmdir) {
563-
clear_nlink(file_inode);
574+
if (flags & AT_REMOVEDIR) {
575+
clear_nlink(inode);
564576
drop_nlink(dir);
565577
} else
566-
drop_nlink(file_inode);
578+
drop_nlink(inode);
567579

568-
v9fs_invalidate_inode_attr(file_inode);
580+
v9fs_invalidate_inode_attr(inode);
569581
v9fs_invalidate_inode_attr(dir);
570582
}
571583
return retval;
@@ -856,7 +868,7 @@ int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
856868

857869
int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
858870
{
859-
return v9fs_remove(i, d, 1);
871+
return v9fs_remove(i, d, AT_REMOVEDIR);
860872
}
861873

862874
/**

‎include/net/9p/9p.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ enum p9_msg_t {
183183
P9_RMKDIR,
184184
P9_TRENAMEAT = 74,
185185
P9_RRENAMEAT,
186+
P9_TUNLINKAT = 76,
187+
P9_RUNLINKAT,
186188
P9_TVERSION = 100,
187189
P9_RVERSION,
188190
P9_TAUTH = 102,

‎include/net/9p/client.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode,
234234
int p9_client_clunk(struct p9_fid *fid);
235235
int p9_client_fsync(struct p9_fid *fid, int datasync);
236236
int p9_client_remove(struct p9_fid *fid);
237+
int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags);
237238
int p9_client_read(struct p9_fid *fid, char *data, char __user *udata,
238239
u64 offset, u32 count);
239240
int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,

‎net/9p/client.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,29 @@ int p9_client_remove(struct p9_fid *fid)
13031303
}
13041304
EXPORT_SYMBOL(p9_client_remove);
13051305

1306+
int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags)
1307+
{
1308+
int err = 0;
1309+
struct p9_req_t *req;
1310+
struct p9_client *clnt;
1311+
1312+
P9_DPRINTK(P9_DEBUG_9P, ">>> TUNLINKAT fid %d %s %d\n",
1313+
dfid->fid, name, flags);
1314+
1315+
clnt = dfid->clnt;
1316+
req = p9_client_rpc(clnt, P9_TUNLINKAT, "dsd", dfid->fid, name, flags);
1317+
if (IS_ERR(req)) {
1318+
err = PTR_ERR(req);
1319+
goto error;
1320+
}
1321+
P9_DPRINTK(P9_DEBUG_9P, "<<< RUNLINKAT fid %d %s\n", dfid->fid, name);
1322+
1323+
p9_free_req(clnt, req);
1324+
error:
1325+
return err;
1326+
}
1327+
EXPORT_SYMBOL(p9_client_unlinkat);
1328+
13061329
int
13071330
p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
13081331
u32 count)

0 commit comments

Comments
 (0)