Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Trenameat and Tunlinkat #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 101 additions & 2 deletions src/libdiod/diod_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ int diod_exportok (Npfid *fid);
int diod_auth_required (Npstr *uname, u32 n_uname, Npstr *aname);
char *diod_get_path (Npfid *fid);
char *diod_get_files (char *name, void *a);
Npfcall *diod_renameat(Npfid *olddirfid, Npstr *oldname, Npfid *newdirfid,
Npstr *newname);
Npfcall *diod_unlinkat(Npfid *dirfid, Npstr *name, u32 flags);

int
diod_init (Npsrv *srv)
Expand Down Expand Up @@ -187,8 +190,8 @@ diod_init (Npsrv *srv)
srv->getlock = diod_getlock;
srv->link = diod_link;
srv->mkdir = diod_mkdir;
//srv->renameat = diod_renameat;
//srv->unlinkat = diod_unlinkat;
srv->renameat = diod_renameat;
srv->unlinkat = diod_unlinkat;

if (!np_ctl_addfile (srv->ctlroot, "exports", diod_get_exports, srv, 0))
goto error;
Expand Down Expand Up @@ -1475,6 +1478,102 @@ diod_xattrcreate (Npfid *fid, Npstr *name, u64 attr_size, u32 flags)
return NULL;
}

Npfcall*
diod_renameat(Npfid *olddirfid, Npstr *oldname, Npfid *newdirfid, Npstr *newname)
{
Fid *odf = olddirfid->aux;
Fid *ndf = newdirfid->aux;
Npsrv *srv = olddirfid->conn->srv;
Npfcall *ret = NULL;
Path opath = NULL, npath = NULL;

if (!(opath = path_append (srv, odf->path, oldname))) {
np_uerror (ENOMEM);
goto error;
}

if (!(npath = path_append (srv, ndf->path, newname))) {
np_uerror (ENOMEM);
goto error;
}

if (rename (path_s (opath), path_s (npath)) < 0) {
np_uerror (errno);
goto error_quiet;
}

if (!(ret = np_create_rrenameat ())) {
np_uerror (ENOMEM);
goto error;
}

path_decref (srv, npath);
path_decref (srv, opath);
return ret;
error:
errn (np_rerror (), "diod_renameat %s@%s:%s -> %s",
olddirfid->user->uname, np_conn_get_client_id (olddirfid->conn),
path_s (opath), path_s (npath));
error_quiet:
if (npath)
path_decref (srv, npath);
if (opath)
path_decref (srv, opath);
return NULL;
}

Npfcall*
diod_unlinkat(Npfid *dirfid, Npstr *name, u32 flags)
{
Fid *df = dirfid->aux;
Path rpath = NULL;
Npfcall *ret = NULL;
Npsrv *srv = dirfid->conn->srv;
struct stat st;

if (!(rpath = path_append (srv, df->path, name))) {
np_uerror (ENOMEM);
goto error;
}

if (lstat (path_s (rpath), &st) < 0) {
np_uerror (errno);
goto error;
}

if (S_ISDIR (st.st_mode)) {
if (!(flags & Uremovedir)) {
np_uerror (EISDIR);
goto error_quiet;
}

if (rmdir (path_s (rpath)) < 0) {
np_uerror (errno);
goto error_quiet;
}
}
else if (unlink (path_s (rpath)) < 0) {
np_uerror (errno);
goto error_quiet;
}

if (!(ret = np_create_runlinkat())) {
np_uerror (ENOMEM);
goto error;
}

path_decref (srv, rpath);
return ret;
error:
errn (np_rerror (), "diod_unlinkat %s@%s:%s",
dirfid->user->uname, np_conn_get_client_id (dirfid->conn),
path_s (rpath));
error_quiet:
if (rpath)
path_decref (srv, rpath);
return NULL;
}

char *
diod_get_path (Npfid *fid)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libnpfs/fcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ np_unlinkat (Npreq *req, Npfcall *tc)
np_uerror (95); /* v9fs expects this not ENOSYS for this op */
goto done;
}
rc = (*req->conn->srv->unlinkat)(dirfid, &tc->u.tunlinkat.name);
rc = (*req->conn->srv->unlinkat)(dirfid, &tc->u.tunlinkat.name, tc->u.tunlinkat.flags);
done:
return rc;
}
2 changes: 1 addition & 1 deletion src/libnpfs/npfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ struct Npsrv {
Npfcall* (*link)(Npfid *, Npfid *, Npstr *);
Npfcall* (*mkdir)(Npfid *, Npstr *, u32, u32);
Npfcall* (*renameat)(Npfid *, Npstr *, Npfid *, Npstr *);
Npfcall* (*unlinkat)(Npfid *, Npstr *);
Npfcall* (*unlinkat)(Npfid *, Npstr *, u32);

/* implementation specific */
pthread_mutex_t lock;
Expand Down
5 changes: 5 additions & 0 deletions src/libnpfs/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ enum {
Osync = 04000000,
};

// flags for Tunlinkat
enum {
Uremovedir = 0x200,
};

// flags for Tlock
enum {
Lblock = 1,
Expand Down