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

[PATCH] kNFSd: Giant patch importing NFSv4 server functionality

Now that all the hooks are in place, this large patch imports all
of the new code for the NFSv4 server.

This patch makes almost no changes to the existing nfsd codebase
(these have been taken care of by the preceding patches).

One aspect of the NFSv4 code deserves comment.  The most natural scheme
for processing a COMPOUND request would seem to be:
  1a. XDR decode phase, decode args of all operations
  2a. processing phase, process all operations
  3a. XDR encode phase, encode results of all operations

However, we use a scheme which works as follows:
  1b. XDR decode phase, decode args of all operations
  2b. For each operation,
        process the operation
        encode the result

To see what is wrong with the first scheme, consider a COMPOUND
of the form READ REMOVE.  Since the last bit of processing for
the READ request occurs in XDR encode, we might discover in step
3a that the READ request should return an error.  Therefore, the
REMOVE request should not be processed at all.  This is a fatal
problem, since the REMOVE was already been done in step 2a!

Another type of problem would occur in a COMPOUND of the form
READ WRITE.  Assume that both operations succeed.  Under scheme
(a), the WRITE is actually performed _before_ the READ (since
the "real" READ is really done during XDR encode).  This is
certainly incorrect if the READ and WRITE ranges overlap.

These examples might seem a little artificial, but nevertheless
it does seem that in order to process a COMPOUND correctly in
all cases, we need to use scheme (b) instead of scheme (a).

(To construct less artificial examples, just substitute GETATTR
 for READ in the examples above.  This works because the "real"
 GETATTR is done during XDR encode: one would really have to
 bend over backwards in order to arrange things otherwise.)
parent 106c646c
This diff is collapsed.
This diff is collapsed.
...@@ -338,10 +338,23 @@ static struct svc_version nfsd_version3 = { ...@@ -338,10 +338,23 @@ static struct svc_version nfsd_version3 = {
.vs_dispatch = nfsd_dispatch .vs_dispatch = nfsd_dispatch
}; };
#endif #endif
#ifdef CONFIG_NFSD_V4
static struct svc_version nfsd_version4 = {
.vs_vers = 4,
.vs_nproc = 2,
.vs_proc = nfsd_procedures4,
.vs_dispatch = nfsd_dispatch
};
#endif
static struct svc_version * nfsd_version[] = { static struct svc_version * nfsd_version[] = {
[2] = &nfsd_version2, [2] = &nfsd_version2,
#ifdef CONFIG_NFSD_V3 #if defined(CONFIG_NFSD_V3)
[3] = &nfsd_version3, [3] = &nfsd_version3,
#elif defined(CONFIG_NFSD_V4)
[3] = NULL,
#endif
#if defined(CONFIG_NFSD_V4)
[4] = &nfsd_version4,
#endif #endif
}; };
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#define NFS3_ACCESS_EXTEND 0x0008 #define NFS3_ACCESS_EXTEND 0x0008
#define NFS3_ACCESS_DELETE 0x0010 #define NFS3_ACCESS_DELETE 0x0010
#define NFS3_ACCESS_EXECUTE 0x0020 #define NFS3_ACCESS_EXECUTE 0x0020
#define NFS3_ACCESS_FULL 0x003f
/* Flags for create mode */ /* Flags for create mode */
enum nfs3_createmode { enum nfs3_createmode {
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* nfsd version * nfsd version
*/ */
#define NFSD_VERSION "0.5" #define NFSD_VERSION "0.5"
#define NFSD_SUPPORTED_MINOR_VERSION 0
#ifdef __KERNEL__ #ifdef __KERNEL__
/* /*
...@@ -69,6 +70,9 @@ extern struct svc_procedure nfsd_procedures2[]; ...@@ -69,6 +70,9 @@ extern struct svc_procedure nfsd_procedures2[];
#ifdef CONFIG_NFSD_V3 #ifdef CONFIG_NFSD_V3
extern struct svc_procedure nfsd_procedures3[]; extern struct svc_procedure nfsd_procedures3[];
#endif /* CONFIG_NFSD_V3 */ #endif /* CONFIG_NFSD_V3 */
#ifdef CONFIG_NFSD_V4
extern struct svc_procedure nfsd_procedures4[];
#endif /* CONFIG_NFSD_V4 */
extern struct svc_program nfsd_program; extern struct svc_program nfsd_program;
/* /*
...@@ -197,6 +201,73 @@ void nfsd_lockd_unexport(struct svc_client *); ...@@ -197,6 +201,73 @@ void nfsd_lockd_unexport(struct svc_client *);
*/ */
extern struct timeval nfssvc_boot; extern struct timeval nfssvc_boot;
#ifdef CONFIG_NFSD_V4
/* before processing a COMPOUND operation, we have to check that there
* is enough space in the buffer for XDR encode to succeed. otherwise,
* we might process an operation with side effects, and be unable to
* tell the client that the operation succeeded.
*
* COMPOUND_SLACK_SPACE - this is the minimum amount of buffer space
* needed to encode an "ordinary" _successful_ operation. (GETATTR,
* READ, READDIR, and READLINK have their own buffer checks.) if we
* fall below this level, we fail the next operation with NFS4ERR_RESOURCE.
*
* COMPOUND_ERR_SLACK_SPACE - this is the minimum amount of buffer space
* needed to encode an operation which has failed with NFS4ERR_RESOURCE.
* care is taken to ensure that we never fall below this level for any
* reason.
*/
#define COMPOUND_SLACK_SPACE 140 /* OP_GETFH */
#define COMPOUND_ERR_SLACK_SPACE 12 /* OP_SETATTR */
#define NFSD_LEASE_TIME 60 /* seconds */
/*
* The following attributes are currently not supported by the NFSv4 server:
* ACL (will be supported in a forthcoming patch)
* ARCHIVE (deprecated anyway)
* FS_LOCATIONS (will be supported eventually)
* HIDDEN (unlikely to be supported any time soon)
* MIMETYPE (unlikely to be supported any time soon)
* QUOTA_* (will be supported in a forthcoming patch)
* SYSTEM (unlikely to be supported any time soon)
* TIME_BACKUP (unlikely to be supported any time soon)
* TIME_CREATE (unlikely to be supported any time soon)
*/
#define NFSD_SUPPORTED_ATTRS_WORD0 \
(FATTR4_WORD0_SUPPORTED_ATTRS | FATTR4_WORD0_TYPE | FATTR4_WORD0_FH_EXPIRE_TYPE \
| FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE | FATTR4_WORD0_LINK_SUPPORT \
| FATTR4_WORD0_SYMLINK_SUPPORT | FATTR4_WORD0_NAMED_ATTR | FATTR4_WORD0_FSID \
| FATTR4_WORD0_UNIQUE_HANDLES | FATTR4_WORD0_LEASE_TIME | FATTR4_WORD0_RDATTR_ERROR \
| FATTR4_WORD0_ACLSUPPORT | FATTR4_WORD0_CANSETTIME | FATTR4_WORD0_CASE_INSENSITIVE \
| FATTR4_WORD0_CASE_PRESERVING | FATTR4_WORD0_CHOWN_RESTRICTED \
| FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FILEID | FATTR4_WORD0_FILES_AVAIL \
| FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_HOMOGENEOUS \
| FATTR4_WORD0_MAXFILESIZE | FATTR4_WORD0_MAXLINK | FATTR4_WORD0_MAXNAME \
| FATTR4_WORD0_MAXREAD | FATTR4_WORD0_MAXWRITE)
#define NFSD_SUPPORTED_ATTRS_WORD1 \
(FATTR4_WORD1_MODE | FATTR4_WORD1_NO_TRUNC | FATTR4_WORD1_NUMLINKS \
| FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP | FATTR4_WORD1_RAWDEV \
| FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | FATTR4_WORD1_SPACE_TOTAL \
| FATTR4_WORD1_SPACE_USED | FATTR4_WORD1_TIME_ACCESS | FATTR4_WORD1_TIME_ACCESS_SET \
| FATTR4_WORD1_TIME_CREATE | FATTR4_WORD1_TIME_DELTA | FATTR4_WORD1_TIME_METADATA \
| FATTR4_WORD1_TIME_MODIFY | FATTR4_WORD1_TIME_MODIFY_SET)
/* These will return ERR_INVAL if specified in GETATTR or READDIR. */
#define NFSD_WRITEONLY_ATTRS_WORD1 \
(FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET)
/* These are the only attrs allowed in CREATE/OPEN/SETATTR. */
#define NFSD_WRITEABLE_ATTRS_WORD0 FATTR4_WORD0_SIZE
#define NFSD_WRITEABLE_ATTRS_WORD1 \
(FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \
| FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_METADATA | FATTR4_WORD1_TIME_MODIFY_SET)
#endif /* CONFIG_NFSD_V4 */
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* LINUX_NFSD_NFSD_H */ #endif /* LINUX_NFSD_NFSD_H */
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