Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 624bd5b7 authored by Anna Schumaker's avatar Anna Schumaker Committed by Trond Myklebust
Browse files

nfs: Add DEALLOCATE support



This patch adds support for using the NFS v4.2 operation DEALLOCATE to
punch holes in a file.

Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
parent f4ac1674
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@


/* nfs4.2proc.c */
/* nfs4.2proc.c */
int nfs42_proc_allocate(struct file *, loff_t, loff_t);
int nfs42_proc_allocate(struct file *, loff_t, loff_t);
int nfs42_proc_deallocate(struct file *, loff_t, loff_t);
loff_t nfs42_proc_llseek(struct file *, loff_t, int);
loff_t nfs42_proc_llseek(struct file *, loff_t, int);


/* nfs4.2xdr.h */
/* nfs4.2xdr.h */
+17 −0
Original line number Original line Diff line number Diff line
@@ -90,6 +90,23 @@ int nfs42_proc_allocate(struct file *filep, loff_t offset, loff_t len)
	return err;
	return err;
}
}


int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len)
{
	struct rpc_message msg = {
		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DEALLOCATE],
	};
	struct inode *inode = file_inode(filep);
	int err;

	if (!nfs_server_capable(inode, NFS_CAP_DEALLOCATE))
		return -EOPNOTSUPP;

	err = nfs42_proc_fallocate(&msg, filep, offset, len);
	if (err == -EOPNOTSUPP)
		NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE;
	return err;
}

loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
{
{
	struct inode *inode = file_inode(filep);
	struct inode *inode = file_inode(filep);
+64 −0
Original line number Original line Diff line number Diff line
@@ -10,6 +10,9 @@
#define encode_allocate_maxsz		(op_encode_hdr_maxsz + \
#define encode_allocate_maxsz		(op_encode_hdr_maxsz + \
					 encode_fallocate_maxsz)
					 encode_fallocate_maxsz)
#define decode_allocate_maxsz		(op_decode_hdr_maxsz)
#define decode_allocate_maxsz		(op_decode_hdr_maxsz)
#define encode_deallocate_maxsz		(op_encode_hdr_maxsz + \
					 encode_fallocate_maxsz)
#define decode_deallocate_maxsz		(op_decode_hdr_maxsz)
#define encode_seek_maxsz		(op_encode_hdr_maxsz + \
#define encode_seek_maxsz		(op_encode_hdr_maxsz + \
					 encode_stateid_maxsz + \
					 encode_stateid_maxsz + \
					 2 /* offset */ + \
					 2 /* offset */ + \
@@ -26,6 +29,12 @@
#define NFS4_dec_allocate_sz		(compound_decode_hdr_maxsz + \
#define NFS4_dec_allocate_sz		(compound_decode_hdr_maxsz + \
					 decode_putfh_maxsz + \
					 decode_putfh_maxsz + \
					 decode_allocate_maxsz)
					 decode_allocate_maxsz)
#define NFS4_enc_deallocate_sz		(compound_encode_hdr_maxsz + \
					 encode_putfh_maxsz + \
					 encode_deallocate_maxsz)
#define NFS4_dec_deallocate_sz		(compound_decode_hdr_maxsz + \
					 decode_putfh_maxsz + \
					 decode_deallocate_maxsz)
#define NFS4_enc_seek_sz		(compound_encode_hdr_maxsz + \
#define NFS4_enc_seek_sz		(compound_encode_hdr_maxsz + \
					 encode_putfh_maxsz + \
					 encode_putfh_maxsz + \
					 encode_seek_maxsz)
					 encode_seek_maxsz)
@@ -50,6 +59,14 @@ static void encode_allocate(struct xdr_stream *xdr,
	encode_fallocate(xdr, args);
	encode_fallocate(xdr, args);
}
}


static void encode_deallocate(struct xdr_stream *xdr,
			      struct nfs42_falloc_args *args,
			      struct compound_hdr *hdr)
{
	encode_op_hdr(xdr, OP_DEALLOCATE, decode_deallocate_maxsz, hdr);
	encode_fallocate(xdr, args);
}

static void encode_seek(struct xdr_stream *xdr,
static void encode_seek(struct xdr_stream *xdr,
			struct nfs42_seek_args *args,
			struct nfs42_seek_args *args,
			struct compound_hdr *hdr)
			struct compound_hdr *hdr)
@@ -78,6 +95,24 @@ static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
	encode_nops(&hdr);
	encode_nops(&hdr);
}
}


/*
 * Encode DEALLOCATE request
 */
static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
				    struct xdr_stream *xdr,
				    struct nfs42_falloc_args *args)
{
	struct compound_hdr hdr = {
		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
	};

	encode_compound_hdr(xdr, req, &hdr);
	encode_sequence(xdr, &args->seq_args, &hdr);
	encode_putfh(xdr, args->falloc_fh, &hdr);
	encode_deallocate(xdr, args, &hdr);
	encode_nops(&hdr);
}

/*
/*
 * Encode SEEK request
 * Encode SEEK request
 */
 */
@@ -101,6 +136,11 @@ static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
	return decode_op_hdr(xdr, OP_ALLOCATE);
	return decode_op_hdr(xdr, OP_ALLOCATE);
}
}


static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
{
	return decode_op_hdr(xdr, OP_DEALLOCATE);
}

static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
{
{
	int status;
	int status;
@@ -147,6 +187,30 @@ static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
	return status;
	return status;
}
}


/*
 * Decode DEALLOCATE request
 */
static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
				   struct xdr_stream *xdr,
				   struct nfs42_falloc_res *res)
{
	struct compound_hdr hdr;
	int status;

	status = decode_compound_hdr(xdr, &hdr);
	if (status)
		goto out;
	status = decode_sequence(xdr, &res->seq_res, rqstp);
	if (status)
		goto out;
	status = decode_putfh(xdr);
	if (status)
		goto out;
	status = decode_deallocate(xdr, res);
out:
	return status;
}

/*
/*
 * Decode SEEK request
 * Decode SEEK request
 */
 */
+5 −2
Original line number Original line Diff line number Diff line
@@ -145,7 +145,7 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t
	if (!S_ISREG(inode->i_mode))
	if (!S_ISREG(inode->i_mode))
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;


	if (mode != 0)
	if ((mode != 0) && (mode != (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE)))
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;


	ret = inode_newsize_ok(inode, offset + len);
	ret = inode_newsize_ok(inode, offset + len);
@@ -153,6 +153,9 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t
		return ret;
		return ret;


	mutex_lock(&inode->i_mutex);
	mutex_lock(&inode->i_mutex);
	if (mode & FALLOC_FL_PUNCH_HOLE)
		ret = nfs42_proc_deallocate(filep, offset, len);
	else
		ret = nfs42_proc_allocate(filep, offset, len);
		ret = nfs42_proc_allocate(filep, offset, len);
	mutex_unlock(&inode->i_mutex);
	mutex_unlock(&inode->i_mutex);


+1 −0
Original line number Original line Diff line number Diff line
@@ -8425,6 +8425,7 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
		| NFS_CAP_STATEID_NFSV41
		| NFS_CAP_STATEID_NFSV41
		| NFS_CAP_ATOMIC_OPEN_V1
		| NFS_CAP_ATOMIC_OPEN_V1
		| NFS_CAP_ALLOCATE
		| NFS_CAP_ALLOCATE
		| NFS_CAP_DEALLOCATE
		| NFS_CAP_SEEK,
		| NFS_CAP_SEEK,
	.init_client = nfs41_init_client,
	.init_client = nfs41_init_client,
	.shutdown_client = nfs41_shutdown_client,
	.shutdown_client = nfs41_shutdown_client,
Loading