Exemple #1
0
/*
 * Decode READ reply
 */
static int
nfs_xdr_readres(struct rpc_rqst *req, u32 *p, struct nfs_readres *res)
{
	struct kvec *iov = req->rq_rcv_buf.head;
	int	status, count, recvd, hdrlen;

	if ((status = ntohl(*p++)))
		return -nfs_stat_to_errno(status);
	p = xdr_decode_fattr(p, res->fattr);

	count = ntohl(*p++);
	res->eof = 0;
	hdrlen = (u8 *) p - (u8 *) iov->iov_base;
	if (iov->iov_len < hdrlen) {
		printk(KERN_WARNING "NFS: READ reply header overflowed:"
				"length %d > %Zu\n", hdrlen, iov->iov_len);
		return -errno_NFSERR_IO;
	} else if (iov->iov_len != hdrlen) {
		dprintk("NFS: READ header is short. iovec will be shifted.\n");
		xdr_shift_buf(&req->rq_rcv_buf, iov->iov_len - hdrlen);
	}

	recvd = req->rq_rcv_buf.len - hdrlen;
	if (count > recvd) {
		printk(KERN_WARNING "NFS: server cheating in read reply: "
			"count %d > recvd %d\n", count, recvd);
		count = recvd;
	}

	dprintk("RPC:      readres OK count %d\n", count);
	if (count < res->count)
		res->count = count;

	return count;
}
Exemple #2
0
int nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
		     struct nfs_fattr *fattr)
{
	int *p, *p0;
	int status;
	int ruid = 0;

	PRINTK("NFS call  getattr\n");
	if (!(p0 = nfs_rpc_alloc(server->rsize)))
		return -EIO;
retry:
	p = nfs_rpc_header(p0, NFSPROC_GETATTR, ruid);
	p = xdr_encode_fhandle(p, fhandle);
	if ((status = nfs_rpc_call(server, p0, p, server->rsize)) < 0) {
		nfs_rpc_free(p0);
		return status;
	}
	if (!(p = nfs_rpc_verify(p0)))
		status = -errno_NFSERR_IO;
	else if ((status = ntohl(*p++)) == NFS_OK) {
		p = xdr_decode_fattr(p, fattr);
		PRINTK("NFS reply getattr\n");
		/* status = 0; */
	}
	else {
		if (!ruid && current->fsuid == 0 && current->uid != 0) {
			ruid = 1;
			goto retry;
		}
		PRINTK("NFS reply getattr failed = %d\n", status);
		status = -nfs_stat_to_errno(status);
	}
	nfs_rpc_free(p0);
	return status;
}
Exemple #3
0
static inline __be32 *
xdr_decode_post_op_attr(__be32 *p, struct nfs_fattr *fattr)
{
	if (*p++)
		p = xdr_decode_fattr(p, fattr);
	return p;
}
Exemple #4
0
/*
 * Decode attrstat reply
 * GETATTR, SETATTR, WRITE
 */
static int
nfs_xdr_attrstat(struct rpc_rqst *req, u32 *p, struct nfs_fattr *fattr)
{
	int	status;

	if ((status = ntohl(*p++)))
		return -nfs_stat_to_errno(status);
	xdr_decode_fattr(p, fattr);
	return 0;
}
Exemple #5
0
/*
 * Decode diropres reply
 * LOOKUP, CREATE, MKDIR
 */
static int
nfs_xdr_diropres(struct rpc_rqst *req, u32 *p, struct nfs_diropok *res)
{
	int	status;

	if ((status = ntohl(*p++)))
		return -nfs_stat_to_errno(status);
	p = xdr_decode_fhandle(p, res->fh);
	xdr_decode_fattr(p, res->fattr);
	return 0;
}
Exemple #6
0
int nfs_proc_read(struct nfs_server *server, struct nfs_fh *fhandle,
	  int offset, int count, char *data, struct nfs_fattr *fattr, int fs)
{
	int *p, *p0;
	int status;
	int ruid = 0;
	int len;

	PRINTK("NFS call  read %d @ %d\n", count, offset);
	if (!(p0 = nfs_rpc_alloc(server->rsize)))
		return -EIO;
retry:
	p = nfs_rpc_header(p0, NFSPROC_READ, ruid);
	p = xdr_encode_fhandle(p, fhandle);
	*p++ = htonl(offset);
	*p++ = htonl(count);
	*p++ = htonl(count); /* traditional, could be any value */
	if ((status = nfs_rpc_call(server, p0, p, server->rsize)) < 0) {
		nfs_rpc_free(p0);
		return status;
	}
	if (!(p = nfs_rpc_verify(p0)))
		status = -errno_NFSERR_IO;
	else if ((status = ntohl(*p++)) == NFS_OK) {
		p = xdr_decode_fattr(p, fattr);
		if (!(p = xdr_decode_data(p, data, &len, count, fs))) {
			printk("nfs_proc_read: giant data size\n"); 
			status = -errno_NFSERR_IO;
		}
		else {
			status = len;
			PRINTK("NFS reply read %d\n", len);
		}
	}
	else {
		if (!ruid && current->fsuid == 0 && current->uid != 0) {
			ruid = 1;
			goto retry;
		}
		PRINTK("NFS reply read failed = %d\n", status);
		status = -nfs_stat_to_errno(status);
	}
	nfs_rpc_free(p0);
	return status;
}
Exemple #7
0
static inline __be32 *
xdr_decode_post_op_attr_stream(struct xdr_stream *xdr, struct nfs_fattr *fattr)
{
	__be32 *p;

	p = xdr_inline_decode(xdr, 4);
	if (unlikely(!p))
		goto out_overflow;
	if (ntohl(*p++)) {
		p = xdr_inline_decode(xdr, 84);
		if (unlikely(!p))
			goto out_overflow;
		p = xdr_decode_fattr(p, fattr);
	}
	return p;
out_overflow:
	print_overflow_msg(__func__, xdr);
	return ERR_PTR(-EIO);
}
Exemple #8
0
/* not parallel */
int 
nfs_proc_read_np(struct nfs_fh *fhandle, int offset, int count, 
	      char *data, struct nfs_fattr *fattr) {
    int *p;
    int len = 0;
    int status;
    int ruid = 0;
    struct generic_server *server = fhandle->server;
    int *p0;
    
    DPRINTF(CLUHELP_LEVEL,("NFS call  read %d @ %d\n", count, offset));
    if (!(p0 = overhead_rpc_alloc(server->rsize)))
	return -EIO;

    p = nfs_rpc_header(p0, NFSPROC_READ, ruid);
    p = xdr_encode_fhandle(p, fhandle);
    *p++ = htonl(offset);
    *p++ = htonl(count);
    *p++ = htonl(count);		/* traditional, could be any value */

    DPRINTF(CLUHELP_LEVEL,("ORIGNAL\n"));
    /*     print_rpc2(p0,128); */
    if ((status = generic_rpc_call(server, p0, p)) < 0) {
	overhead_rpc_free(p0);
	return status;
    }


    if (!(p = generic_rpc_verify(p0)))
	status = NFSERR_IO;
    else if ((status = ntohl(*p++)) == NFS_OK) {
	p = xdr_decode_fattr(p, fattr);
	if (!(p = xdr_decode_data(p, data, &len, count))) {
	    DPRINTF(CLUHELP_LEVEL,("nfs_proc_read: giant data size\n")); 
	    status = NFSERR_IO;
	}
	else
	    DPRINTF(CLUHELP_LEVEL,("NFS reply read %d\n", len));
    }

    overhead_rpc_free(p0);
    return (status == NFS_OK) ? len : nfs_stat_to_errno(status);
}
Exemple #9
0
int nfs_proc_lookup(struct nfs_server *server, struct nfs_fh *dir, const char *name,
		    struct nfs_fh *fhandle, struct nfs_fattr *fattr)
{
	int *p, *p0;
	int status;
	int ruid = 0;

	PRINTK("NFS call  lookup %s\n", name);
#ifdef NFS_PROC_DEBUG
	if (!strcmp(name, "xyzzy"))
		proc_debug = 1 - proc_debug;
#endif
	if (!(p0 = nfs_rpc_alloc(server->rsize)))
		return -EIO;
retry:
	p = nfs_rpc_header(p0, NFSPROC_LOOKUP, ruid);
	p = xdr_encode_fhandle(p, dir);
	p = xdr_encode_string(p, name);
	if ((status = nfs_rpc_call(server, p0, p, server->rsize)) < 0) {
		nfs_rpc_free(p0);
		return status;
	}
	if (!(p = nfs_rpc_verify(p0)))
		status = -errno_NFSERR_IO;
	else if ((status = ntohl(*p++)) == NFS_OK) {
		p = xdr_decode_fhandle(p, fhandle);
		p = xdr_decode_fattr(p, fattr);
		PRINTK("NFS reply lookup\n");
		/* status = 0; */
	}
	else {
		if (!ruid && current->fsuid == 0 && current->uid != 0) {
			ruid = 1;
			goto retry;
		}
		PRINTK("NFS reply lookup failed = %d\n", status);
		status = -nfs_stat_to_errno(status);
	}
	nfs_rpc_free(p0);
	return status;
}
Exemple #10
0
int nfs_proc_create(struct nfs_server *server, struct nfs_fh *dir,
		    const char *name, struct nfs_sattr *sattr,
		    struct nfs_fh *fhandle, struct nfs_fattr *fattr)
{
	int *p, *p0;
	int status;
	int ruid = 0;

	PRINTK("NFS call  create %s\n", name);
	if (!(p0 = nfs_rpc_alloc(server->wsize)))
		return -EIO;
retry:
	p = nfs_rpc_header(p0, NFSPROC_CREATE, ruid);
	p = xdr_encode_fhandle(p, dir);
	p = xdr_encode_string(p, name);
	p = xdr_encode_sattr(p, sattr);
	if ((status = nfs_rpc_call(server, p0, p, server->wsize)) < 0) {
		nfs_rpc_free(p0);
		return status;
	}
	if (!(p = nfs_rpc_verify(p0)))
		status = -errno_NFSERR_IO;
	else if ((status = ntohl(*p++)) == NFS_OK) {
		p = xdr_decode_fhandle(p, fhandle);
		p = xdr_decode_fattr(p, fattr);
		PRINTK("NFS reply create\n");
		/* status = 0; */
	}
	else {
		if (!ruid && current->fsuid == 0 && current->uid != 0) {
			ruid = 1;
			goto retry;
		}
		PRINTK("NFS reply create failed = %d\n", status);
		status = -nfs_stat_to_errno(status);
	}
	nfs_rpc_free(p0);
	return status;
}
Exemple #11
0
int nfs_proc_write(struct nfs_server *server, struct nfs_fh *fhandle,
		   int offset, int count, char *data, struct nfs_fattr *fattr)
{
	int *p, *p0;
	int status;
	int ruid = 0;

	PRINTK("NFS call  write %d @ %d\n", count, offset);
	if (!(p0 = nfs_rpc_alloc(server->wsize)))
		return -EIO;
retry:
	p = nfs_rpc_header(p0, NFSPROC_WRITE, ruid);
	p = xdr_encode_fhandle(p, fhandle);
	*p++ = htonl(offset); /* traditional, could be any value */
	*p++ = htonl(offset);
	*p++ = htonl(count); /* traditional, could be any value */
	p = xdr_encode_data(p, data, count);
	if ((status = nfs_rpc_call(server, p0, p, server->wsize)) < 0) {
		nfs_rpc_free(p0);
		return status;
	}
	if (!(p = nfs_rpc_verify(p0)))
		status = -errno_NFSERR_IO;
	else if ((status = ntohl(*p++)) == NFS_OK) {
		p = xdr_decode_fattr(p, fattr);
		PRINTK("NFS reply write\n");
		/* status = 0; */
	}
	else {
		if (!ruid && current->fsuid == 0 && current->uid != 0) {
			ruid = 1;
			goto retry;
		}
		PRINTK("NFS reply write failed = %d\n", status);
		status = -nfs_stat_to_errno(status);
	}
	nfs_rpc_free(p0);
	return status;
}
Exemple #12
0
/*
 * Decode READ reply
 */
static int
nfs_xdr_readres(struct rpc_rqst *req, u32 *p, struct nfs_readres *res)
{
	struct iovec *iov = req->rq_rvec;
	int	status, count, recvd, hdrlen;

	if ((status = ntohl(*p++)))
		return -nfs_stat_to_errno(status);
	p = xdr_decode_fattr(p, res->fattr);

	count = ntohl(*p++);
	hdrlen = (u8 *) p - (u8 *) iov->iov_base;
	recvd = req->rq_rlen - hdrlen;
	if (p != iov[req->rq_rnr-1].iov_base) {
		/* Unexpected reply header size. Punt.
		 * XXX: Move iovec contents to align data on page
		 * boundary and adjust RPC header size guess */
		printk(KERN_WARNING "NFS: Odd RPC header size in read reply: %d\n", hdrlen);
		return -errno_NFSERR_IO;
	}
	if (count > recvd) {
		printk(KERN_WARNING "NFS: server cheating in read reply: "
			"count %d > recvd %d\n", count, recvd);
		count = recvd;
	}

	dprintk("RPC:      readres OK count %d\n", count);
	if (count < res->count) {
		xdr_zero_iovec(iov+1, req->rq_rnr-2, res->count - count);
		res->count = count;
		res->eof = 1;  /* Silly NFSv3ism which can't be helped */
	} else
		res->eof = 0;

	return count;
}
Exemple #13
0
int 
nfs_proc_writev(struct nfs_fh *fhandle, int offset, int count, 
	       struct ae_recv *r, struct nfs_fattr *fattr) {
    
    int *p;
    int status;
    int ruid = 0;
    struct generic_server *server = fhandle->server;
    char *tmp_data;
    int i;
    int wsize;			/* to be used with new prpc */
    int remaining_count = count;
    struct p_rpc *prpc;
    struct p_rpc_rec *rw;

        
    DPRINTF(CLUHELP_LEVEL,("NFS call  write %p  %d @ %d\n", r, count, offset));
    wsize = server->wsize;
    if (!(prpc = p_overhead_rpc_alloc(wsize, count)))
	return -EIO;

    demand(count <= wsize, we only handle up to 8K for now);

    tmp_data = NULL; // data;
    for (i = 0; i < prpc->n ; i++) {
      static char overflow[4];
	rw = &prpc->rw[i];
	rw->start = nfs_rpc_header(rw->ptr, NFSPROC_WRITE, ruid);
	rw->start = xdr_encode_fhandle(rw->start, fhandle);
	*rw->start++ = htonl(offset + i*wsize);	/* offset */
	*rw->start++ = htonl(offset + i*wsize);	/* offset */
	rw->count = (remaining_count >= wsize) ? wsize : remaining_count;
	*rw->start++ = htonl(rw->count); /* count */
	*rw->start++ = htonl(rw->count); /* data len */
	rw->end = rw->start;
	rw->r.n = 1;
	rw->r = *r;

	if ((rw->count % 4) != 0) {
	  rw->r.r[r->n].data = overflow;
	  rw->r.r[r->n].sz = 4 - (rw->count % 4);
	  rw->r.n++;
	}
	pr_ae_recv(&rw->r);
	tmp_data += rw->count;
	remaining_count -= rw->count;

	rw->xid = rw->ptr[0];
	rw->done = 0;

	/* 	print_rpc2(prpc->rw[i].ptr,128); */
    }
    /*     pr_p_rpc(prpc); */
    lprintf("p_generic_rpc_call start\n");
    if ((status = p_generic_rpc_call(server,prpc)) < 0) {
	p_overhead_rpc_free(prpc);
	return status;
    }
    lprintf("p_generic_rpc_call done\n");
    DPRINTF(CLUHELP_LEVEL,("P_GENERIC_RPC_CALL: %d\n",status));

    for (i = 0; i < prpc->n ; i++) {
	rw = &prpc->rw[i];

	if (!(p = generic_rpc_verify(rw->ptr))) {
	    status = NFSERR_IO;
	    break;
	} else if ((status = ntohl(*p++)) == NFS_OK) {
	    p = xdr_decode_fattr(p, fattr);
	    DPRINTF(CLUHELP_LEVEL,("NFS reply write xid: %d, count %d\n", 
		   rw->xid,rw->count));
	}
    }
    
    DPRINTF(CLUHELP_LEVEL,("status: %d\n",status));
    
    p_overhead_rpc_free(prpc);
    return nfs_stat_to_errno(status);
}
Exemple #14
0
int 
nfs_proc_read_p(struct nfs_fh *fhandle, int offset, int count, 
	      char *data, struct nfs_fattr *fattr) {
    int *p;
    int len = 0;
    int status;
    int ruid = 0;
    struct generic_server *server = fhandle->server;
    struct p_rpc *prpc;
    struct p_rpc_rec *rw;
    int i;
    int rsize;			/* to be used with new prpc */
    int remaining_count = count;
    int total_length = 0;
    char *tmp_data;
    char *tmp_data0;
    
    DPRINTF(CLUHELP_LEVEL,("NFS call  read %d @ %d\n", count, offset));
    rsize = server->rsize;
    //rsize = 1366;
    if ((offset < NFSMAXOFFSET) && ((offset % 4096) != 0)) {
      kprintf("warning non page aligned read: %d:%d\n",offset,count);
    }
    if (!(prpc = p_overhead_rpc_alloc(rsize, count)))
	return -EIO;

    for (i = 0; i < prpc->n ; i++) {
	rw = &prpc->rw[i];
	rw->start = nfs_rpc_header(rw->ptr, NFSPROC_READ, ruid);
	rw->start = xdr_encode_fhandle(rw->start, fhandle);
	*rw->start++ = htonl(offset + i*rsize);	/* offset */
	*rw->start++ = htonl((remaining_count >= rsize) ? 
			     rsize : remaining_count); /* count */
	rw->count = (remaining_count >= rsize) ? rsize : remaining_count;
	remaining_count -= rsize;
	*rw->start++ = htonl(rsize); /* traditional, could be any value */

	rw->end = rw->start;
	rw->r.n = 0;

	rw->xid = rw->ptr[0];
	rw->done = 0;

	/* 	print_rpc2(prpc->rw[i].ptr,128); */
    }
    /*     pr_p_rpc(prpc); */

    if ((status = p_generic_rpc_call(server,prpc)) < 0) {
	p_overhead_rpc_free(prpc);
	return status;
    }
    DPRINTF(CLUHELP_LEVEL,("P_GENERIC_RPC_CALL: %d\n",status));
    tmp_data = tmp_data0 = data;
    for (i = 0; i < prpc->n ; i++) {
	rw = &prpc->rw[i];

	if (!(p = generic_rpc_verify(rw->ptr))) {
	    status = NFSERR_IO;
	    break;
	} else if ((status = ntohl(*p++)) == NFS_OK) {
	    p = xdr_decode_fattr(p, fattr);
	    if (!(p = xdr_decode_data(p, tmp_data, &len, rw->count))) {
		DPRINTF(CLUHELP_LEVEL,("nfs_proc_read: giant data size\n")); 
		status = NFSERR_IO;
		break;
	    } else {
		DPRINTF(CLUHELP_LEVEL,("NFS reply read xid: %d, length: %d count %d\n", 
			 rw->xid,len,rw->count));
		tmp_data += len;
		total_length += len;
	    }
	}
    }
    DPRINTF(CLUHELP_LEVEL,("status: %d\n",status));

    p_overhead_rpc_free(prpc);
    return (status == NFS_OK) ? total_length : nfs_stat_to_errno(status);
}