Commit dd14459e authored by Neil Brown's avatar Neil Brown Committed by Linus Torvalds

[PATCH] nfsd4: move code to truncate on open to separate function

for OPEN with O_TRUNC, if the truncate fails, the open fails.  for
nfs4_open_upgrade, this means undo the get_write_access.  for new OPENs, this
means release the newly created stateid.
Signed-off-by: default avatarAndy Adamson <andros@citi.umich.edu>
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
Signed-off-by: default avatarNeil Brown <neilb@cse.unsw.edu.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 71dd672e
...@@ -1302,6 +1302,18 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct svc_fh *cur_fh, struct nfs4_sta ...@@ -1302,6 +1302,18 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct svc_fh *cur_fh, struct nfs4_sta
status = get_write_access(inode); status = get_write_access(inode);
if (status) if (status)
return nfserrno(status); return nfserrno(status);
if (open->op_truncate) {
struct iattr iattr = {
.ia_valid = ATTR_SIZE,
.ia_size = 0,
};
status = nfsd_setattr(rqstp, cur_fh, &iattr, 0,
(time_t)0);
if (status) {
put_write_access(inode);
return status;
}
}
/* remember the open */ /* remember the open */
filp->f_mode = (filp->f_mode | FMODE_WRITE) & ~FMODE_READ; filp->f_mode = (filp->f_mode | FMODE_WRITE) & ~FMODE_READ;
...@@ -1332,7 +1344,6 @@ nfs4_set_claim_prev(struct nfsd4_open *open, int *status) ...@@ -1332,7 +1344,6 @@ nfs4_set_claim_prev(struct nfsd4_open *open, int *status)
int int
nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open) nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
{ {
struct iattr iattr;
struct nfs4_stateowner *sop = open->op_stateowner; struct nfs4_stateowner *sop = open->op_stateowner;
struct nfs4_file *fp = NULL; struct nfs4_file *fp = NULL;
struct inode *ino; struct inode *ino;
...@@ -1383,18 +1394,23 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf ...@@ -1383,18 +1394,23 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
if ((status = nfs4_new_open(rqstp, &stp, current_fh, flags))) if ((status = nfs4_new_open(rqstp, &stp, current_fh, flags)))
goto out; goto out;
init_stateid(stp, fp, sop, open); init_stateid(stp, fp, sop, open);
if (open->op_truncate) {
struct iattr iattr = {
.ia_valid = ATTR_SIZE,
.ia_size = 0,
};
status = nfsd_setattr(rqstp, current_fh, &iattr, 0,
(time_t)0);
if (status) {
release_stateid(stp, OPEN_STATE);
goto out;
}
}
} }
dprintk("nfs4_process_open2: stateid=(%08x/%08x/%08x/%08x)\n", dprintk("nfs4_process_open2: stateid=(%08x/%08x/%08x/%08x)\n",
stp->st_stateid.si_boot, stp->st_stateid.si_stateownerid, stp->st_stateid.si_boot, stp->st_stateid.si_stateownerid,
stp->st_stateid.si_fileid, stp->st_stateid.si_generation); stp->st_stateid.si_fileid, stp->st_stateid.si_generation);
if (open->op_truncate) {
iattr.ia_valid = ATTR_SIZE;
iattr.ia_size = 0;
status = nfsd_setattr(rqstp, current_fh, &iattr, 0, (time_t)0);
if (status)
goto out;
}
memcpy(&open->op_stateid, &stp->st_stateid, sizeof(stateid_t)); memcpy(&open->op_stateid, &stp->st_stateid, sizeof(stateid_t));
open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE; open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment