diff options
36 files changed, 2359 insertions, 1163 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 7936b801fe6a..c08813dbfce2 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt | |||
| @@ -2395,6 +2395,18 @@ and is between 256 and 4096 characters. It is defined in the file | |||
| 2395 | stifb= [HW] | 2395 | stifb= [HW] |
| 2396 | Format: bpp:<bpp1>[:<bpp2>[:<bpp3>...]] | 2396 | Format: bpp:<bpp1>[:<bpp2>[:<bpp3>...]] |
| 2397 | 2397 | ||
| 2398 | sunrpc.min_resvport= | ||
| 2399 | sunrpc.max_resvport= | ||
| 2400 | [NFS,SUNRPC] | ||
| 2401 | SunRPC servers often require that client requests | ||
| 2402 | originate from a privileged port (i.e. a port in the | ||
| 2403 | range 0 < portnr < 1024). | ||
| 2404 | An administrator who wishes to reserve some of these | ||
| 2405 | ports for other uses may adjust the range that the | ||
| 2406 | kernel's sunrpc client considers to be privileged | ||
| 2407 | using these two parameters to set the minimum and | ||
| 2408 | maximum port values. | ||
| 2409 | |||
| 2398 | sunrpc.pool_mode= | 2410 | sunrpc.pool_mode= |
| 2399 | [NFS] | 2411 | [NFS] |
| 2400 | Control how the NFS server code allocates CPUs to | 2412 | Control how the NFS server code allocates CPUs to |
| @@ -2411,6 +2423,15 @@ and is between 256 and 4096 characters. It is defined in the file | |||
| 2411 | pernode one pool for each NUMA node (equivalent | 2423 | pernode one pool for each NUMA node (equivalent |
| 2412 | to global on non-NUMA machines) | 2424 | to global on non-NUMA machines) |
| 2413 | 2425 | ||
| 2426 | sunrpc.tcp_slot_table_entries= | ||
| 2427 | sunrpc.udp_slot_table_entries= | ||
| 2428 | [NFS,SUNRPC] | ||
| 2429 | Sets the upper limit on the number of simultaneous | ||
| 2430 | RPC calls that can be sent from the client to a | ||
| 2431 | server. Increasing these values may allow you to | ||
| 2432 | improve throughput, but will also increase the | ||
| 2433 | amount of memory reserved for use by the client. | ||
| 2434 | |||
| 2414 | swiotlb= [IA-64] Number of I/O TLB slabs | 2435 | swiotlb= [IA-64] Number of I/O TLB slabs |
| 2415 | 2436 | ||
| 2416 | switches= [HW,M68k] | 2437 | switches= [HW,M68k] |
diff --git a/fs/lockd/host.c b/fs/lockd/host.c index 99d737bd4325..7cb076ac6b45 100644 --- a/fs/lockd/host.c +++ b/fs/lockd/host.c | |||
| @@ -87,18 +87,6 @@ static unsigned int nlm_hash_address(const struct sockaddr *sap) | |||
| 87 | return hash & (NLM_HOST_NRHASH - 1); | 87 | return hash & (NLM_HOST_NRHASH - 1); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | static void nlm_clear_port(struct sockaddr *sap) | ||
| 91 | { | ||
| 92 | switch (sap->sa_family) { | ||
| 93 | case AF_INET: | ||
| 94 | ((struct sockaddr_in *)sap)->sin_port = 0; | ||
| 95 | break; | ||
| 96 | case AF_INET6: | ||
| 97 | ((struct sockaddr_in6 *)sap)->sin6_port = 0; | ||
| 98 | break; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | /* | 90 | /* |
| 103 | * Common host lookup routine for server & client | 91 | * Common host lookup routine for server & client |
| 104 | */ | 92 | */ |
| @@ -177,7 +165,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni) | |||
| 177 | host->h_addrbuf = nsm->sm_addrbuf; | 165 | host->h_addrbuf = nsm->sm_addrbuf; |
| 178 | memcpy(nlm_addr(host), ni->sap, ni->salen); | 166 | memcpy(nlm_addr(host), ni->sap, ni->salen); |
| 179 | host->h_addrlen = ni->salen; | 167 | host->h_addrlen = ni->salen; |
| 180 | nlm_clear_port(nlm_addr(host)); | 168 | rpc_set_port(nlm_addr(host), 0); |
| 181 | memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len); | 169 | memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len); |
| 182 | host->h_version = ni->version; | 170 | host->h_version = ni->version; |
| 183 | host->h_proto = ni->protocol; | 171 | host->h_proto = ni->protocol; |
diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c index 7fce1b525849..30c933188dd7 100644 --- a/fs/lockd/mon.c +++ b/fs/lockd/mon.c | |||
| @@ -61,43 +61,6 @@ static inline struct sockaddr *nsm_addr(const struct nsm_handle *nsm) | |||
| 61 | return (struct sockaddr *)&nsm->sm_addr; | 61 | return (struct sockaddr *)&nsm->sm_addr; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | static void nsm_display_ipv4_address(const struct sockaddr *sap, char *buf, | ||
| 65 | const size_t len) | ||
| 66 | { | ||
| 67 | const struct sockaddr_in *sin = (struct sockaddr_in *)sap; | ||
| 68 | snprintf(buf, len, "%pI4", &sin->sin_addr.s_addr); | ||
| 69 | } | ||
| 70 | |||
| 71 | static void nsm_display_ipv6_address(const struct sockaddr *sap, char *buf, | ||
| 72 | const size_t len) | ||
| 73 | { | ||
| 74 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; | ||
| 75 | |||
| 76 | if (ipv6_addr_v4mapped(&sin6->sin6_addr)) | ||
| 77 | snprintf(buf, len, "%pI4", &sin6->sin6_addr.s6_addr32[3]); | ||
| 78 | else if (sin6->sin6_scope_id != 0) | ||
| 79 | snprintf(buf, len, "%pI6%%%u", &sin6->sin6_addr, | ||
| 80 | sin6->sin6_scope_id); | ||
| 81 | else | ||
| 82 | snprintf(buf, len, "%pI6", &sin6->sin6_addr); | ||
| 83 | } | ||
| 84 | |||
| 85 | static void nsm_display_address(const struct sockaddr *sap, | ||
| 86 | char *buf, const size_t len) | ||
| 87 | { | ||
| 88 | switch (sap->sa_family) { | ||
| 89 | case AF_INET: | ||
| 90 | nsm_display_ipv4_address(sap, buf, len); | ||
| 91 | break; | ||
| 92 | case AF_INET6: | ||
| 93 | nsm_display_ipv6_address(sap, buf, len); | ||
| 94 | break; | ||
| 95 | default: | ||
| 96 | snprintf(buf, len, "unsupported address family"); | ||
| 97 | break; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | static struct rpc_clnt *nsm_create(void) | 64 | static struct rpc_clnt *nsm_create(void) |
| 102 | { | 65 | { |
| 103 | struct sockaddr_in sin = { | 66 | struct sockaddr_in sin = { |
| @@ -307,8 +270,11 @@ static struct nsm_handle *nsm_create_handle(const struct sockaddr *sap, | |||
| 307 | memcpy(nsm_addr(new), sap, salen); | 270 | memcpy(nsm_addr(new), sap, salen); |
| 308 | new->sm_addrlen = salen; | 271 | new->sm_addrlen = salen; |
| 309 | nsm_init_private(new); | 272 | nsm_init_private(new); |
| 310 | nsm_display_address((const struct sockaddr *)&new->sm_addr, | 273 | |
| 311 | new->sm_addrbuf, sizeof(new->sm_addrbuf)); | 274 | if (rpc_ntop(nsm_addr(new), new->sm_addrbuf, |
| 275 | sizeof(new->sm_addrbuf)) == 0) | ||
| 276 | (void)snprintf(new->sm_addrbuf, sizeof(new->sm_addrbuf), | ||
| 277 | "unsupported address family"); | ||
| 312 | memcpy(new->sm_name, hostname, hostname_len); | 278 | memcpy(new->sm_name, hostname, hostname_len); |
| 313 | new->sm_name[hostname_len] = '\0'; | 279 | new->sm_name[hostname_len] = '\0'; |
| 314 | 280 | ||
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c index 7f604c7941fb..293fa0528a6e 100644 --- a/fs/nfs/callback.c +++ b/fs/nfs/callback.c | |||
| @@ -43,21 +43,29 @@ static struct svc_program nfs4_callback_program; | |||
| 43 | unsigned int nfs_callback_set_tcpport; | 43 | unsigned int nfs_callback_set_tcpport; |
| 44 | unsigned short nfs_callback_tcpport; | 44 | unsigned short nfs_callback_tcpport; |
| 45 | unsigned short nfs_callback_tcpport6; | 45 | unsigned short nfs_callback_tcpport6; |
| 46 | static const int nfs_set_port_min = 0; | 46 | #define NFS_CALLBACK_MAXPORTNR (65535U) |
| 47 | static const int nfs_set_port_max = 65535; | ||
| 48 | 47 | ||
| 49 | static int param_set_port(const char *val, struct kernel_param *kp) | 48 | static int param_set_portnr(const char *val, struct kernel_param *kp) |
| 50 | { | 49 | { |
| 51 | char *endp; | 50 | unsigned long num; |
| 52 | int num = simple_strtol(val, &endp, 0); | 51 | int ret; |
| 53 | if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max) | 52 | |
| 53 | if (!val) | ||
| 54 | return -EINVAL; | ||
| 55 | ret = strict_strtoul(val, 0, &num); | ||
| 56 | if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR) | ||
| 54 | return -EINVAL; | 57 | return -EINVAL; |
| 55 | *((int *)kp->arg) = num; | 58 | *((unsigned int *)kp->arg) = num; |
| 56 | return 0; | 59 | return 0; |
| 57 | } | 60 | } |
| 58 | 61 | ||
| 59 | module_param_call(callback_tcpport, param_set_port, param_get_int, | 62 | static int param_get_portnr(char *buffer, struct kernel_param *kp) |
| 60 | &nfs_callback_set_tcpport, 0644); | 63 | { |
| 64 | return param_get_uint(buffer, kp); | ||
| 65 | } | ||
| 66 | #define param_check_portnr(name, p) __param_check(name, p, unsigned int); | ||
| 67 | |||
| 68 | module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644); | ||
| 61 | 69 | ||
| 62 | /* | 70 | /* |
| 63 | * This is the NFSv4 callback kernel thread. | 71 | * This is the NFSv4 callback kernel thread. |
diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 8d25ccb2d51d..d36925f9b952 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c | |||
| @@ -809,6 +809,9 @@ static int nfs_init_server(struct nfs_server *server, | |||
| 809 | /* Initialise the client representation from the mount data */ | 809 | /* Initialise the client representation from the mount data */ |
| 810 | server->flags = data->flags; | 810 | server->flags = data->flags; |
| 811 | server->options = data->options; | 811 | server->options = data->options; |
| 812 | server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID| | ||
| 813 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP| | ||
| 814 | NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME; | ||
| 812 | 815 | ||
| 813 | if (data->rsize) | 816 | if (data->rsize) |
| 814 | server->rsize = nfs_block_size(data->rsize, NULL); | 817 | server->rsize = nfs_block_size(data->rsize, NULL); |
| @@ -1074,10 +1077,6 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data, | |||
| 1074 | (unsigned long long) server->fsid.major, | 1077 | (unsigned long long) server->fsid.major, |
| 1075 | (unsigned long long) server->fsid.minor); | 1078 | (unsigned long long) server->fsid.minor); |
| 1076 | 1079 | ||
| 1077 | BUG_ON(!server->nfs_client); | ||
| 1078 | BUG_ON(!server->nfs_client->rpc_ops); | ||
| 1079 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); | ||
| 1080 | |||
| 1081 | spin_lock(&nfs_client_lock); | 1080 | spin_lock(&nfs_client_lock); |
| 1082 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); | 1081 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); |
| 1083 | list_add_tail(&server->master_link, &nfs_volume_list); | 1082 | list_add_tail(&server->master_link, &nfs_volume_list); |
| @@ -1274,7 +1273,7 @@ static int nfs4_init_server(struct nfs_server *server, | |||
| 1274 | 1273 | ||
| 1275 | /* Initialise the client representation from the mount data */ | 1274 | /* Initialise the client representation from the mount data */ |
| 1276 | server->flags = data->flags; | 1275 | server->flags = data->flags; |
| 1277 | server->caps |= NFS_CAP_ATOMIC_OPEN; | 1276 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR; |
| 1278 | server->options = data->options; | 1277 | server->options = data->options; |
| 1279 | 1278 | ||
| 1280 | /* Get a client record */ | 1279 | /* Get a client record */ |
| @@ -1359,10 +1358,6 @@ struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data, | |||
| 1359 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) | 1358 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
| 1360 | server->namelen = NFS4_MAXNAMLEN; | 1359 | server->namelen = NFS4_MAXNAMLEN; |
| 1361 | 1360 | ||
| 1362 | BUG_ON(!server->nfs_client); | ||
| 1363 | BUG_ON(!server->nfs_client->rpc_ops); | ||
| 1364 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); | ||
| 1365 | |||
| 1366 | spin_lock(&nfs_client_lock); | 1361 | spin_lock(&nfs_client_lock); |
| 1367 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); | 1362 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); |
| 1368 | list_add_tail(&server->master_link, &nfs_volume_list); | 1363 | list_add_tail(&server->master_link, &nfs_volume_list); |
| @@ -1400,7 +1395,7 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data, | |||
| 1400 | 1395 | ||
| 1401 | /* Initialise the client representation from the parent server */ | 1396 | /* Initialise the client representation from the parent server */ |
| 1402 | nfs_server_copy_userdata(server, parent_server); | 1397 | nfs_server_copy_userdata(server, parent_server); |
| 1403 | server->caps |= NFS_CAP_ATOMIC_OPEN; | 1398 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR; |
| 1404 | 1399 | ||
| 1405 | /* Get a client representation. | 1400 | /* Get a client representation. |
| 1406 | * Note: NFSv4 always uses TCP, */ | 1401 | * Note: NFSv4 always uses TCP, */ |
diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 05062329b678..5021b75d2d1e 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c | |||
| @@ -328,6 +328,42 @@ nfs_file_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | /* | 330 | /* |
| 331 | * Decide whether a read/modify/write cycle may be more efficient | ||
| 332 | * then a modify/write/read cycle when writing to a page in the | ||
| 333 | * page cache. | ||
| 334 | * | ||
| 335 | * The modify/write/read cycle may occur if a page is read before | ||
| 336 | * being completely filled by the writer. In this situation, the | ||
| 337 | * page must be completely written to stable storage on the server | ||
| 338 | * before it can be refilled by reading in the page from the server. | ||
| 339 | * This can lead to expensive, small, FILE_SYNC mode writes being | ||
| 340 | * done. | ||
| 341 | * | ||
| 342 | * It may be more efficient to read the page first if the file is | ||
| 343 | * open for reading in addition to writing, the page is not marked | ||
| 344 | * as Uptodate, it is not dirty or waiting to be committed, | ||
| 345 | * indicating that it was previously allocated and then modified, | ||
| 346 | * that there were valid bytes of data in that range of the file, | ||
| 347 | * and that the new data won't completely replace the old data in | ||
| 348 | * that range of the file. | ||
| 349 | */ | ||
| 350 | static int nfs_want_read_modify_write(struct file *file, struct page *page, | ||
| 351 | loff_t pos, unsigned len) | ||
| 352 | { | ||
| 353 | unsigned int pglen = nfs_page_length(page); | ||
| 354 | unsigned int offset = pos & (PAGE_CACHE_SIZE - 1); | ||
| 355 | unsigned int end = offset + len; | ||
| 356 | |||
| 357 | if ((file->f_mode & FMODE_READ) && /* open for read? */ | ||
| 358 | !PageUptodate(page) && /* Uptodate? */ | ||
| 359 | !PagePrivate(page) && /* i/o request already? */ | ||
| 360 | pglen && /* valid bytes of file? */ | ||
| 361 | (end < pglen || offset)) /* replace all valid bytes? */ | ||
| 362 | return 1; | ||
| 363 | return 0; | ||
| 364 | } | ||
| 365 | |||
| 366 | /* | ||
| 331 | * This does the "real" work of the write. We must allocate and lock the | 367 | * This does the "real" work of the write. We must allocate and lock the |
| 332 | * page to be sent back to the generic routine, which then copies the | 368 | * page to be sent back to the generic routine, which then copies the |
| 333 | * data from user space. | 369 | * data from user space. |
| @@ -340,15 +376,16 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping, | |||
| 340 | struct page **pagep, void **fsdata) | 376 | struct page **pagep, void **fsdata) |
| 341 | { | 377 | { |
| 342 | int ret; | 378 | int ret; |
| 343 | pgoff_t index; | 379 | pgoff_t index = pos >> PAGE_CACHE_SHIFT; |
| 344 | struct page *page; | 380 | struct page *page; |
| 345 | index = pos >> PAGE_CACHE_SHIFT; | 381 | int once_thru = 0; |
| 346 | 382 | ||
| 347 | dfprintk(PAGECACHE, "NFS: write_begin(%s/%s(%ld), %u@%lld)\n", | 383 | dfprintk(PAGECACHE, "NFS: write_begin(%s/%s(%ld), %u@%lld)\n", |
| 348 | file->f_path.dentry->d_parent->d_name.name, | 384 | file->f_path.dentry->d_parent->d_name.name, |
| 349 | file->f_path.dentry->d_name.name, | 385 | file->f_path.dentry->d_name.name, |
| 350 | mapping->host->i_ino, len, (long long) pos); | 386 | mapping->host->i_ino, len, (long long) pos); |
| 351 | 387 | ||
| 388 | start: | ||
| 352 | /* | 389 | /* |
| 353 | * Prevent starvation issues if someone is doing a consistency | 390 | * Prevent starvation issues if someone is doing a consistency |
| 354 | * sync-to-disk | 391 | * sync-to-disk |
| @@ -367,6 +404,13 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping, | |||
| 367 | if (ret) { | 404 | if (ret) { |
| 368 | unlock_page(page); | 405 | unlock_page(page); |
| 369 | page_cache_release(page); | 406 | page_cache_release(page); |
| 407 | } else if (!once_thru && | ||
| 408 | nfs_want_read_modify_write(file, page, pos, len)) { | ||
| 409 | once_thru = 1; | ||
| 410 | ret = nfs_readpage(file, page); | ||
| 411 | page_cache_release(page); | ||
| 412 | if (!ret) | ||
| 413 | goto start; | ||
| 370 | } | 414 | } |
| 371 | return ret; | 415 | return ret; |
| 372 | } | 416 | } |
| @@ -479,6 +523,7 @@ const struct address_space_operations nfs_file_aops = { | |||
| 479 | .invalidatepage = nfs_invalidate_page, | 523 | .invalidatepage = nfs_invalidate_page, |
| 480 | .releasepage = nfs_release_page, | 524 | .releasepage = nfs_release_page, |
| 481 | .direct_IO = nfs_direct_IO, | 525 | .direct_IO = nfs_direct_IO, |
| 526 | .migratepage = nfs_migrate_page, | ||
| 482 | .launder_page = nfs_launder_page, | 527 | .launder_page = nfs_launder_page, |
| 483 | }; | 528 | }; |
| 484 | 529 | ||
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c index 86147b0ab2cf..21a84d45916f 100644 --- a/fs/nfs/idmap.c +++ b/fs/nfs/idmap.c | |||
| @@ -101,7 +101,7 @@ static void idmap_pipe_destroy_msg(struct rpc_pipe_msg *); | |||
| 101 | 101 | ||
| 102 | static unsigned int fnvhash32(const void *, size_t); | 102 | static unsigned int fnvhash32(const void *, size_t); |
| 103 | 103 | ||
| 104 | static struct rpc_pipe_ops idmap_upcall_ops = { | 104 | static const struct rpc_pipe_ops idmap_upcall_ops = { |
| 105 | .upcall = idmap_pipe_upcall, | 105 | .upcall = idmap_pipe_upcall, |
| 106 | .downcall = idmap_pipe_downcall, | 106 | .downcall = idmap_pipe_downcall, |
| 107 | .destroy_msg = idmap_pipe_destroy_msg, | 107 | .destroy_msg = idmap_pipe_destroy_msg, |
| @@ -119,8 +119,8 @@ nfs_idmap_new(struct nfs_client *clp) | |||
| 119 | if (idmap == NULL) | 119 | if (idmap == NULL) |
| 120 | return -ENOMEM; | 120 | return -ENOMEM; |
| 121 | 121 | ||
| 122 | idmap->idmap_dentry = rpc_mkpipe(clp->cl_rpcclient->cl_dentry, "idmap", | 122 | idmap->idmap_dentry = rpc_mkpipe(clp->cl_rpcclient->cl_path.dentry, |
| 123 | idmap, &idmap_upcall_ops, 0); | 123 | "idmap", idmap, &idmap_upcall_ops, 0); |
| 124 | if (IS_ERR(idmap->idmap_dentry)) { | 124 | if (IS_ERR(idmap->idmap_dentry)) { |
| 125 | error = PTR_ERR(idmap->idmap_dentry); | 125 | error = PTR_ERR(idmap->idmap_dentry); |
| 126 | kfree(idmap); | 126 | kfree(idmap); |
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index bd7938eda6a8..fe5a8b45d867 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
| @@ -286,6 +286,11 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) | |||
| 286 | /* We can't support update_atime(), since the server will reset it */ | 286 | /* We can't support update_atime(), since the server will reset it */ |
| 287 | inode->i_flags |= S_NOATIME|S_NOCMTIME; | 287 | inode->i_flags |= S_NOATIME|S_NOCMTIME; |
| 288 | inode->i_mode = fattr->mode; | 288 | inode->i_mode = fattr->mode; |
| 289 | if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0 | ||
| 290 | && nfs_server_capable(inode, NFS_CAP_MODE)) | ||
| 291 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
| 292 | | NFS_INO_INVALID_ACCESS | ||
| 293 | | NFS_INO_INVALID_ACL; | ||
| 289 | /* Why so? Because we want revalidate for devices/FIFOs, and | 294 | /* Why so? Because we want revalidate for devices/FIFOs, and |
| 290 | * that's precisely what we have in nfs_file_inode_operations. | 295 | * that's precisely what we have in nfs_file_inode_operations. |
| 291 | */ | 296 | */ |
| @@ -330,20 +335,46 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) | |||
| 330 | nfsi->attr_gencount = fattr->gencount; | 335 | nfsi->attr_gencount = fattr->gencount; |
| 331 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) | 336 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) |
| 332 | inode->i_atime = fattr->atime; | 337 | inode->i_atime = fattr->atime; |
| 338 | else if (nfs_server_capable(inode, NFS_CAP_ATIME)) | ||
| 339 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | ||
| 333 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) | 340 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) |
| 334 | inode->i_mtime = fattr->mtime; | 341 | inode->i_mtime = fattr->mtime; |
| 342 | else if (nfs_server_capable(inode, NFS_CAP_MTIME)) | ||
| 343 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
| 344 | | NFS_INO_INVALID_DATA; | ||
| 335 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) | 345 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) |
| 336 | inode->i_ctime = fattr->ctime; | 346 | inode->i_ctime = fattr->ctime; |
| 347 | else if (nfs_server_capable(inode, NFS_CAP_CTIME)) | ||
| 348 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
| 349 | | NFS_INO_INVALID_ACCESS | ||
| 350 | | NFS_INO_INVALID_ACL; | ||
| 337 | if (fattr->valid & NFS_ATTR_FATTR_CHANGE) | 351 | if (fattr->valid & NFS_ATTR_FATTR_CHANGE) |
| 338 | nfsi->change_attr = fattr->change_attr; | 352 | nfsi->change_attr = fattr->change_attr; |
| 353 | else if (nfs_server_capable(inode, NFS_CAP_CHANGE_ATTR)) | ||
| 354 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
| 355 | | NFS_INO_INVALID_DATA; | ||
| 339 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) | 356 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) |
| 340 | inode->i_size = nfs_size_to_loff_t(fattr->size); | 357 | inode->i_size = nfs_size_to_loff_t(fattr->size); |
| 358 | else | ||
| 359 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
| 360 | | NFS_INO_INVALID_DATA | ||
| 361 | | NFS_INO_REVAL_PAGECACHE; | ||
| 341 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) | 362 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) |
| 342 | inode->i_nlink = fattr->nlink; | 363 | inode->i_nlink = fattr->nlink; |
| 364 | else if (nfs_server_capable(inode, NFS_CAP_NLINK)) | ||
| 365 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | ||
| 343 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) | 366 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) |
| 344 | inode->i_uid = fattr->uid; | 367 | inode->i_uid = fattr->uid; |
| 368 | else if (nfs_server_capable(inode, NFS_CAP_OWNER)) | ||
| 369 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
| 370 | | NFS_INO_INVALID_ACCESS | ||
| 371 | | NFS_INO_INVALID_ACL; | ||
| 345 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) | 372 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) |
| 346 | inode->i_gid = fattr->gid; | 373 | inode->i_gid = fattr->gid; |
| 374 | else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP)) | ||
| 375 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
| 376 | | NFS_INO_INVALID_ACCESS | ||
| 377 | | NFS_INO_INVALID_ACL; | ||
| 347 | if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) | 378 | if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) |
| 348 | inode->i_blocks = fattr->du.nfs2.blocks; | 379 | inode->i_blocks = fattr->du.nfs2.blocks; |
| 349 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { | 380 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { |
| @@ -1145,6 +1176,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
| 1145 | loff_t cur_isize, new_isize; | 1176 | loff_t cur_isize, new_isize; |
| 1146 | unsigned long invalid = 0; | 1177 | unsigned long invalid = 0; |
| 1147 | unsigned long now = jiffies; | 1178 | unsigned long now = jiffies; |
| 1179 | unsigned long save_cache_validity; | ||
| 1148 | 1180 | ||
| 1149 | dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n", | 1181 | dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n", |
| 1150 | __func__, inode->i_sb->s_id, inode->i_ino, | 1182 | __func__, inode->i_sb->s_id, inode->i_ino, |
| @@ -1171,10 +1203,11 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
| 1171 | */ | 1203 | */ |
| 1172 | nfsi->read_cache_jiffies = fattr->time_start; | 1204 | nfsi->read_cache_jiffies = fattr->time_start; |
| 1173 | 1205 | ||
| 1174 | if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) || (fattr->valid & (NFS_ATTR_FATTR_MTIME|NFS_ATTR_FATTR_CTIME))) | 1206 | save_cache_validity = nfsi->cache_validity; |
| 1175 | nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR | 1207 | nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR |
| 1176 | | NFS_INO_INVALID_ATIME | 1208 | | NFS_INO_INVALID_ATIME |
| 1177 | | NFS_INO_REVAL_PAGECACHE); | 1209 | | NFS_INO_REVAL_FORCED |
| 1210 | | NFS_INO_REVAL_PAGECACHE); | ||
| 1178 | 1211 | ||
| 1179 | /* Do atomic weak cache consistency updates */ | 1212 | /* Do atomic weak cache consistency updates */ |
| 1180 | nfs_wcc_update_inode(inode, fattr); | 1213 | nfs_wcc_update_inode(inode, fattr); |
| @@ -1189,7 +1222,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
| 1189 | nfs_force_lookup_revalidate(inode); | 1222 | nfs_force_lookup_revalidate(inode); |
| 1190 | nfsi->change_attr = fattr->change_attr; | 1223 | nfsi->change_attr = fattr->change_attr; |
| 1191 | } | 1224 | } |
| 1192 | } | 1225 | } else if (server->caps & NFS_CAP_CHANGE_ATTR) |
| 1226 | invalid |= save_cache_validity; | ||
| 1193 | 1227 | ||
| 1194 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) { | 1228 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) { |
| 1195 | /* NFSv2/v3: Check if the mtime agrees */ | 1229 | /* NFSv2/v3: Check if the mtime agrees */ |
| @@ -1201,7 +1235,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
| 1201 | nfs_force_lookup_revalidate(inode); | 1235 | nfs_force_lookup_revalidate(inode); |
| 1202 | memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); | 1236 | memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); |
| 1203 | } | 1237 | } |
| 1204 | } | 1238 | } else if (server->caps & NFS_CAP_MTIME) |
| 1239 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
| 1240 | | NFS_INO_INVALID_DATA | ||
| 1241 | | NFS_INO_REVAL_PAGECACHE | ||
| 1242 | | NFS_INO_REVAL_FORCED); | ||
| 1243 | |||
| 1205 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) { | 1244 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) { |
| 1206 | /* If ctime has changed we should definitely clear access+acl caches */ | 1245 | /* If ctime has changed we should definitely clear access+acl caches */ |
| 1207 | if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) { | 1246 | if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) { |
| @@ -1215,7 +1254,11 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
| 1215 | } | 1254 | } |
| 1216 | memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime)); | 1255 | memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime)); |
| 1217 | } | 1256 | } |
| 1218 | } | 1257 | } else if (server->caps & NFS_CAP_CTIME) |
| 1258 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
| 1259 | | NFS_INO_INVALID_ACCESS | ||
| 1260 | | NFS_INO_INVALID_ACL | ||
| 1261 | | NFS_INO_REVAL_FORCED); | ||
| 1219 | 1262 | ||
| 1220 | /* Check if our cached file size is stale */ | 1263 | /* Check if our cached file size is stale */ |
| 1221 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) { | 1264 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) { |
| @@ -1231,30 +1274,50 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
| 1231 | dprintk("NFS: isize change on server for file %s/%ld\n", | 1274 | dprintk("NFS: isize change on server for file %s/%ld\n", |
| 1232 | inode->i_sb->s_id, inode->i_ino); | 1275 | inode->i_sb->s_id, inode->i_ino); |
| 1233 | } | 1276 | } |
| 1234 | } | 1277 | } else |
| 1278 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
| 1279 | | NFS_INO_REVAL_PAGECACHE | ||
| 1280 | | NFS_INO_REVAL_FORCED); | ||
| 1235 | 1281 | ||
| 1236 | 1282 | ||
| 1237 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) | 1283 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) |
| 1238 | memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime)); | 1284 | memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime)); |
| 1285 | else if (server->caps & NFS_CAP_ATIME) | ||
| 1286 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATIME | ||
| 1287 | | NFS_INO_REVAL_FORCED); | ||
| 1239 | 1288 | ||
| 1240 | if (fattr->valid & NFS_ATTR_FATTR_MODE) { | 1289 | if (fattr->valid & NFS_ATTR_FATTR_MODE) { |
| 1241 | if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) { | 1290 | if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) { |
| 1242 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; | 1291 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; |
| 1243 | inode->i_mode = fattr->mode; | 1292 | inode->i_mode = fattr->mode; |
| 1244 | } | 1293 | } |
| 1245 | } | 1294 | } else if (server->caps & NFS_CAP_MODE) |
| 1295 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
| 1296 | | NFS_INO_INVALID_ACCESS | ||
| 1297 | | NFS_INO_INVALID_ACL | ||
| 1298 | | NFS_INO_REVAL_FORCED); | ||
| 1299 | |||
| 1246 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) { | 1300 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) { |
| 1247 | if (inode->i_uid != fattr->uid) { | 1301 | if (inode->i_uid != fattr->uid) { |
| 1248 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; | 1302 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; |
| 1249 | inode->i_uid = fattr->uid; | 1303 | inode->i_uid = fattr->uid; |
| 1250 | } | 1304 | } |
| 1251 | } | 1305 | } else if (server->caps & NFS_CAP_OWNER) |
| 1306 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
| 1307 | | NFS_INO_INVALID_ACCESS | ||
| 1308 | | NFS_INO_INVALID_ACL | ||
| 1309 | | NFS_INO_REVAL_FORCED); | ||
| 1310 | |||
| 1252 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) { | 1311 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) { |
| 1253 | if (inode->i_gid != fattr->gid) { | 1312 | if (inode->i_gid != fattr->gid) { |
| 1254 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; | 1313 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; |
| 1255 | inode->i_gid = fattr->gid; | 1314 | inode->i_gid = fattr->gid; |
| 1256 | } | 1315 | } |
| 1257 | } | 1316 | } else if (server->caps & NFS_CAP_OWNER_GROUP) |
| 1317 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
| 1318 | | NFS_INO_INVALID_ACCESS | ||
| 1319 | | NFS_INO_INVALID_ACL | ||
| 1320 | | NFS_INO_REVAL_FORCED); | ||
| 1258 | 1321 | ||
| 1259 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) { | 1322 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) { |
| 1260 | if (inode->i_nlink != fattr->nlink) { | 1323 | if (inode->i_nlink != fattr->nlink) { |
| @@ -1263,7 +1326,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
| 1263 | invalid |= NFS_INO_INVALID_DATA; | 1326 | invalid |= NFS_INO_INVALID_DATA; |
| 1264 | inode->i_nlink = fattr->nlink; | 1327 | inode->i_nlink = fattr->nlink; |
| 1265 | } | 1328 | } |
| 1266 | } | 1329 | } else if (server->caps & NFS_CAP_NLINK) |
| 1330 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
| 1331 | | NFS_INO_REVAL_FORCED); | ||
| 1267 | 1332 | ||
| 1268 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { | 1333 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { |
| 1269 | /* | 1334 | /* |
| @@ -1293,9 +1358,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
| 1293 | || S_ISLNK(inode->i_mode))) | 1358 | || S_ISLNK(inode->i_mode))) |
| 1294 | invalid &= ~NFS_INO_INVALID_DATA; | 1359 | invalid &= ~NFS_INO_INVALID_DATA; |
| 1295 | if (!nfs_have_delegation(inode, FMODE_READ) || | 1360 | if (!nfs_have_delegation(inode, FMODE_READ) || |
| 1296 | (nfsi->cache_validity & NFS_INO_REVAL_FORCED)) | 1361 | (save_cache_validity & NFS_INO_REVAL_FORCED)) |
| 1297 | nfsi->cache_validity |= invalid; | 1362 | nfsi->cache_validity |= invalid; |
| 1298 | nfsi->cache_validity &= ~NFS_INO_REVAL_FORCED; | ||
| 1299 | 1363 | ||
| 1300 | return 0; | 1364 | return 0; |
| 1301 | out_changed: | 1365 | out_changed: |
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 7dd90a6769d0..2e485677019c 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h | |||
| @@ -102,6 +102,7 @@ struct nfs_mount_request { | |||
| 102 | }; | 102 | }; |
| 103 | 103 | ||
| 104 | extern int nfs_mount(struct nfs_mount_request *info); | 104 | extern int nfs_mount(struct nfs_mount_request *info); |
| 105 | extern void nfs_umount(const struct nfs_mount_request *info); | ||
| 105 | 106 | ||
| 106 | /* client.c */ | 107 | /* client.c */ |
| 107 | extern struct rpc_program nfs_program; | 108 | extern struct rpc_program nfs_program; |
| @@ -213,7 +214,6 @@ void nfs_zap_acl_cache(struct inode *inode); | |||
| 213 | extern int nfs_wait_bit_killable(void *word); | 214 | extern int nfs_wait_bit_killable(void *word); |
| 214 | 215 | ||
| 215 | /* super.c */ | 216 | /* super.c */ |
| 216 | void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *); | ||
| 217 | extern struct file_system_type nfs_xdev_fs_type; | 217 | extern struct file_system_type nfs_xdev_fs_type; |
| 218 | #ifdef CONFIG_NFS_V4 | 218 | #ifdef CONFIG_NFS_V4 |
| 219 | extern struct file_system_type nfs4_xdev_fs_type; | 219 | extern struct file_system_type nfs4_xdev_fs_type; |
| @@ -248,6 +248,12 @@ extern void nfs_read_prepare(struct rpc_task *task, void *calldata); | |||
| 248 | 248 | ||
| 249 | /* write.c */ | 249 | /* write.c */ |
| 250 | extern void nfs_write_prepare(struct rpc_task *task, void *calldata); | 250 | extern void nfs_write_prepare(struct rpc_task *task, void *calldata); |
| 251 | #ifdef CONFIG_MIGRATION | ||
| 252 | extern int nfs_migrate_page(struct address_space *, | ||
| 253 | struct page *, struct page *); | ||
| 254 | #else | ||
| 255 | #define nfs_migrate_page NULL | ||
| 256 | #endif | ||
| 251 | 257 | ||
| 252 | /* nfs4proc.c */ | 258 | /* nfs4proc.c */ |
| 253 | extern int _nfs4_call_sync(struct nfs_server *server, | 259 | extern int _nfs4_call_sync(struct nfs_server *server, |
| @@ -368,24 +374,3 @@ unsigned int nfs_page_array_len(unsigned int base, size_t len) | |||
| 368 | return ((unsigned long)len + (unsigned long)base + | 374 | return ((unsigned long)len + (unsigned long)base + |
| 369 | PAGE_SIZE - 1) >> PAGE_SHIFT; | 375 | PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 370 | } | 376 | } |
| 371 | |||
| 372 | #define IPV6_SCOPE_DELIMITER '%' | ||
| 373 | |||
| 374 | /* | ||
| 375 | * Set the port number in an address. Be agnostic about the address | ||
| 376 | * family. | ||
| 377 | */ | ||
| 378 | static inline void nfs_set_port(struct sockaddr *sap, unsigned short port) | ||
| 379 | { | ||
| 380 | struct sockaddr_in *ap = (struct sockaddr_in *)sap; | ||
| 381 | struct sockaddr_in6 *ap6 = (struct sockaddr_in6 *)sap; | ||
| 382 | |||
| 383 | switch (sap->sa_family) { | ||
| 384 | case AF_INET: | ||
| 385 | ap->sin_port = htons(port); | ||
| 386 | break; | ||
| 387 | case AF_INET6: | ||
| 388 | ap6->sin6_port = htons(port); | ||
| 389 | break; | ||
| 390 | } | ||
| 391 | } | ||
diff --git a/fs/nfs/mount_clnt.c b/fs/nfs/mount_clnt.c index 38ef9eaec407..0adefc40cc89 100644 --- a/fs/nfs/mount_clnt.c +++ b/fs/nfs/mount_clnt.c | |||
| @@ -209,6 +209,71 @@ out_mnt_err: | |||
| 209 | goto out; | 209 | goto out; |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | /** | ||
| 213 | * nfs_umount - Notify a server that we have unmounted this export | ||
| 214 | * @info: pointer to umount request arguments | ||
| 215 | * | ||
| 216 | * MOUNTPROC_UMNT is advisory, so we set a short timeout, and always | ||
| 217 | * use UDP. | ||
| 218 | */ | ||
| 219 | void nfs_umount(const struct nfs_mount_request *info) | ||
| 220 | { | ||
| 221 | static const struct rpc_timeout nfs_umnt_timeout = { | ||
| 222 | .to_initval = 1 * HZ, | ||
| 223 | .to_maxval = 3 * HZ, | ||
| 224 | .to_retries = 2, | ||
| 225 | }; | ||
| 226 | struct rpc_create_args args = { | ||
| 227 | .protocol = IPPROTO_UDP, | ||
| 228 | .address = info->sap, | ||
| 229 | .addrsize = info->salen, | ||
| 230 | .timeout = &nfs_umnt_timeout, | ||
| 231 | .servername = info->hostname, | ||
| 232 | .program = &mnt_program, | ||
| 233 | .version = info->version, | ||
| 234 | .authflavor = RPC_AUTH_UNIX, | ||
| 235 | .flags = RPC_CLNT_CREATE_NOPING, | ||
| 236 | }; | ||
| 237 | struct mountres result; | ||
| 238 | struct rpc_message msg = { | ||
| 239 | .rpc_argp = info->dirpath, | ||
| 240 | .rpc_resp = &result, | ||
| 241 | }; | ||
| 242 | struct rpc_clnt *clnt; | ||
| 243 | int status; | ||
| 244 | |||
| 245 | if (info->noresvport) | ||
| 246 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; | ||
| 247 | |||
| 248 | clnt = rpc_create(&args); | ||
| 249 | if (unlikely(IS_ERR(clnt))) | ||
| 250 | goto out_clnt_err; | ||
| 251 | |||
| 252 | dprintk("NFS: sending UMNT request for %s:%s\n", | ||
| 253 | (info->hostname ? info->hostname : "server"), info->dirpath); | ||
| 254 | |||
| 255 | if (info->version == NFS_MNT3_VERSION) | ||
| 256 | msg.rpc_proc = &clnt->cl_procinfo[MOUNTPROC3_UMNT]; | ||
| 257 | else | ||
| 258 | msg.rpc_proc = &clnt->cl_procinfo[MOUNTPROC_UMNT]; | ||
| 259 | |||
| 260 | status = rpc_call_sync(clnt, &msg, 0); | ||
| 261 | rpc_shutdown_client(clnt); | ||
| 262 | |||
| 263 | if (unlikely(status < 0)) | ||
| 264 | goto out_call_err; | ||
| 265 | |||
| 266 | return; | ||
| 267 | |||
| 268 | out_clnt_err: | ||
| 269 | dprintk("NFS: failed to create UMNT RPC client, status=%ld\n", | ||
| 270 | PTR_ERR(clnt)); | ||
| 271 | return; | ||
| 272 | |||
| 273 | out_call_err: | ||
| 274 | dprintk("NFS: UMNT request failed, status=%d\n", status); | ||
| 275 | } | ||
| 276 | |||
| 212 | /* | 277 | /* |
| 213 | * XDR encode/decode functions for MOUNT | 278 | * XDR encode/decode functions for MOUNT |
| 214 | */ | 279 | */ |
| @@ -258,7 +323,7 @@ static int decode_status(struct xdr_stream *xdr, struct mountres *res) | |||
| 258 | return -EIO; | 323 | return -EIO; |
| 259 | status = ntohl(*p); | 324 | status = ntohl(*p); |
| 260 | 325 | ||
| 261 | for (i = 0; i <= ARRAY_SIZE(mnt_errtbl); i++) { | 326 | for (i = 0; i < ARRAY_SIZE(mnt_errtbl); i++) { |
| 262 | if (mnt_errtbl[i].status == status) { | 327 | if (mnt_errtbl[i].status == status) { |
| 263 | res->errno = mnt_errtbl[i].errno; | 328 | res->errno = mnt_errtbl[i].errno; |
| 264 | return 0; | 329 | return 0; |
| @@ -309,7 +374,7 @@ static int decode_fhs_status(struct xdr_stream *xdr, struct mountres *res) | |||
| 309 | return -EIO; | 374 | return -EIO; |
| 310 | status = ntohl(*p); | 375 | status = ntohl(*p); |
| 311 | 376 | ||
| 312 | for (i = 0; i <= ARRAY_SIZE(mnt3_errtbl); i++) { | 377 | for (i = 0; i < ARRAY_SIZE(mnt3_errtbl); i++) { |
| 313 | if (mnt3_errtbl[i].status == status) { | 378 | if (mnt3_errtbl[i].status == status) { |
| 314 | res->errno = mnt3_errtbl[i].errno; | 379 | res->errno = mnt3_errtbl[i].errno; |
| 315 | return 0; | 380 | return 0; |
| @@ -407,6 +472,13 @@ static struct rpc_procinfo mnt_procedures[] = { | |||
| 407 | .p_statidx = MOUNTPROC_MNT, | 472 | .p_statidx = MOUNTPROC_MNT, |
| 408 | .p_name = "MOUNT", | 473 | .p_name = "MOUNT", |
| 409 | }, | 474 | }, |
| 475 | [MOUNTPROC_UMNT] = { | ||
| 476 | .p_proc = MOUNTPROC_UMNT, | ||
| 477 | .p_encode = (kxdrproc_t)mnt_enc_dirpath, | ||
| 478 | .p_arglen = MNT_enc_dirpath_sz, | ||
| 479 | .p_statidx = MOUNTPROC_UMNT, | ||
| 480 | .p_name = "UMOUNT", | ||
| 481 | }, | ||
| 410 | }; | 482 | }; |
| 411 | 483 | ||
| 412 | static struct rpc_procinfo mnt3_procedures[] = { | 484 | static struct rpc_procinfo mnt3_procedures[] = { |
| @@ -419,6 +491,13 @@ static struct rpc_procinfo mnt3_procedures[] = { | |||
| 419 | .p_statidx = MOUNTPROC3_MNT, | 491 | .p_statidx = MOUNTPROC3_MNT, |
| 420 | .p_name = "MOUNT", | 492 | .p_name = "MOUNT", |
| 421 | }, | 493 | }, |
| 494 | [MOUNTPROC3_UMNT] = { | ||
| 495 | .p_proc = MOUNTPROC3_UMNT, | ||
| 496 | .p_encode = (kxdrproc_t)mnt_enc_dirpath, | ||
| 497 | .p_arglen = MNT_enc_dirpath_sz, | ||
| 498 | .p_statidx = MOUNTPROC3_UMNT, | ||
| 499 | .p_name = "UMOUNT", | ||
| 500 | }, | ||
| 422 | }; | 501 | }; |
| 423 | 502 | ||
| 424 | 503 | ||
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c index 2a2a0a7143ad..ef22ee89aa77 100644 --- a/fs/nfs/nfs4namespace.c +++ b/fs/nfs/nfs4namespace.c | |||
| @@ -121,11 +121,11 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, | |||
| 121 | 121 | ||
| 122 | if (memchr(buf->data, IPV6_SCOPE_DELIMITER, buf->len)) | 122 | if (memchr(buf->data, IPV6_SCOPE_DELIMITER, buf->len)) |
| 123 | continue; | 123 | continue; |
| 124 | nfs_parse_ip_address(buf->data, buf->len, | 124 | mountdata->addrlen = rpc_pton(buf->data, buf->len, |
| 125 | mountdata->addr, &mountdata->addrlen); | 125 | mountdata->addr, mountdata->addrlen); |
| 126 | if (mountdata->addr->sa_family == AF_UNSPEC) | 126 | if (mountdata->addrlen == 0) |
| 127 | continue; | 127 | continue; |
| 128 | nfs_set_port(mountdata->addr, NFS_PORT); | 128 | rpc_set_port(mountdata->addr, NFS_PORT); |
| 129 | 129 | ||
| 130 | memcpy(page2, buf->data, buf->len); | 130 | memcpy(page2, buf->data, buf->len); |
| 131 | page2[buf->len] = '\0'; | 131 | page2[buf->len] = '\0'; |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 6917311f201c..be6544aef41f 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
| @@ -61,6 +61,8 @@ | |||
| 61 | #define NFS4_POLL_RETRY_MIN (HZ/10) | 61 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
| 62 | #define NFS4_POLL_RETRY_MAX (15*HZ) | 62 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 63 | 63 | ||
| 64 | #define NFS4_MAX_LOOP_ON_RECOVER (10) | ||
| 65 | |||
| 64 | struct nfs4_opendata; | 66 | struct nfs4_opendata; |
| 65 | static int _nfs4_proc_open(struct nfs4_opendata *data); | 67 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
| 66 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); | 68 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
| @@ -426,17 +428,19 @@ out: | |||
| 426 | static int nfs4_recover_session(struct nfs4_session *session) | 428 | static int nfs4_recover_session(struct nfs4_session *session) |
| 427 | { | 429 | { |
| 428 | struct nfs_client *clp = session->clp; | 430 | struct nfs_client *clp = session->clp; |
| 431 | unsigned int loop; | ||
| 429 | int ret; | 432 | int ret; |
| 430 | 433 | ||
| 431 | for (;;) { | 434 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 432 | ret = nfs4_wait_clnt_recover(clp); | 435 | ret = nfs4_wait_clnt_recover(clp); |
| 433 | if (ret != 0) | 436 | if (ret != 0) |
| 434 | return ret; | 437 | break; |
| 435 | if (!test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)) | 438 | if (!test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)) |
| 436 | break; | 439 | break; |
| 437 | nfs4_schedule_state_manager(clp); | 440 | nfs4_schedule_state_manager(clp); |
| 441 | ret = -EIO; | ||
| 438 | } | 442 | } |
| 439 | return 0; | 443 | return ret; |
| 440 | } | 444 | } |
| 441 | 445 | ||
| 442 | static int nfs41_setup_sequence(struct nfs4_session *session, | 446 | static int nfs41_setup_sequence(struct nfs4_session *session, |
| @@ -1444,18 +1448,20 @@ static int _nfs4_proc_open(struct nfs4_opendata *data) | |||
| 1444 | static int nfs4_recover_expired_lease(struct nfs_server *server) | 1448 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1445 | { | 1449 | { |
| 1446 | struct nfs_client *clp = server->nfs_client; | 1450 | struct nfs_client *clp = server->nfs_client; |
| 1451 | unsigned int loop; | ||
| 1447 | int ret; | 1452 | int ret; |
| 1448 | 1453 | ||
| 1449 | for (;;) { | 1454 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 1450 | ret = nfs4_wait_clnt_recover(clp); | 1455 | ret = nfs4_wait_clnt_recover(clp); |
| 1451 | if (ret != 0) | 1456 | if (ret != 0) |
| 1452 | return ret; | 1457 | break; |
| 1453 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && | 1458 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1454 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) | 1459 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
| 1455 | break; | 1460 | break; |
| 1456 | nfs4_schedule_state_recovery(clp); | 1461 | nfs4_schedule_state_recovery(clp); |
| 1462 | ret = -EIO; | ||
| 1457 | } | 1463 | } |
| 1458 | return 0; | 1464 | return ret; |
| 1459 | } | 1465 | } |
| 1460 | 1466 | ||
| 1461 | /* | 1467 | /* |
| @@ -1997,12 +2003,34 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f | |||
| 1997 | status = nfs4_call_sync(server, &msg, &args, &res, 0); | 2003 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
| 1998 | if (status == 0) { | 2004 | if (status == 0) { |
| 1999 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); | 2005 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
| 2006 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| | ||
| 2007 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| | ||
| 2008 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| | ||
| 2009 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| | ||
| 2010 | NFS_CAP_CTIME|NFS_CAP_MTIME); | ||
| 2000 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) | 2011 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2001 | server->caps |= NFS_CAP_ACLS; | 2012 | server->caps |= NFS_CAP_ACLS; |
| 2002 | if (res.has_links != 0) | 2013 | if (res.has_links != 0) |
| 2003 | server->caps |= NFS_CAP_HARDLINKS; | 2014 | server->caps |= NFS_CAP_HARDLINKS; |
| 2004 | if (res.has_symlinks != 0) | 2015 | if (res.has_symlinks != 0) |
| 2005 | server->caps |= NFS_CAP_SYMLINKS; | 2016 | server->caps |= NFS_CAP_SYMLINKS; |
| 2017 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) | ||
| 2018 | server->caps |= NFS_CAP_FILEID; | ||
| 2019 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) | ||
| 2020 | server->caps |= NFS_CAP_MODE; | ||
| 2021 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) | ||
| 2022 | server->caps |= NFS_CAP_NLINK; | ||
| 2023 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) | ||
| 2024 | server->caps |= NFS_CAP_OWNER; | ||
| 2025 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) | ||
| 2026 | server->caps |= NFS_CAP_OWNER_GROUP; | ||
| 2027 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) | ||
| 2028 | server->caps |= NFS_CAP_ATIME; | ||
| 2029 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) | ||
| 2030 | server->caps |= NFS_CAP_CTIME; | ||
| 2031 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) | ||
| 2032 | server->caps |= NFS_CAP_MTIME; | ||
| 2033 | |||
| 2006 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); | 2034 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2007 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; | 2035 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2008 | server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; | 2036 | server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; |
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 14b6f513648f..cfc30d362f94 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c | |||
| @@ -3148,7 +3148,8 @@ out_overflow: | |||
| 3148 | return -EIO; | 3148 | return -EIO; |
| 3149 | } | 3149 | } |
| 3150 | 3150 | ||
| 3151 | static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid) | 3151 | static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, |
| 3152 | struct nfs_client *clp, uint32_t *uid, int may_sleep) | ||
| 3152 | { | 3153 | { |
| 3153 | uint32_t len; | 3154 | uint32_t len; |
| 3154 | __be32 *p; | 3155 | __be32 *p; |
| @@ -3165,7 +3166,9 @@ static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nf | |||
| 3165 | p = xdr_inline_decode(xdr, len); | 3166 | p = xdr_inline_decode(xdr, len); |
| 3166 | if (unlikely(!p)) | 3167 | if (unlikely(!p)) |
| 3167 | goto out_overflow; | 3168 | goto out_overflow; |
| 3168 | if (len < XDR_MAX_NETOBJ) { | 3169 | if (!may_sleep) { |
| 3170 | /* do nothing */ | ||
| 3171 | } else if (len < XDR_MAX_NETOBJ) { | ||
| 3169 | if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0) | 3172 | if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0) |
| 3170 | ret = NFS_ATTR_FATTR_OWNER; | 3173 | ret = NFS_ATTR_FATTR_OWNER; |
| 3171 | else | 3174 | else |
| @@ -3183,7 +3186,8 @@ out_overflow: | |||
| 3183 | return -EIO; | 3186 | return -EIO; |
| 3184 | } | 3187 | } |
| 3185 | 3188 | ||
| 3186 | static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid) | 3189 | static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, |
| 3190 | struct nfs_client *clp, uint32_t *gid, int may_sleep) | ||
| 3187 | { | 3191 | { |
| 3188 | uint32_t len; | 3192 | uint32_t len; |
| 3189 | __be32 *p; | 3193 | __be32 *p; |
| @@ -3200,7 +3204,9 @@ static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nf | |||
| 3200 | p = xdr_inline_decode(xdr, len); | 3204 | p = xdr_inline_decode(xdr, len); |
| 3201 | if (unlikely(!p)) | 3205 | if (unlikely(!p)) |
| 3202 | goto out_overflow; | 3206 | goto out_overflow; |
| 3203 | if (len < XDR_MAX_NETOBJ) { | 3207 | if (!may_sleep) { |
| 3208 | /* do nothing */ | ||
| 3209 | } else if (len < XDR_MAX_NETOBJ) { | ||
| 3204 | if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0) | 3210 | if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0) |
| 3205 | ret = NFS_ATTR_FATTR_GROUP; | 3211 | ret = NFS_ATTR_FATTR_GROUP; |
| 3206 | else | 3212 | else |
| @@ -3616,7 +3622,8 @@ xdr_error: | |||
| 3616 | return status; | 3622 | return status; |
| 3617 | } | 3623 | } |
| 3618 | 3624 | ||
| 3619 | static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server) | 3625 | static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, |
| 3626 | const struct nfs_server *server, int may_sleep) | ||
| 3620 | { | 3627 | { |
| 3621 | __be32 *savep; | 3628 | __be32 *savep; |
| 3622 | uint32_t attrlen, | 3629 | uint32_t attrlen, |
| @@ -3688,12 +3695,14 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons | |||
| 3688 | goto xdr_error; | 3695 | goto xdr_error; |
| 3689 | fattr->valid |= status; | 3696 | fattr->valid |= status; |
| 3690 | 3697 | ||
| 3691 | status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid); | 3698 | status = decode_attr_owner(xdr, bitmap, server->nfs_client, |
| 3699 | &fattr->uid, may_sleep); | ||
| 3692 | if (status < 0) | 3700 | if (status < 0) |
| 3693 | goto xdr_error; | 3701 | goto xdr_error; |
| 3694 | fattr->valid |= status; | 3702 | fattr->valid |= status; |
| 3695 | 3703 | ||
| 3696 | status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid); | 3704 | status = decode_attr_group(xdr, bitmap, server->nfs_client, |
| 3705 | &fattr->gid, may_sleep); | ||
| 3697 | if (status < 0) | 3706 | if (status < 0) |
| 3698 | goto xdr_error; | 3707 | goto xdr_error; |
| 3699 | fattr->valid |= status; | 3708 | fattr->valid |= status; |
| @@ -4616,7 +4625,8 @@ static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct | |||
| 4616 | status = decode_open_downgrade(&xdr, res); | 4625 | status = decode_open_downgrade(&xdr, res); |
| 4617 | if (status != 0) | 4626 | if (status != 0) |
| 4618 | goto out; | 4627 | goto out; |
| 4619 | decode_getfattr(&xdr, res->fattr, res->server); | 4628 | decode_getfattr(&xdr, res->fattr, res->server, |
| 4629 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4620 | out: | 4630 | out: |
| 4621 | return status; | 4631 | return status; |
| 4622 | } | 4632 | } |
| @@ -4643,7 +4653,8 @@ static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_ac | |||
| 4643 | status = decode_access(&xdr, res); | 4653 | status = decode_access(&xdr, res); |
| 4644 | if (status != 0) | 4654 | if (status != 0) |
| 4645 | goto out; | 4655 | goto out; |
| 4646 | decode_getfattr(&xdr, res->fattr, res->server); | 4656 | decode_getfattr(&xdr, res->fattr, res->server, |
| 4657 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4647 | out: | 4658 | out: |
| 4648 | return status; | 4659 | return status; |
| 4649 | } | 4660 | } |
| @@ -4670,7 +4681,8 @@ static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lo | |||
| 4670 | goto out; | 4681 | goto out; |
| 4671 | if ((status = decode_getfh(&xdr, res->fh)) != 0) | 4682 | if ((status = decode_getfh(&xdr, res->fh)) != 0) |
| 4672 | goto out; | 4683 | goto out; |
| 4673 | status = decode_getfattr(&xdr, res->fattr, res->server); | 4684 | status = decode_getfattr(&xdr, res->fattr, res->server |
| 4685 | ,!RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4674 | out: | 4686 | out: |
| 4675 | return status; | 4687 | return status; |
| 4676 | } | 4688 | } |
| @@ -4694,7 +4706,8 @@ static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nf | |||
| 4694 | if ((status = decode_putrootfh(&xdr)) != 0) | 4706 | if ((status = decode_putrootfh(&xdr)) != 0) |
| 4695 | goto out; | 4707 | goto out; |
| 4696 | if ((status = decode_getfh(&xdr, res->fh)) == 0) | 4708 | if ((status = decode_getfh(&xdr, res->fh)) == 0) |
| 4697 | status = decode_getfattr(&xdr, res->fattr, res->server); | 4709 | status = decode_getfattr(&xdr, res->fattr, res->server, |
| 4710 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4698 | out: | 4711 | out: |
| 4699 | return status; | 4712 | return status; |
| 4700 | } | 4713 | } |
| @@ -4719,7 +4732,8 @@ static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_rem | |||
| 4719 | goto out; | 4732 | goto out; |
| 4720 | if ((status = decode_remove(&xdr, &res->cinfo)) != 0) | 4733 | if ((status = decode_remove(&xdr, &res->cinfo)) != 0) |
| 4721 | goto out; | 4734 | goto out; |
| 4722 | decode_getfattr(&xdr, &res->dir_attr, res->server); | 4735 | decode_getfattr(&xdr, &res->dir_attr, res->server, |
| 4736 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4723 | out: | 4737 | out: |
| 4724 | return status; | 4738 | return status; |
| 4725 | } | 4739 | } |
| @@ -4749,11 +4763,13 @@ static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_re | |||
| 4749 | if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) | 4763 | if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) |
| 4750 | goto out; | 4764 | goto out; |
| 4751 | /* Current FH is target directory */ | 4765 | /* Current FH is target directory */ |
| 4752 | if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0) | 4766 | if (decode_getfattr(&xdr, res->new_fattr, res->server, |
| 4767 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | ||
| 4753 | goto out; | 4768 | goto out; |
| 4754 | if ((status = decode_restorefh(&xdr)) != 0) | 4769 | if ((status = decode_restorefh(&xdr)) != 0) |
| 4755 | goto out; | 4770 | goto out; |
| 4756 | decode_getfattr(&xdr, res->old_fattr, res->server); | 4771 | decode_getfattr(&xdr, res->old_fattr, res->server, |
| 4772 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4757 | out: | 4773 | out: |
| 4758 | return status; | 4774 | return status; |
| 4759 | } | 4775 | } |
| @@ -4786,11 +4802,13 @@ static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link | |||
| 4786 | * Note order: OP_LINK leaves the directory as the current | 4802 | * Note order: OP_LINK leaves the directory as the current |
| 4787 | * filehandle. | 4803 | * filehandle. |
| 4788 | */ | 4804 | */ |
| 4789 | if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0) | 4805 | if (decode_getfattr(&xdr, res->dir_attr, res->server, |
| 4806 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | ||
| 4790 | goto out; | 4807 | goto out; |
| 4791 | if ((status = decode_restorefh(&xdr)) != 0) | 4808 | if ((status = decode_restorefh(&xdr)) != 0) |
| 4792 | goto out; | 4809 | goto out; |
| 4793 | decode_getfattr(&xdr, res->fattr, res->server); | 4810 | decode_getfattr(&xdr, res->fattr, res->server, |
| 4811 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4794 | out: | 4812 | out: |
| 4795 | return status; | 4813 | return status; |
| 4796 | } | 4814 | } |
| @@ -4819,11 +4837,13 @@ static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_cr | |||
| 4819 | goto out; | 4837 | goto out; |
| 4820 | if ((status = decode_getfh(&xdr, res->fh)) != 0) | 4838 | if ((status = decode_getfh(&xdr, res->fh)) != 0) |
| 4821 | goto out; | 4839 | goto out; |
| 4822 | if (decode_getfattr(&xdr, res->fattr, res->server) != 0) | 4840 | if (decode_getfattr(&xdr, res->fattr, res->server, |
| 4841 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | ||
| 4823 | goto out; | 4842 | goto out; |
| 4824 | if ((status = decode_restorefh(&xdr)) != 0) | 4843 | if ((status = decode_restorefh(&xdr)) != 0) |
| 4825 | goto out; | 4844 | goto out; |
| 4826 | decode_getfattr(&xdr, res->dir_fattr, res->server); | 4845 | decode_getfattr(&xdr, res->dir_fattr, res->server, |
| 4846 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4827 | out: | 4847 | out: |
| 4828 | return status; | 4848 | return status; |
| 4829 | } | 4849 | } |
| @@ -4855,7 +4875,8 @@ static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_g | |||
| 4855 | status = decode_putfh(&xdr); | 4875 | status = decode_putfh(&xdr); |
| 4856 | if (status) | 4876 | if (status) |
| 4857 | goto out; | 4877 | goto out; |
| 4858 | status = decode_getfattr(&xdr, res->fattr, res->server); | 4878 | status = decode_getfattr(&xdr, res->fattr, res->server, |
| 4879 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4859 | out: | 4880 | out: |
| 4860 | return status; | 4881 | return status; |
| 4861 | } | 4882 | } |
| @@ -4962,7 +4983,8 @@ static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_clos | |||
| 4962 | * an ESTALE error. Shouldn't be a problem, | 4983 | * an ESTALE error. Shouldn't be a problem, |
| 4963 | * though, since fattr->valid will remain unset. | 4984 | * though, since fattr->valid will remain unset. |
| 4964 | */ | 4985 | */ |
| 4965 | decode_getfattr(&xdr, res->fattr, res->server); | 4986 | decode_getfattr(&xdr, res->fattr, res->server, |
| 4987 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 4966 | out: | 4988 | out: |
| 4967 | return status; | 4989 | return status; |
| 4968 | } | 4990 | } |
| @@ -4994,11 +5016,13 @@ static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openr | |||
| 4994 | goto out; | 5016 | goto out; |
| 4995 | if (decode_getfh(&xdr, &res->fh) != 0) | 5017 | if (decode_getfh(&xdr, &res->fh) != 0) |
| 4996 | goto out; | 5018 | goto out; |
| 4997 | if (decode_getfattr(&xdr, res->f_attr, res->server) != 0) | 5019 | if (decode_getfattr(&xdr, res->f_attr, res->server, |
| 5020 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | ||
| 4998 | goto out; | 5021 | goto out; |
| 4999 | if (decode_restorefh(&xdr) != 0) | 5022 | if (decode_restorefh(&xdr) != 0) |
| 5000 | goto out; | 5023 | goto out; |
| 5001 | decode_getfattr(&xdr, res->dir_attr, res->server); | 5024 | decode_getfattr(&xdr, res->dir_attr, res->server, |
| 5025 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 5002 | out: | 5026 | out: |
| 5003 | return status; | 5027 | return status; |
| 5004 | } | 5028 | } |
| @@ -5046,7 +5070,8 @@ static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nf | |||
| 5046 | status = decode_open(&xdr, res); | 5070 | status = decode_open(&xdr, res); |
| 5047 | if (status) | 5071 | if (status) |
| 5048 | goto out; | 5072 | goto out; |
| 5049 | decode_getfattr(&xdr, res->f_attr, res->server); | 5073 | decode_getfattr(&xdr, res->f_attr, res->server, |
| 5074 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 5050 | out: | 5075 | out: |
| 5051 | return status; | 5076 | return status; |
| 5052 | } | 5077 | } |
| @@ -5073,7 +5098,8 @@ static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_se | |||
| 5073 | status = decode_setattr(&xdr); | 5098 | status = decode_setattr(&xdr); |
| 5074 | if (status) | 5099 | if (status) |
| 5075 | goto out; | 5100 | goto out; |
| 5076 | decode_getfattr(&xdr, res->fattr, res->server); | 5101 | decode_getfattr(&xdr, res->fattr, res->server, |
| 5102 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 5077 | out: | 5103 | out: |
| 5078 | return status; | 5104 | return status; |
| 5079 | } | 5105 | } |
| @@ -5247,7 +5273,8 @@ static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writ | |||
| 5247 | status = decode_write(&xdr, res); | 5273 | status = decode_write(&xdr, res); |
| 5248 | if (status) | 5274 | if (status) |
| 5249 | goto out; | 5275 | goto out; |
| 5250 | decode_getfattr(&xdr, res->fattr, res->server); | 5276 | decode_getfattr(&xdr, res->fattr, res->server, |
| 5277 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 5251 | if (!status) | 5278 | if (!status) |
| 5252 | status = res->count; | 5279 | status = res->count; |
| 5253 | out: | 5280 | out: |
| @@ -5276,7 +5303,8 @@ static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_wri | |||
| 5276 | status = decode_commit(&xdr, res); | 5303 | status = decode_commit(&xdr, res); |
| 5277 | if (status) | 5304 | if (status) |
| 5278 | goto out; | 5305 | goto out; |
| 5279 | decode_getfattr(&xdr, res->fattr, res->server); | 5306 | decode_getfattr(&xdr, res->fattr, res->server, |
| 5307 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 5280 | out: | 5308 | out: |
| 5281 | return status; | 5309 | return status; |
| 5282 | } | 5310 | } |
| @@ -5440,7 +5468,8 @@ static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nf | |||
| 5440 | if (status != 0) | 5468 | if (status != 0) |
| 5441 | goto out; | 5469 | goto out; |
| 5442 | status = decode_delegreturn(&xdr); | 5470 | status = decode_delegreturn(&xdr); |
| 5443 | decode_getfattr(&xdr, res->fattr, res->server); | 5471 | decode_getfattr(&xdr, res->fattr, res->server, |
| 5472 | !RPC_IS_ASYNC(rqstp->rq_task)); | ||
| 5444 | out: | 5473 | out: |
| 5445 | return status; | 5474 | return status; |
| 5446 | } | 5475 | } |
| @@ -5468,7 +5497,8 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, | |||
| 5468 | goto out; | 5497 | goto out; |
| 5469 | xdr_enter_page(&xdr, PAGE_SIZE); | 5498 | xdr_enter_page(&xdr, PAGE_SIZE); |
| 5470 | status = decode_getfattr(&xdr, &res->fs_locations->fattr, | 5499 | status = decode_getfattr(&xdr, &res->fs_locations->fattr, |
| 5471 | res->fs_locations->server); | 5500 | res->fs_locations->server, |
| 5501 | !RPC_IS_ASYNC(req->rq_task)); | ||
| 5472 | out: | 5502 | out: |
| 5473 | return status; | 5503 | return status; |
| 5474 | } | 5504 | } |
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 0b4cbdc60abd..9c85cdb353aa 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
| @@ -158,7 +158,7 @@ static const match_table_t nfs_mount_option_tokens = { | |||
| 158 | { Opt_mountvers, "mountvers=%s" }, | 158 | { Opt_mountvers, "mountvers=%s" }, |
| 159 | { Opt_nfsvers, "nfsvers=%s" }, | 159 | { Opt_nfsvers, "nfsvers=%s" }, |
| 160 | { Opt_nfsvers, "vers=%s" }, | 160 | { Opt_nfsvers, "vers=%s" }, |
| 161 | { Opt_minorversion, "minorversion=%u" }, | 161 | { Opt_minorversion, "minorversion=%s" }, |
| 162 | 162 | ||
| 163 | { Opt_sec, "sec=%s" }, | 163 | { Opt_sec, "sec=%s" }, |
| 164 | { Opt_proto, "proto=%s" }, | 164 | { Opt_proto, "proto=%s" }, |
| @@ -742,129 +742,10 @@ static int nfs_verify_server_address(struct sockaddr *addr) | |||
| 742 | } | 742 | } |
| 743 | } | 743 | } |
| 744 | 744 | ||
| 745 | dfprintk(MOUNT, "NFS: Invalid IP address specified\n"); | ||
| 745 | return 0; | 746 | return 0; |
| 746 | } | 747 | } |
| 747 | 748 | ||
| 748 | static void nfs_parse_ipv4_address(char *string, size_t str_len, | ||
| 749 | struct sockaddr *sap, size_t *addr_len) | ||
| 750 | { | ||
| 751 | struct sockaddr_in *sin = (struct sockaddr_in *)sap; | ||
| 752 | u8 *addr = (u8 *)&sin->sin_addr.s_addr; | ||
| 753 | |||
| 754 | if (str_len <= INET_ADDRSTRLEN) { | ||
| 755 | dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n", | ||
| 756 | (int)str_len, string); | ||
| 757 | |||
| 758 | sin->sin_family = AF_INET; | ||
| 759 | *addr_len = sizeof(*sin); | ||
| 760 | if (in4_pton(string, str_len, addr, '\0', NULL)) | ||
| 761 | return; | ||
| 762 | } | ||
| 763 | |||
| 764 | sap->sa_family = AF_UNSPEC; | ||
| 765 | *addr_len = 0; | ||
| 766 | } | ||
| 767 | |||
| 768 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
| 769 | static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len, | ||
| 770 | const char *delim, | ||
| 771 | struct sockaddr_in6 *sin6) | ||
| 772 | { | ||
| 773 | char *p; | ||
| 774 | size_t len; | ||
| 775 | |||
| 776 | if ((string + str_len) == delim) | ||
| 777 | return 1; | ||
| 778 | |||
| 779 | if (*delim != IPV6_SCOPE_DELIMITER) | ||
| 780 | return 0; | ||
| 781 | |||
| 782 | if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)) | ||
| 783 | return 0; | ||
| 784 | |||
| 785 | len = (string + str_len) - delim - 1; | ||
| 786 | p = kstrndup(delim + 1, len, GFP_KERNEL); | ||
| 787 | if (p) { | ||
| 788 | unsigned long scope_id = 0; | ||
| 789 | struct net_device *dev; | ||
| 790 | |||
| 791 | dev = dev_get_by_name(&init_net, p); | ||
| 792 | if (dev != NULL) { | ||
| 793 | scope_id = dev->ifindex; | ||
| 794 | dev_put(dev); | ||
| 795 | } else { | ||
| 796 | if (strict_strtoul(p, 10, &scope_id) == 0) { | ||
| 797 | kfree(p); | ||
| 798 | return 0; | ||
| 799 | } | ||
| 800 | } | ||
| 801 | |||
| 802 | kfree(p); | ||
| 803 | |||
| 804 | sin6->sin6_scope_id = scope_id; | ||
| 805 | dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id); | ||
| 806 | return 1; | ||
| 807 | } | ||
| 808 | |||
| 809 | return 0; | ||
| 810 | } | ||
| 811 | |||
| 812 | static void nfs_parse_ipv6_address(char *string, size_t str_len, | ||
| 813 | struct sockaddr *sap, size_t *addr_len) | ||
| 814 | { | ||
| 815 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; | ||
| 816 | u8 *addr = (u8 *)&sin6->sin6_addr.in6_u; | ||
| 817 | const char *delim; | ||
| 818 | |||
| 819 | if (str_len <= INET6_ADDRSTRLEN) { | ||
| 820 | dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n", | ||
| 821 | (int)str_len, string); | ||
| 822 | |||
| 823 | sin6->sin6_family = AF_INET6; | ||
| 824 | *addr_len = sizeof(*sin6); | ||
| 825 | if (in6_pton(string, str_len, addr, | ||
| 826 | IPV6_SCOPE_DELIMITER, &delim) != 0) { | ||
| 827 | if (nfs_parse_ipv6_scope_id(string, str_len, | ||
| 828 | delim, sin6) != 0) | ||
| 829 | return; | ||
| 830 | } | ||
| 831 | } | ||
| 832 | |||
| 833 | sap->sa_family = AF_UNSPEC; | ||
| 834 | *addr_len = 0; | ||
| 835 | } | ||
| 836 | #else | ||
| 837 | static void nfs_parse_ipv6_address(char *string, size_t str_len, | ||
| 838 | struct sockaddr *sap, size_t *addr_len) | ||
| 839 | { | ||
| 840 | sap->sa_family = AF_UNSPEC; | ||
| 841 | *addr_len = 0; | ||
| 842 | } | ||
| 843 | #endif | ||
| 844 | |||
| 845 | /* | ||
| 846 | * Construct a sockaddr based on the contents of a string that contains | ||
| 847 | * an IP address in presentation format. | ||
| 848 | * | ||
| 849 | * If there is a problem constructing the new sockaddr, set the address | ||
| 850 | * family to AF_UNSPEC. | ||
| 851 | */ | ||
| 852 | void nfs_parse_ip_address(char *string, size_t str_len, | ||
| 853 | struct sockaddr *sap, size_t *addr_len) | ||
| 854 | { | ||
| 855 | unsigned int i, colons; | ||
| 856 | |||
| 857 | colons = 0; | ||
| 858 | for (i = 0; i < str_len; i++) | ||
| 859 | if (string[i] == ':') | ||
| 860 | colons++; | ||
| 861 | |||
| 862 | if (colons >= 2) | ||
| 863 | nfs_parse_ipv6_address(string, str_len, sap, addr_len); | ||
| 864 | else | ||
| 865 | nfs_parse_ipv4_address(string, str_len, sap, addr_len); | ||
| 866 | } | ||
| 867 | |||
| 868 | /* | 749 | /* |
| 869 | * Sanity check the NFS transport protocol. | 750 | * Sanity check the NFS transport protocol. |
| 870 | * | 751 | * |
| @@ -904,8 +785,6 @@ static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt) | |||
| 904 | 785 | ||
| 905 | /* | 786 | /* |
| 906 | * Parse the value of the 'sec=' option. | 787 | * Parse the value of the 'sec=' option. |
| 907 | * | ||
| 908 | * The flavor_len setting is for v4 mounts. | ||
| 909 | */ | 788 | */ |
| 910 | static int nfs_parse_security_flavors(char *value, | 789 | static int nfs_parse_security_flavors(char *value, |
| 911 | struct nfs_parsed_mount_data *mnt) | 790 | struct nfs_parsed_mount_data *mnt) |
| @@ -916,53 +795,43 @@ static int nfs_parse_security_flavors(char *value, | |||
| 916 | 795 | ||
| 917 | switch (match_token(value, nfs_secflavor_tokens, args)) { | 796 | switch (match_token(value, nfs_secflavor_tokens, args)) { |
| 918 | case Opt_sec_none: | 797 | case Opt_sec_none: |
| 919 | mnt->auth_flavor_len = 0; | ||
| 920 | mnt->auth_flavors[0] = RPC_AUTH_NULL; | 798 | mnt->auth_flavors[0] = RPC_AUTH_NULL; |
| 921 | break; | 799 | break; |
| 922 | case Opt_sec_sys: | 800 | case Opt_sec_sys: |
| 923 | mnt->auth_flavor_len = 0; | ||
| 924 | mnt->auth_flavors[0] = RPC_AUTH_UNIX; | 801 | mnt->auth_flavors[0] = RPC_AUTH_UNIX; |
| 925 | break; | 802 | break; |
| 926 | case Opt_sec_krb5: | 803 | case Opt_sec_krb5: |
| 927 | mnt->auth_flavor_len = 1; | ||
| 928 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5; | 804 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5; |
| 929 | break; | 805 | break; |
| 930 | case Opt_sec_krb5i: | 806 | case Opt_sec_krb5i: |
| 931 | mnt->auth_flavor_len = 1; | ||
| 932 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I; | 807 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I; |
| 933 | break; | 808 | break; |
| 934 | case Opt_sec_krb5p: | 809 | case Opt_sec_krb5p: |
| 935 | mnt->auth_flavor_len = 1; | ||
| 936 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P; | 810 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P; |
| 937 | break; | 811 | break; |
| 938 | case Opt_sec_lkey: | 812 | case Opt_sec_lkey: |
| 939 | mnt->auth_flavor_len = 1; | ||
| 940 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY; | 813 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY; |
| 941 | break; | 814 | break; |
| 942 | case Opt_sec_lkeyi: | 815 | case Opt_sec_lkeyi: |
| 943 | mnt->auth_flavor_len = 1; | ||
| 944 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI; | 816 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI; |
| 945 | break; | 817 | break; |
| 946 | case Opt_sec_lkeyp: | 818 | case Opt_sec_lkeyp: |
| 947 | mnt->auth_flavor_len = 1; | ||
| 948 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP; | 819 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP; |
| 949 | break; | 820 | break; |
| 950 | case Opt_sec_spkm: | 821 | case Opt_sec_spkm: |
| 951 | mnt->auth_flavor_len = 1; | ||
| 952 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM; | 822 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM; |
| 953 | break; | 823 | break; |
| 954 | case Opt_sec_spkmi: | 824 | case Opt_sec_spkmi: |
| 955 | mnt->auth_flavor_len = 1; | ||
| 956 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI; | 825 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI; |
| 957 | break; | 826 | break; |
| 958 | case Opt_sec_spkmp: | 827 | case Opt_sec_spkmp: |
| 959 | mnt->auth_flavor_len = 1; | ||
| 960 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP; | 828 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP; |
| 961 | break; | 829 | break; |
| 962 | default: | 830 | default: |
| 963 | return 0; | 831 | return 0; |
| 964 | } | 832 | } |
| 965 | 833 | ||
| 834 | mnt->auth_flavor_len = 1; | ||
| 966 | return 1; | 835 | return 1; |
| 967 | } | 836 | } |
| 968 | 837 | ||
| @@ -1001,7 +870,6 @@ static int nfs_parse_mount_options(char *raw, | |||
| 1001 | while ((p = strsep(&raw, ",")) != NULL) { | 870 | while ((p = strsep(&raw, ",")) != NULL) { |
| 1002 | substring_t args[MAX_OPT_ARGS]; | 871 | substring_t args[MAX_OPT_ARGS]; |
| 1003 | unsigned long option; | 872 | unsigned long option; |
| 1004 | int int_option; | ||
| 1005 | int token; | 873 | int token; |
| 1006 | 874 | ||
| 1007 | if (!*p) | 875 | if (!*p) |
| @@ -1273,11 +1141,16 @@ static int nfs_parse_mount_options(char *raw, | |||
| 1273 | } | 1141 | } |
| 1274 | break; | 1142 | break; |
| 1275 | case Opt_minorversion: | 1143 | case Opt_minorversion: |
| 1276 | if (match_int(args, &int_option)) | 1144 | string = match_strdup(args); |
| 1277 | return 0; | 1145 | if (string == NULL) |
| 1278 | if (int_option < 0 || int_option > NFS4_MAX_MINOR_VERSION) | 1146 | goto out_nomem; |
| 1279 | return 0; | 1147 | rc = strict_strtoul(string, 10, &option); |
| 1280 | mnt->minorversion = int_option; | 1148 | kfree(string); |
| 1149 | if (rc != 0) | ||
| 1150 | goto out_invalid_value; | ||
| 1151 | if (option > NFS4_MAX_MINOR_VERSION) | ||
| 1152 | goto out_invalid_value; | ||
| 1153 | mnt->minorversion = option; | ||
| 1281 | break; | 1154 | break; |
| 1282 | 1155 | ||
| 1283 | /* | 1156 | /* |
| @@ -1352,11 +1225,14 @@ static int nfs_parse_mount_options(char *raw, | |||
| 1352 | string = match_strdup(args); | 1225 | string = match_strdup(args); |
| 1353 | if (string == NULL) | 1226 | if (string == NULL) |
| 1354 | goto out_nomem; | 1227 | goto out_nomem; |
| 1355 | nfs_parse_ip_address(string, strlen(string), | 1228 | mnt->nfs_server.addrlen = |
| 1356 | (struct sockaddr *) | 1229 | rpc_pton(string, strlen(string), |
| 1357 | &mnt->nfs_server.address, | 1230 | (struct sockaddr *) |
| 1358 | &mnt->nfs_server.addrlen); | 1231 | &mnt->nfs_server.address, |
| 1232 | sizeof(mnt->nfs_server.address)); | ||
| 1359 | kfree(string); | 1233 | kfree(string); |
| 1234 | if (mnt->nfs_server.addrlen == 0) | ||
| 1235 | goto out_invalid_address; | ||
| 1360 | break; | 1236 | break; |
| 1361 | case Opt_clientaddr: | 1237 | case Opt_clientaddr: |
| 1362 | string = match_strdup(args); | 1238 | string = match_strdup(args); |
| @@ -1376,11 +1252,14 @@ static int nfs_parse_mount_options(char *raw, | |||
| 1376 | string = match_strdup(args); | 1252 | string = match_strdup(args); |
| 1377 | if (string == NULL) | 1253 | if (string == NULL) |
| 1378 | goto out_nomem; | 1254 | goto out_nomem; |
| 1379 | nfs_parse_ip_address(string, strlen(string), | 1255 | mnt->mount_server.addrlen = |
| 1380 | (struct sockaddr *) | 1256 | rpc_pton(string, strlen(string), |
| 1381 | &mnt->mount_server.address, | 1257 | (struct sockaddr *) |
| 1382 | &mnt->mount_server.addrlen); | 1258 | &mnt->mount_server.address, |
| 1259 | sizeof(mnt->mount_server.address)); | ||
| 1383 | kfree(string); | 1260 | kfree(string); |
| 1261 | if (mnt->mount_server.addrlen == 0) | ||
| 1262 | goto out_invalid_address; | ||
| 1384 | break; | 1263 | break; |
| 1385 | case Opt_lookupcache: | 1264 | case Opt_lookupcache: |
| 1386 | string = match_strdup(args); | 1265 | string = match_strdup(args); |
| @@ -1432,8 +1311,11 @@ static int nfs_parse_mount_options(char *raw, | |||
| 1432 | 1311 | ||
| 1433 | return 1; | 1312 | return 1; |
| 1434 | 1313 | ||
| 1314 | out_invalid_address: | ||
| 1315 | printk(KERN_INFO "NFS: bad IP address specified: %s\n", p); | ||
| 1316 | return 0; | ||
| 1435 | out_invalid_value: | 1317 | out_invalid_value: |
| 1436 | printk(KERN_INFO "NFS: bad mount option value specified: %s \n", p); | 1318 | printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p); |
| 1437 | return 0; | 1319 | return 0; |
| 1438 | out_nomem: | 1320 | out_nomem: |
| 1439 | printk(KERN_INFO "NFS: not enough memory to parse option\n"); | 1321 | printk(KERN_INFO "NFS: not enough memory to parse option\n"); |
| @@ -1445,13 +1327,50 @@ out_security_failure: | |||
| 1445 | } | 1327 | } |
| 1446 | 1328 | ||
| 1447 | /* | 1329 | /* |
| 1330 | * Match the requested auth flavors with the list returned by | ||
| 1331 | * the server. Returns zero and sets the mount's authentication | ||
| 1332 | * flavor on success; returns -EACCES if server does not support | ||
| 1333 | * the requested flavor. | ||
| 1334 | */ | ||
| 1335 | static int nfs_walk_authlist(struct nfs_parsed_mount_data *args, | ||
| 1336 | struct nfs_mount_request *request) | ||
| 1337 | { | ||
| 1338 | unsigned int i, j, server_authlist_len = *(request->auth_flav_len); | ||
| 1339 | |||
| 1340 | /* | ||
| 1341 | * We avoid sophisticated negotiating here, as there are | ||
| 1342 | * plenty of cases where we can get it wrong, providing | ||
| 1343 | * either too little or too much security. | ||
| 1344 | * | ||
| 1345 | * RFC 2623, section 2.7 suggests we SHOULD prefer the | ||
| 1346 | * flavor listed first. However, some servers list | ||
| 1347 | * AUTH_NULL first. Our caller plants AUTH_SYS, the | ||
| 1348 | * preferred default, in args->auth_flavors[0] if user | ||
| 1349 | * didn't specify sec= mount option. | ||
| 1350 | */ | ||
| 1351 | for (i = 0; i < args->auth_flavor_len; i++) | ||
| 1352 | for (j = 0; j < server_authlist_len; j++) | ||
| 1353 | if (args->auth_flavors[i] == request->auth_flavs[j]) { | ||
| 1354 | dfprintk(MOUNT, "NFS: using auth flavor %d\n", | ||
| 1355 | request->auth_flavs[j]); | ||
| 1356 | args->auth_flavors[0] = request->auth_flavs[j]; | ||
| 1357 | return 0; | ||
| 1358 | } | ||
| 1359 | |||
| 1360 | dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n"); | ||
| 1361 | nfs_umount(request); | ||
| 1362 | return -EACCES; | ||
| 1363 | } | ||
| 1364 | |||
| 1365 | /* | ||
| 1448 | * Use the remote server's MOUNT service to request the NFS file handle | 1366 | * Use the remote server's MOUNT service to request the NFS file handle |
| 1449 | * corresponding to the provided path. | 1367 | * corresponding to the provided path. |
| 1450 | */ | 1368 | */ |
| 1451 | static int nfs_try_mount(struct nfs_parsed_mount_data *args, | 1369 | static int nfs_try_mount(struct nfs_parsed_mount_data *args, |
| 1452 | struct nfs_fh *root_fh) | 1370 | struct nfs_fh *root_fh) |
| 1453 | { | 1371 | { |
| 1454 | unsigned int auth_flavor_len = 0; | 1372 | rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS]; |
| 1373 | unsigned int server_authlist_len = ARRAY_SIZE(server_authlist); | ||
| 1455 | struct nfs_mount_request request = { | 1374 | struct nfs_mount_request request = { |
| 1456 | .sap = (struct sockaddr *) | 1375 | .sap = (struct sockaddr *) |
| 1457 | &args->mount_server.address, | 1376 | &args->mount_server.address, |
| @@ -1459,7 +1378,8 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args, | |||
| 1459 | .protocol = args->mount_server.protocol, | 1378 | .protocol = args->mount_server.protocol, |
| 1460 | .fh = root_fh, | 1379 | .fh = root_fh, |
| 1461 | .noresvport = args->flags & NFS_MOUNT_NORESVPORT, | 1380 | .noresvport = args->flags & NFS_MOUNT_NORESVPORT, |
| 1462 | .auth_flav_len = &auth_flavor_len, | 1381 | .auth_flav_len = &server_authlist_len, |
| 1382 | .auth_flavs = server_authlist, | ||
| 1463 | }; | 1383 | }; |
| 1464 | int status; | 1384 | int status; |
| 1465 | 1385 | ||
| @@ -1489,19 +1409,25 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args, | |||
| 1489 | /* | 1409 | /* |
| 1490 | * autobind will be used if mount_server.port == 0 | 1410 | * autobind will be used if mount_server.port == 0 |
| 1491 | */ | 1411 | */ |
| 1492 | nfs_set_port(request.sap, args->mount_server.port); | 1412 | rpc_set_port(request.sap, args->mount_server.port); |
| 1493 | 1413 | ||
| 1494 | /* | 1414 | /* |
| 1495 | * Now ask the mount server to map our export path | 1415 | * Now ask the mount server to map our export path |
| 1496 | * to a file handle. | 1416 | * to a file handle. |
| 1497 | */ | 1417 | */ |
| 1498 | status = nfs_mount(&request); | 1418 | status = nfs_mount(&request); |
| 1499 | if (status == 0) | 1419 | if (status != 0) { |
| 1500 | return 0; | 1420 | dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n", |
| 1421 | request.hostname, status); | ||
| 1422 | return status; | ||
| 1423 | } | ||
| 1501 | 1424 | ||
| 1502 | dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n", | 1425 | /* |
| 1503 | request.hostname, status); | 1426 | * MNTv1 (NFSv2) does not support auth flavor negotiation. |
| 1504 | return status; | 1427 | */ |
| 1428 | if (args->mount_server.version != NFS_MNT3_VERSION) | ||
| 1429 | return 0; | ||
| 1430 | return nfs_walk_authlist(args, &request); | ||
| 1505 | } | 1431 | } |
| 1506 | 1432 | ||
| 1507 | static int nfs_parse_simple_hostname(const char *dev_name, | 1433 | static int nfs_parse_simple_hostname(const char *dev_name, |
| @@ -1676,6 +1602,7 @@ static int nfs_validate_mount_data(void *options, | |||
| 1676 | args->nfs_server.port = 0; /* autobind unless user sets port */ | 1602 | args->nfs_server.port = 0; /* autobind unless user sets port */ |
| 1677 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; | 1603 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
| 1678 | args->auth_flavors[0] = RPC_AUTH_UNIX; | 1604 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
| 1605 | args->auth_flavor_len = 1; | ||
| 1679 | 1606 | ||
| 1680 | switch (data->version) { | 1607 | switch (data->version) { |
| 1681 | case 1: | 1608 | case 1: |
| @@ -1776,7 +1703,7 @@ static int nfs_validate_mount_data(void *options, | |||
| 1776 | &args->nfs_server.address)) | 1703 | &args->nfs_server.address)) |
| 1777 | goto out_no_address; | 1704 | goto out_no_address; |
| 1778 | 1705 | ||
| 1779 | nfs_set_port((struct sockaddr *)&args->nfs_server.address, | 1706 | rpc_set_port((struct sockaddr *)&args->nfs_server.address, |
| 1780 | args->nfs_server.port); | 1707 | args->nfs_server.port); |
| 1781 | 1708 | ||
| 1782 | nfs_set_mount_transport_protocol(args); | 1709 | nfs_set_mount_transport_protocol(args); |
| @@ -2339,7 +2266,7 @@ static int nfs4_validate_mount_data(void *options, | |||
| 2339 | args->acdirmax = NFS_DEF_ACDIRMAX; | 2266 | args->acdirmax = NFS_DEF_ACDIRMAX; |
| 2340 | args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */ | 2267 | args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */ |
| 2341 | args->auth_flavors[0] = RPC_AUTH_UNIX; | 2268 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
| 2342 | args->auth_flavor_len = 0; | 2269 | args->auth_flavor_len = 1; |
| 2343 | args->minorversion = 0; | 2270 | args->minorversion = 0; |
| 2344 | 2271 | ||
| 2345 | switch (data->version) { | 2272 | switch (data->version) { |
| @@ -2409,7 +2336,7 @@ static int nfs4_validate_mount_data(void *options, | |||
| 2409 | &args->nfs_server.address)) | 2336 | &args->nfs_server.address)) |
| 2410 | return -EINVAL; | 2337 | return -EINVAL; |
| 2411 | 2338 | ||
| 2412 | nfs_set_port((struct sockaddr *)&args->nfs_server.address, | 2339 | rpc_set_port((struct sockaddr *)&args->nfs_server.address, |
| 2413 | args->nfs_server.port); | 2340 | args->nfs_server.port); |
| 2414 | 2341 | ||
| 2415 | nfs_validate_transport_protocol(args); | 2342 | nfs_validate_transport_protocol(args); |
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index a34fae21fe10..120acadc6a84 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <linux/file.h> | 13 | #include <linux/file.h> |
| 14 | #include <linux/writeback.h> | 14 | #include <linux/writeback.h> |
| 15 | #include <linux/swap.h> | 15 | #include <linux/swap.h> |
| 16 | #include <linux/migrate.h> | ||
| 16 | 17 | ||
| 17 | #include <linux/sunrpc/clnt.h> | 18 | #include <linux/sunrpc/clnt.h> |
| 18 | #include <linux/nfs_fs.h> | 19 | #include <linux/nfs_fs.h> |
| @@ -26,6 +27,7 @@ | |||
| 26 | #include "internal.h" | 27 | #include "internal.h" |
| 27 | #include "iostat.h" | 28 | #include "iostat.h" |
| 28 | #include "nfs4_fs.h" | 29 | #include "nfs4_fs.h" |
| 30 | #include "fscache.h" | ||
| 29 | 31 | ||
| 30 | #define NFSDBG_FACILITY NFSDBG_PAGECACHE | 32 | #define NFSDBG_FACILITY NFSDBG_PAGECACHE |
| 31 | 33 | ||
| @@ -218,24 +220,17 @@ static void nfs_end_page_writeback(struct page *page) | |||
| 218 | clear_bdi_congested(&nfss->backing_dev_info, BLK_RW_ASYNC); | 220 | clear_bdi_congested(&nfss->backing_dev_info, BLK_RW_ASYNC); |
| 219 | } | 221 | } |
| 220 | 222 | ||
| 221 | /* | 223 | static struct nfs_page *nfs_find_and_lock_request(struct page *page) |
| 222 | * Find an associated nfs write request, and prepare to flush it out | ||
| 223 | * May return an error if the user signalled nfs_wait_on_request(). | ||
| 224 | */ | ||
| 225 | static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio, | ||
| 226 | struct page *page) | ||
| 227 | { | 224 | { |
| 228 | struct inode *inode = page->mapping->host; | 225 | struct inode *inode = page->mapping->host; |
| 229 | struct nfs_page *req; | 226 | struct nfs_page *req; |
| 230 | int ret; | 227 | int ret; |
| 231 | 228 | ||
| 232 | spin_lock(&inode->i_lock); | 229 | spin_lock(&inode->i_lock); |
| 233 | for(;;) { | 230 | for (;;) { |
| 234 | req = nfs_page_find_request_locked(page); | 231 | req = nfs_page_find_request_locked(page); |
| 235 | if (req == NULL) { | 232 | if (req == NULL) |
| 236 | spin_unlock(&inode->i_lock); | 233 | break; |
| 237 | return 0; | ||
| 238 | } | ||
| 239 | if (nfs_set_page_tag_locked(req)) | 234 | if (nfs_set_page_tag_locked(req)) |
| 240 | break; | 235 | break; |
| 241 | /* Note: If we hold the page lock, as is the case in nfs_writepage, | 236 | /* Note: If we hold the page lock, as is the case in nfs_writepage, |
| @@ -247,23 +242,40 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio, | |||
| 247 | ret = nfs_wait_on_request(req); | 242 | ret = nfs_wait_on_request(req); |
| 248 | nfs_release_request(req); | 243 | nfs_release_request(req); |
| 249 | if (ret != 0) | 244 | if (ret != 0) |
| 250 | return ret; | 245 | return ERR_PTR(ret); |
| 251 | spin_lock(&inode->i_lock); | 246 | spin_lock(&inode->i_lock); |
| 252 | } | 247 | } |
| 253 | if (test_bit(PG_CLEAN, &req->wb_flags)) { | ||
| 254 | spin_unlock(&inode->i_lock); | ||
| 255 | BUG(); | ||
| 256 | } | ||
| 257 | if (nfs_set_page_writeback(page) != 0) { | ||
| 258 | spin_unlock(&inode->i_lock); | ||
| 259 | BUG(); | ||
| 260 | } | ||
| 261 | spin_unlock(&inode->i_lock); | 248 | spin_unlock(&inode->i_lock); |
| 249 | return req; | ||
| 250 | } | ||
| 251 | |||
| 252 | /* | ||
| 253 | * Find an associated nfs write request, and prepare to flush it out | ||
| 254 | * May return an error if the user signalled nfs_wait_on_request(). | ||
| 255 | */ | ||
| 256 | static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio, | ||
| 257 | struct page *page) | ||
| 258 | { | ||
| 259 | struct nfs_page *req; | ||
| 260 | int ret = 0; | ||
| 261 | |||
| 262 | req = nfs_find_and_lock_request(page); | ||
| 263 | if (!req) | ||
| 264 | goto out; | ||
| 265 | ret = PTR_ERR(req); | ||
| 266 | if (IS_ERR(req)) | ||
| 267 | goto out; | ||
| 268 | |||
| 269 | ret = nfs_set_page_writeback(page); | ||
| 270 | BUG_ON(ret != 0); | ||
| 271 | BUG_ON(test_bit(PG_CLEAN, &req->wb_flags)); | ||
| 272 | |||
| 262 | if (!nfs_pageio_add_request(pgio, req)) { | 273 | if (!nfs_pageio_add_request(pgio, req)) { |
| 263 | nfs_redirty_request(req); | 274 | nfs_redirty_request(req); |
| 264 | return pgio->pg_error; | 275 | ret = pgio->pg_error; |
| 265 | } | 276 | } |
| 266 | return 0; | 277 | out: |
| 278 | return ret; | ||
| 267 | } | 279 | } |
| 268 | 280 | ||
| 269 | static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, struct nfs_pageio_descriptor *pgio) | 281 | static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, struct nfs_pageio_descriptor *pgio) |
| @@ -1580,6 +1592,41 @@ int nfs_wb_page(struct inode *inode, struct page* page) | |||
| 1580 | return nfs_wb_page_priority(inode, page, FLUSH_STABLE); | 1592 | return nfs_wb_page_priority(inode, page, FLUSH_STABLE); |
| 1581 | } | 1593 | } |
| 1582 | 1594 | ||
| 1595 | #ifdef CONFIG_MIGRATION | ||
| 1596 | int nfs_migrate_page(struct address_space *mapping, struct page *newpage, | ||
| 1597 | struct page *page) | ||
| 1598 | { | ||
| 1599 | struct nfs_page *req; | ||
| 1600 | int ret; | ||
| 1601 | |||
| 1602 | if (PageFsCache(page)) | ||
| 1603 | nfs_fscache_release_page(page, GFP_KERNEL); | ||
| 1604 | |||
| 1605 | req = nfs_find_and_lock_request(page); | ||
| 1606 | ret = PTR_ERR(req); | ||
| 1607 | if (IS_ERR(req)) | ||
| 1608 | goto out; | ||
| 1609 | |||
| 1610 | ret = migrate_page(mapping, newpage, page); | ||
| 1611 | if (!req) | ||
| 1612 | goto out; | ||
| 1613 | if (ret) | ||
| 1614 | goto out_unlock; | ||
| 1615 | page_cache_get(newpage); | ||
| 1616 | req->wb_page = newpage; | ||
| 1617 | SetPagePrivate(newpage); | ||
| 1618 | set_page_private(newpage, page_private(page)); | ||
| 1619 | ClearPagePrivate(page); | ||
| 1620 | set_page_private(page, 0); | ||
| 1621 | page_cache_release(page); | ||
| 1622 | out_unlock: | ||
| 1623 | nfs_clear_page_tag_locked(req); | ||
| 1624 | nfs_release_request(req); | ||
| 1625 | out: | ||
| 1626 | return ret; | ||
| 1627 | } | ||
| 1628 | #endif | ||
| 1629 | |||
| 1583 | int __init nfs_init_writepagecache(void) | 1630 | int __init nfs_init_writepagecache(void) |
| 1584 | { | 1631 | { |
| 1585 | nfs_wdata_cachep = kmem_cache_create("nfs_write_data", | 1632 | nfs_wdata_cachep = kmem_cache_create("nfs_write_data", |
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index b92a27629fb7..d9462643155c 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c | |||
| @@ -85,6 +85,11 @@ static void expkey_request(struct cache_detail *cd, | |||
| 85 | (*bpp)[-1] = '\n'; | 85 | (*bpp)[-1] = '\n'; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | static int expkey_upcall(struct cache_detail *cd, struct cache_head *h) | ||
| 89 | { | ||
| 90 | return sunrpc_cache_pipe_upcall(cd, h, expkey_request); | ||
| 91 | } | ||
| 92 | |||
| 88 | static struct svc_expkey *svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old); | 93 | static struct svc_expkey *svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old); |
| 89 | static struct svc_expkey *svc_expkey_lookup(struct svc_expkey *); | 94 | static struct svc_expkey *svc_expkey_lookup(struct svc_expkey *); |
| 90 | static struct cache_detail svc_expkey_cache; | 95 | static struct cache_detail svc_expkey_cache; |
| @@ -259,7 +264,7 @@ static struct cache_detail svc_expkey_cache = { | |||
| 259 | .hash_table = expkey_table, | 264 | .hash_table = expkey_table, |
| 260 | .name = "nfsd.fh", | 265 | .name = "nfsd.fh", |
| 261 | .cache_put = expkey_put, | 266 | .cache_put = expkey_put, |
| 262 | .cache_request = expkey_request, | 267 | .cache_upcall = expkey_upcall, |
| 263 | .cache_parse = expkey_parse, | 268 | .cache_parse = expkey_parse, |
| 264 | .cache_show = expkey_show, | 269 | .cache_show = expkey_show, |
| 265 | .match = expkey_match, | 270 | .match = expkey_match, |
| @@ -355,6 +360,11 @@ static void svc_export_request(struct cache_detail *cd, | |||
| 355 | (*bpp)[-1] = '\n'; | 360 | (*bpp)[-1] = '\n'; |
| 356 | } | 361 | } |
| 357 | 362 | ||
| 363 | static int svc_export_upcall(struct cache_detail *cd, struct cache_head *h) | ||
| 364 | { | ||
| 365 | return sunrpc_cache_pipe_upcall(cd, h, svc_export_request); | ||
| 366 | } | ||
| 367 | |||
| 358 | static struct svc_export *svc_export_update(struct svc_export *new, | 368 | static struct svc_export *svc_export_update(struct svc_export *new, |
| 359 | struct svc_export *old); | 369 | struct svc_export *old); |
| 360 | static struct svc_export *svc_export_lookup(struct svc_export *); | 370 | static struct svc_export *svc_export_lookup(struct svc_export *); |
| @@ -724,7 +734,7 @@ struct cache_detail svc_export_cache = { | |||
| 724 | .hash_table = export_table, | 734 | .hash_table = export_table, |
| 725 | .name = "nfsd.export", | 735 | .name = "nfsd.export", |
| 726 | .cache_put = svc_export_put, | 736 | .cache_put = svc_export_put, |
| 727 | .cache_request = svc_export_request, | 737 | .cache_upcall = svc_export_upcall, |
| 728 | .cache_parse = svc_export_parse, | 738 | .cache_parse = svc_export_parse, |
| 729 | .cache_show = svc_export_show, | 739 | .cache_show = svc_export_show, |
| 730 | .match = svc_export_match, | 740 | .match = svc_export_match, |
diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c index 5b398421b051..cdfa86fa1471 100644 --- a/fs/nfsd/nfs4idmap.c +++ b/fs/nfsd/nfs4idmap.c | |||
| @@ -146,6 +146,12 @@ idtoname_request(struct cache_detail *cd, struct cache_head *ch, char **bpp, | |||
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | static int | 148 | static int |
| 149 | idtoname_upcall(struct cache_detail *cd, struct cache_head *ch) | ||
| 150 | { | ||
| 151 | return sunrpc_cache_pipe_upcall(cd, ch, idtoname_request); | ||
| 152 | } | ||
| 153 | |||
| 154 | static int | ||
| 149 | idtoname_match(struct cache_head *ca, struct cache_head *cb) | 155 | idtoname_match(struct cache_head *ca, struct cache_head *cb) |
| 150 | { | 156 | { |
| 151 | struct ent *a = container_of(ca, struct ent, h); | 157 | struct ent *a = container_of(ca, struct ent, h); |
| @@ -175,10 +181,10 @@ idtoname_show(struct seq_file *m, struct cache_detail *cd, struct cache_head *h) | |||
| 175 | } | 181 | } |
| 176 | 182 | ||
| 177 | static void | 183 | static void |
| 178 | warn_no_idmapd(struct cache_detail *detail) | 184 | warn_no_idmapd(struct cache_detail *detail, int has_died) |
| 179 | { | 185 | { |
| 180 | printk("nfsd: nfsv4 idmapping failing: has idmapd %s?\n", | 186 | printk("nfsd: nfsv4 idmapping failing: has idmapd %s?\n", |
| 181 | detail->last_close? "died" : "not been started"); | 187 | has_died ? "died" : "not been started"); |
| 182 | } | 188 | } |
| 183 | 189 | ||
| 184 | 190 | ||
| @@ -192,7 +198,7 @@ static struct cache_detail idtoname_cache = { | |||
| 192 | .hash_table = idtoname_table, | 198 | .hash_table = idtoname_table, |
| 193 | .name = "nfs4.idtoname", | 199 | .name = "nfs4.idtoname", |
| 194 | .cache_put = ent_put, | 200 | .cache_put = ent_put, |
| 195 | .cache_request = idtoname_request, | 201 | .cache_upcall = idtoname_upcall, |
| 196 | .cache_parse = idtoname_parse, | 202 | .cache_parse = idtoname_parse, |
| 197 | .cache_show = idtoname_show, | 203 | .cache_show = idtoname_show, |
| 198 | .warn_no_listener = warn_no_idmapd, | 204 | .warn_no_listener = warn_no_idmapd, |
| @@ -325,6 +331,12 @@ nametoid_request(struct cache_detail *cd, struct cache_head *ch, char **bpp, | |||
| 325 | } | 331 | } |
| 326 | 332 | ||
| 327 | static int | 333 | static int |
| 334 | nametoid_upcall(struct cache_detail *cd, struct cache_head *ch) | ||
| 335 | { | ||
| 336 | return sunrpc_cache_pipe_upcall(cd, ch, nametoid_request); | ||
| 337 | } | ||
| 338 | |||
| 339 | static int | ||
| 328 | nametoid_match(struct cache_head *ca, struct cache_head *cb) | 340 | nametoid_match(struct cache_head *ca, struct cache_head *cb) |
| 329 | { | 341 | { |
| 330 | struct ent *a = container_of(ca, struct ent, h); | 342 | struct ent *a = container_of(ca, struct ent, h); |
| @@ -363,7 +375,7 @@ static struct cache_detail nametoid_cache = { | |||
| 363 | .hash_table = nametoid_table, | 375 | .hash_table = nametoid_table, |
| 364 | .name = "nfs4.nametoid", | 376 | .name = "nfs4.nametoid", |
| 365 | .cache_put = ent_put, | 377 | .cache_put = ent_put, |
| 366 | .cache_request = nametoid_request, | 378 | .cache_upcall = nametoid_upcall, |
| 367 | .cache_parse = nametoid_parse, | 379 | .cache_parse = nametoid_parse, |
| 368 | .cache_show = nametoid_show, | 380 | .cache_show = nametoid_show, |
| 369 | .warn_no_listener = warn_no_idmapd, | 381 | .warn_no_listener = warn_no_idmapd, |
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 6d0847562d87..7e906c5b7671 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c | |||
| @@ -37,6 +37,7 @@ | |||
| 37 | #include <linux/nfsd/xdr.h> | 37 | #include <linux/nfsd/xdr.h> |
| 38 | #include <linux/nfsd/syscall.h> | 38 | #include <linux/nfsd/syscall.h> |
| 39 | #include <linux/lockd/lockd.h> | 39 | #include <linux/lockd/lockd.h> |
| 40 | #include <linux/sunrpc/clnt.h> | ||
| 40 | 41 | ||
| 41 | #include <asm/uaccess.h> | 42 | #include <asm/uaccess.h> |
| 42 | #include <net/ipv6.h> | 43 | #include <net/ipv6.h> |
| @@ -490,22 +491,18 @@ static ssize_t write_getfd(struct file *file, char *buf, size_t size) | |||
| 490 | * | 491 | * |
| 491 | * Input: | 492 | * Input: |
| 492 | * buf: '\n'-terminated C string containing a | 493 | * buf: '\n'-terminated C string containing a |
| 493 | * presentation format IPv4 address | 494 | * presentation format IP address |
| 494 | * size: length of C string in @buf | 495 | * size: length of C string in @buf |
| 495 | * Output: | 496 | * Output: |
| 496 | * On success: returns zero if all specified locks were released; | 497 | * On success: returns zero if all specified locks were released; |
| 497 | * returns one if one or more locks were not released | 498 | * returns one if one or more locks were not released |
| 498 | * On error: return code is negative errno value | 499 | * On error: return code is negative errno value |
| 499 | * | ||
| 500 | * Note: Only AF_INET client addresses are passed in | ||
| 501 | */ | 500 | */ |
| 502 | static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) | 501 | static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) |
| 503 | { | 502 | { |
| 504 | struct sockaddr_in sin = { | 503 | struct sockaddr_storage address; |
| 505 | .sin_family = AF_INET, | 504 | struct sockaddr *sap = (struct sockaddr *)&address; |
| 506 | }; | 505 | size_t salen = sizeof(address); |
| 507 | int b1, b2, b3, b4; | ||
| 508 | char c; | ||
| 509 | char *fo_path; | 506 | char *fo_path; |
| 510 | 507 | ||
| 511 | /* sanity check */ | 508 | /* sanity check */ |
| @@ -519,14 +516,10 @@ static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) | |||
| 519 | if (qword_get(&buf, fo_path, size) < 0) | 516 | if (qword_get(&buf, fo_path, size) < 0) |
| 520 | return -EINVAL; | 517 | return -EINVAL; |
| 521 | 518 | ||
| 522 | /* get ipv4 address */ | 519 | if (rpc_pton(fo_path, size, sap, salen) == 0) |
| 523 | if (sscanf(fo_path, "%u.%u.%u.%u%c", &b1, &b2, &b3, &b4, &c) != 4) | ||
| 524 | return -EINVAL; | ||
| 525 | if (b1 > 255 || b2 > 255 || b3 > 255 || b4 > 255) | ||
| 526 | return -EINVAL; | 520 | return -EINVAL; |
| 527 | sin.sin_addr.s_addr = htonl((b1 << 24) | (b2 << 16) | (b3 << 8) | b4); | ||
| 528 | 521 | ||
| 529 | return nlmsvc_unlock_all_by_ip((struct sockaddr *)&sin); | 522 | return nlmsvc_unlock_all_by_ip(sap); |
| 530 | } | 523 | } |
| 531 | 524 | ||
| 532 | /** | 525 | /** |
diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index 19fe15d12042..320569eabe3b 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h | |||
| @@ -167,6 +167,15 @@ struct nfs_server { | |||
| 167 | #define NFS_CAP_SYMLINKS (1U << 2) | 167 | #define NFS_CAP_SYMLINKS (1U << 2) |
| 168 | #define NFS_CAP_ACLS (1U << 3) | 168 | #define NFS_CAP_ACLS (1U << 3) |
| 169 | #define NFS_CAP_ATOMIC_OPEN (1U << 4) | 169 | #define NFS_CAP_ATOMIC_OPEN (1U << 4) |
| 170 | #define NFS_CAP_CHANGE_ATTR (1U << 5) | ||
| 171 | #define NFS_CAP_FILEID (1U << 6) | ||
| 172 | #define NFS_CAP_MODE (1U << 7) | ||
| 173 | #define NFS_CAP_NLINK (1U << 8) | ||
| 174 | #define NFS_CAP_OWNER (1U << 9) | ||
| 175 | #define NFS_CAP_OWNER_GROUP (1U << 10) | ||
| 176 | #define NFS_CAP_ATIME (1U << 11) | ||
| 177 | #define NFS_CAP_CTIME (1U << 12) | ||
| 178 | #define NFS_CAP_MTIME (1U << 13) | ||
| 170 | 179 | ||
| 171 | 180 | ||
| 172 | /* maximum number of slots to use */ | 181 | /* maximum number of slots to use */ |
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index 2d8b211b9324..6f52b4d7c447 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h | |||
| @@ -59,6 +59,15 @@ struct cache_head { | |||
| 59 | 59 | ||
| 60 | #define CACHE_NEW_EXPIRY 120 /* keep new things pending confirmation for 120 seconds */ | 60 | #define CACHE_NEW_EXPIRY 120 /* keep new things pending confirmation for 120 seconds */ |
| 61 | 61 | ||
| 62 | struct cache_detail_procfs { | ||
| 63 | struct proc_dir_entry *proc_ent; | ||
| 64 | struct proc_dir_entry *flush_ent, *channel_ent, *content_ent; | ||
| 65 | }; | ||
| 66 | |||
| 67 | struct cache_detail_pipefs { | ||
| 68 | struct dentry *dir; | ||
| 69 | }; | ||
| 70 | |||
| 62 | struct cache_detail { | 71 | struct cache_detail { |
| 63 | struct module * owner; | 72 | struct module * owner; |
| 64 | int hash_size; | 73 | int hash_size; |
| @@ -70,15 +79,17 @@ struct cache_detail { | |||
| 70 | char *name; | 79 | char *name; |
| 71 | void (*cache_put)(struct kref *); | 80 | void (*cache_put)(struct kref *); |
| 72 | 81 | ||
| 73 | void (*cache_request)(struct cache_detail *cd, | 82 | int (*cache_upcall)(struct cache_detail *, |
| 74 | struct cache_head *h, | 83 | struct cache_head *); |
| 75 | char **bpp, int *blen); | 84 | |
| 76 | int (*cache_parse)(struct cache_detail *, | 85 | int (*cache_parse)(struct cache_detail *, |
| 77 | char *buf, int len); | 86 | char *buf, int len); |
| 78 | 87 | ||
| 79 | int (*cache_show)(struct seq_file *m, | 88 | int (*cache_show)(struct seq_file *m, |
| 80 | struct cache_detail *cd, | 89 | struct cache_detail *cd, |
| 81 | struct cache_head *h); | 90 | struct cache_head *h); |
| 91 | void (*warn_no_listener)(struct cache_detail *cd, | ||
| 92 | int has_died); | ||
| 82 | 93 | ||
| 83 | struct cache_head * (*alloc)(void); | 94 | struct cache_head * (*alloc)(void); |
| 84 | int (*match)(struct cache_head *orig, struct cache_head *new); | 95 | int (*match)(struct cache_head *orig, struct cache_head *new); |
| @@ -96,13 +107,15 @@ struct cache_detail { | |||
| 96 | 107 | ||
| 97 | /* fields for communication over channel */ | 108 | /* fields for communication over channel */ |
| 98 | struct list_head queue; | 109 | struct list_head queue; |
| 99 | struct proc_dir_entry *proc_ent; | ||
| 100 | struct proc_dir_entry *flush_ent, *channel_ent, *content_ent; | ||
| 101 | 110 | ||
| 102 | atomic_t readers; /* how many time is /chennel open */ | 111 | atomic_t readers; /* how many time is /chennel open */ |
| 103 | time_t last_close; /* if no readers, when did last close */ | 112 | time_t last_close; /* if no readers, when did last close */ |
| 104 | time_t last_warn; /* when we last warned about no readers */ | 113 | time_t last_warn; /* when we last warned about no readers */ |
| 105 | void (*warn_no_listener)(struct cache_detail *cd); | 114 | |
| 115 | union { | ||
| 116 | struct cache_detail_procfs procfs; | ||
| 117 | struct cache_detail_pipefs pipefs; | ||
| 118 | } u; | ||
| 106 | }; | 119 | }; |
| 107 | 120 | ||
| 108 | 121 | ||
| @@ -127,6 +140,10 @@ struct cache_deferred_req { | |||
| 127 | }; | 140 | }; |
| 128 | 141 | ||
| 129 | 142 | ||
| 143 | extern const struct file_operations cache_file_operations_pipefs; | ||
| 144 | extern const struct file_operations content_file_operations_pipefs; | ||
| 145 | extern const struct file_operations cache_flush_operations_pipefs; | ||
| 146 | |||
| 130 | extern struct cache_head * | 147 | extern struct cache_head * |
| 131 | sunrpc_cache_lookup(struct cache_detail *detail, | 148 | sunrpc_cache_lookup(struct cache_detail *detail, |
| 132 | struct cache_head *key, int hash); | 149 | struct cache_head *key, int hash); |
| @@ -134,6 +151,13 @@ extern struct cache_head * | |||
| 134 | sunrpc_cache_update(struct cache_detail *detail, | 151 | sunrpc_cache_update(struct cache_detail *detail, |
| 135 | struct cache_head *new, struct cache_head *old, int hash); | 152 | struct cache_head *new, struct cache_head *old, int hash); |
| 136 | 153 | ||
| 154 | extern int | ||
| 155 | sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h, | ||
| 156 | void (*cache_request)(struct cache_detail *, | ||
| 157 | struct cache_head *, | ||
| 158 | char **, | ||
| 159 | int *)); | ||
| 160 | |||
| 137 | 161 | ||
| 138 | extern void cache_clean_deferred(void *owner); | 162 | extern void cache_clean_deferred(void *owner); |
| 139 | 163 | ||
| @@ -171,6 +195,10 @@ extern void cache_purge(struct cache_detail *detail); | |||
| 171 | extern int cache_register(struct cache_detail *cd); | 195 | extern int cache_register(struct cache_detail *cd); |
| 172 | extern void cache_unregister(struct cache_detail *cd); | 196 | extern void cache_unregister(struct cache_detail *cd); |
| 173 | 197 | ||
| 198 | extern int sunrpc_cache_register_pipefs(struct dentry *parent, const char *, | ||
| 199 | mode_t, struct cache_detail *); | ||
| 200 | extern void sunrpc_cache_unregister_pipefs(struct cache_detail *); | ||
| 201 | |||
| 174 | extern void qword_add(char **bpp, int *lp, char *str); | 202 | extern void qword_add(char **bpp, int *lp, char *str); |
| 175 | extern void qword_addhex(char **bpp, int *lp, char *buf, int blen); | 203 | extern void qword_addhex(char **bpp, int *lp, char *buf, int blen); |
| 176 | extern int qword_get(char **bpp, char *dest, int bufsize); | 204 | extern int qword_get(char **bpp, char *dest, int bufsize); |
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h index 37881f1a0bd7..ab3f6e90caa5 100644 --- a/include/linux/sunrpc/clnt.h +++ b/include/linux/sunrpc/clnt.h | |||
| @@ -9,6 +9,10 @@ | |||
| 9 | #ifndef _LINUX_SUNRPC_CLNT_H | 9 | #ifndef _LINUX_SUNRPC_CLNT_H |
| 10 | #define _LINUX_SUNRPC_CLNT_H | 10 | #define _LINUX_SUNRPC_CLNT_H |
| 11 | 11 | ||
| 12 | #include <linux/socket.h> | ||
| 13 | #include <linux/in.h> | ||
| 14 | #include <linux/in6.h> | ||
| 15 | |||
| 12 | #include <linux/sunrpc/msg_prot.h> | 16 | #include <linux/sunrpc/msg_prot.h> |
| 13 | #include <linux/sunrpc/sched.h> | 17 | #include <linux/sunrpc/sched.h> |
| 14 | #include <linux/sunrpc/xprt.h> | 18 | #include <linux/sunrpc/xprt.h> |
| @@ -17,6 +21,7 @@ | |||
| 17 | #include <linux/sunrpc/xdr.h> | 21 | #include <linux/sunrpc/xdr.h> |
| 18 | #include <linux/sunrpc/timer.h> | 22 | #include <linux/sunrpc/timer.h> |
| 19 | #include <asm/signal.h> | 23 | #include <asm/signal.h> |
| 24 | #include <linux/path.h> | ||
| 20 | 25 | ||
| 21 | struct rpc_inode; | 26 | struct rpc_inode; |
| 22 | 27 | ||
| @@ -50,9 +55,7 @@ struct rpc_clnt { | |||
| 50 | 55 | ||
| 51 | int cl_nodelen; /* nodename length */ | 56 | int cl_nodelen; /* nodename length */ |
| 52 | char cl_nodename[UNX_MAXNODENAME]; | 57 | char cl_nodename[UNX_MAXNODENAME]; |
| 53 | char cl_pathname[30];/* Path in rpc_pipe_fs */ | 58 | struct path cl_path; |
| 54 | struct vfsmount * cl_vfsmnt; | ||
| 55 | struct dentry * cl_dentry; /* inode */ | ||
| 56 | struct rpc_clnt * cl_parent; /* Points to parent of clones */ | 59 | struct rpc_clnt * cl_parent; /* Points to parent of clones */ |
| 57 | struct rpc_rtt cl_rtt_default; | 60 | struct rpc_rtt cl_rtt_default; |
| 58 | struct rpc_timeout cl_timeout_default; | 61 | struct rpc_timeout cl_timeout_default; |
| @@ -151,5 +154,39 @@ void rpc_force_rebind(struct rpc_clnt *); | |||
| 151 | size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t); | 154 | size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t); |
| 152 | const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t); | 155 | const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t); |
| 153 | 156 | ||
| 157 | size_t rpc_ntop(const struct sockaddr *, char *, const size_t); | ||
| 158 | size_t rpc_pton(const char *, const size_t, | ||
| 159 | struct sockaddr *, const size_t); | ||
| 160 | char * rpc_sockaddr2uaddr(const struct sockaddr *); | ||
| 161 | size_t rpc_uaddr2sockaddr(const char *, const size_t, | ||
| 162 | struct sockaddr *, const size_t); | ||
| 163 | |||
| 164 | static inline unsigned short rpc_get_port(const struct sockaddr *sap) | ||
| 165 | { | ||
| 166 | switch (sap->sa_family) { | ||
| 167 | case AF_INET: | ||
| 168 | return ntohs(((struct sockaddr_in *)sap)->sin_port); | ||
| 169 | case AF_INET6: | ||
| 170 | return ntohs(((struct sockaddr_in6 *)sap)->sin6_port); | ||
| 171 | } | ||
| 172 | return 0; | ||
| 173 | } | ||
| 174 | |||
| 175 | static inline void rpc_set_port(struct sockaddr *sap, | ||
| 176 | const unsigned short port) | ||
| 177 | { | ||
| 178 | switch (sap->sa_family) { | ||
| 179 | case AF_INET: | ||
| 180 | ((struct sockaddr_in *)sap)->sin_port = htons(port); | ||
| 181 | break; | ||
| 182 | case AF_INET6: | ||
| 183 | ((struct sockaddr_in6 *)sap)->sin6_port = htons(port); | ||
| 184 | break; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | #define IPV6_SCOPE_DELIMITER '%' | ||
| 189 | #define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn") | ||
| 190 | |||
| 154 | #endif /* __KERNEL__ */ | 191 | #endif /* __KERNEL__ */ |
| 155 | #endif /* _LINUX_SUNRPC_CLNT_H */ | 192 | #endif /* _LINUX_SUNRPC_CLNT_H */ |
diff --git a/include/linux/sunrpc/msg_prot.h b/include/linux/sunrpc/msg_prot.h index 70df4f1d8847..77e624883393 100644 --- a/include/linux/sunrpc/msg_prot.h +++ b/include/linux/sunrpc/msg_prot.h | |||
| @@ -189,7 +189,22 @@ typedef __be32 rpc_fraghdr; | |||
| 189 | * Additionally, the two alternative forms specified in Section 2.2 of | 189 | * Additionally, the two alternative forms specified in Section 2.2 of |
| 190 | * [RFC2373] are also acceptable. | 190 | * [RFC2373] are also acceptable. |
| 191 | */ | 191 | */ |
| 192 | #define RPCBIND_MAXUADDRLEN (56u) | 192 | |
| 193 | #include <linux/inet.h> | ||
| 194 | |||
| 195 | /* Maximum size of the port number part of a universal address */ | ||
| 196 | #define RPCBIND_MAXUADDRPLEN sizeof(".255.255") | ||
| 197 | |||
| 198 | /* Maximum size of an IPv4 universal address */ | ||
| 199 | #define RPCBIND_MAXUADDR4LEN \ | ||
| 200 | (INET_ADDRSTRLEN + RPCBIND_MAXUADDRPLEN) | ||
| 201 | |||
| 202 | /* Maximum size of an IPv6 universal address */ | ||
| 203 | #define RPCBIND_MAXUADDR6LEN \ | ||
| 204 | (INET6_ADDRSTRLEN + RPCBIND_MAXUADDRPLEN) | ||
| 205 | |||
| 206 | /* Assume INET6_ADDRSTRLEN will always be larger than INET_ADDRSTRLEN... */ | ||
| 207 | #define RPCBIND_MAXUADDRLEN RPCBIND_MAXUADDR6LEN | ||
| 193 | 208 | ||
| 194 | #endif /* __KERNEL__ */ | 209 | #endif /* __KERNEL__ */ |
| 195 | #endif /* _LINUX_SUNRPC_MSGPROT_H_ */ | 210 | #endif /* _LINUX_SUNRPC_MSGPROT_H_ */ |
diff --git a/include/linux/sunrpc/rpc_pipe_fs.h b/include/linux/sunrpc/rpc_pipe_fs.h index cea764c2359f..a92571a34556 100644 --- a/include/linux/sunrpc/rpc_pipe_fs.h +++ b/include/linux/sunrpc/rpc_pipe_fs.h | |||
| @@ -32,8 +32,8 @@ struct rpc_inode { | |||
| 32 | wait_queue_head_t waitq; | 32 | wait_queue_head_t waitq; |
| 33 | #define RPC_PIPE_WAIT_FOR_OPEN 1 | 33 | #define RPC_PIPE_WAIT_FOR_OPEN 1 |
| 34 | int flags; | 34 | int flags; |
| 35 | struct rpc_pipe_ops *ops; | ||
| 36 | struct delayed_work queue_timeout; | 35 | struct delayed_work queue_timeout; |
| 36 | const struct rpc_pipe_ops *ops; | ||
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | static inline struct rpc_inode * | 39 | static inline struct rpc_inode * |
| @@ -44,9 +44,19 @@ RPC_I(struct inode *inode) | |||
| 44 | 44 | ||
| 45 | extern int rpc_queue_upcall(struct inode *, struct rpc_pipe_msg *); | 45 | extern int rpc_queue_upcall(struct inode *, struct rpc_pipe_msg *); |
| 46 | 46 | ||
| 47 | extern struct dentry *rpc_mkdir(char *, struct rpc_clnt *); | 47 | struct rpc_clnt; |
| 48 | extern int rpc_rmdir(struct dentry *); | 48 | extern struct dentry *rpc_create_client_dir(struct dentry *, struct qstr *, struct rpc_clnt *); |
| 49 | extern struct dentry *rpc_mkpipe(struct dentry *, const char *, void *, struct rpc_pipe_ops *, int flags); | 49 | extern int rpc_remove_client_dir(struct dentry *); |
| 50 | |||
| 51 | struct cache_detail; | ||
| 52 | extern struct dentry *rpc_create_cache_dir(struct dentry *, | ||
| 53 | struct qstr *, | ||
| 54 | mode_t umode, | ||
| 55 | struct cache_detail *); | ||
| 56 | extern void rpc_remove_cache_dir(struct dentry *); | ||
| 57 | |||
| 58 | extern struct dentry *rpc_mkpipe(struct dentry *, const char *, void *, | ||
| 59 | const struct rpc_pipe_ops *, int flags); | ||
| 50 | extern int rpc_unlink(struct dentry *); | 60 | extern int rpc_unlink(struct dentry *); |
| 51 | extern struct vfsmount *rpc_get_mount(void); | 61 | extern struct vfsmount *rpc_get_mount(void); |
| 52 | extern void rpc_put_mount(void); | 62 | extern void rpc_put_mount(void); |
diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h index 1175d58efc2e..c090df442572 100644 --- a/include/linux/sunrpc/xprt.h +++ b/include/linux/sunrpc/xprt.h | |||
| @@ -38,10 +38,8 @@ enum rpc_display_format_t { | |||
| 38 | RPC_DISPLAY_ADDR = 0, | 38 | RPC_DISPLAY_ADDR = 0, |
| 39 | RPC_DISPLAY_PORT, | 39 | RPC_DISPLAY_PORT, |
| 40 | RPC_DISPLAY_PROTO, | 40 | RPC_DISPLAY_PROTO, |
| 41 | RPC_DISPLAY_ALL, | ||
| 42 | RPC_DISPLAY_HEX_ADDR, | 41 | RPC_DISPLAY_HEX_ADDR, |
| 43 | RPC_DISPLAY_HEX_PORT, | 42 | RPC_DISPLAY_HEX_PORT, |
| 44 | RPC_DISPLAY_UNIVERSAL_ADDR, | ||
| 45 | RPC_DISPLAY_NETID, | 43 | RPC_DISPLAY_NETID, |
| 46 | RPC_DISPLAY_MAX, | 44 | RPC_DISPLAY_MAX, |
| 47 | }; | 45 | }; |
diff --git a/net/sunrpc/Makefile b/net/sunrpc/Makefile index db73fd2a3f0e..9d2fca5ad14a 100644 --- a/net/sunrpc/Makefile +++ b/net/sunrpc/Makefile | |||
| @@ -10,7 +10,7 @@ obj-$(CONFIG_SUNRPC_XPRT_RDMA) += xprtrdma/ | |||
| 10 | sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \ | 10 | sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \ |
| 11 | auth.o auth_null.o auth_unix.o auth_generic.o \ | 11 | auth.o auth_null.o auth_unix.o auth_generic.o \ |
| 12 | svc.o svcsock.o svcauth.o svcauth_unix.o \ | 12 | svc.o svcsock.o svcauth.o svcauth_unix.o \ |
| 13 | rpcb_clnt.o timer.o xdr.o \ | 13 | addr.o rpcb_clnt.o timer.o xdr.o \ |
| 14 | sunrpc_syms.o cache.o rpc_pipe.o \ | 14 | sunrpc_syms.o cache.o rpc_pipe.o \ |
| 15 | svc_xprt.o | 15 | svc_xprt.o |
| 16 | sunrpc-$(CONFIG_NFS_V4_1) += backchannel_rqst.o bc_svc.o | 16 | sunrpc-$(CONFIG_NFS_V4_1) += backchannel_rqst.o bc_svc.o |
diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c new file mode 100644 index 000000000000..22e8fd89477f --- /dev/null +++ b/net/sunrpc/addr.c | |||
| @@ -0,0 +1,364 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2009, Oracle. All rights reserved. | ||
| 3 | * | ||
| 4 | * Convert socket addresses to presentation addresses and universal | ||
| 5 | * addresses, and vice versa. | ||
| 6 | * | ||
| 7 | * Universal addresses are introduced by RFC 1833 and further refined by | ||
| 8 | * recent RFCs describing NFSv4. The universal address format is part | ||
| 9 | * of the external (network) interface provided by rpcbind version 3 | ||
| 10 | * and 4, and by NFSv4. Such an address is a string containing a | ||
| 11 | * presentation format IP address followed by a port number in | ||
| 12 | * "hibyte.lobyte" format. | ||
| 13 | * | ||
| 14 | * IPv6 addresses can also include a scope ID, typically denoted by | ||
| 15 | * a '%' followed by a device name or a non-negative integer. Refer to | ||
| 16 | * RFC 4291, Section 2.2 for details on IPv6 presentation formats. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <net/ipv6.h> | ||
| 20 | #include <linux/sunrpc/clnt.h> | ||
| 21 | |||
| 22 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
| 23 | |||
| 24 | static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap, | ||
| 25 | char *buf, const int buflen) | ||
| 26 | { | ||
| 27 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; | ||
| 28 | const struct in6_addr *addr = &sin6->sin6_addr; | ||
| 29 | |||
| 30 | /* | ||
| 31 | * RFC 4291, Section 2.2.2 | ||
| 32 | * | ||
| 33 | * Shorthanded ANY address | ||
| 34 | */ | ||
| 35 | if (ipv6_addr_any(addr)) | ||
| 36 | return snprintf(buf, buflen, "::"); | ||
| 37 | |||
| 38 | /* | ||
| 39 | * RFC 4291, Section 2.2.2 | ||
| 40 | * | ||
| 41 | * Shorthanded loopback address | ||
| 42 | */ | ||
| 43 | if (ipv6_addr_loopback(addr)) | ||
| 44 | return snprintf(buf, buflen, "::1"); | ||
| 45 | |||
| 46 | /* | ||
| 47 | * RFC 4291, Section 2.2.3 | ||
| 48 | * | ||
| 49 | * Special presentation address format for mapped v4 | ||
| 50 | * addresses. | ||
| 51 | */ | ||
| 52 | if (ipv6_addr_v4mapped(addr)) | ||
| 53 | return snprintf(buf, buflen, "::ffff:%pI4", | ||
| 54 | &addr->s6_addr32[3]); | ||
| 55 | |||
| 56 | /* | ||
| 57 | * RFC 4291, Section 2.2.1 | ||
| 58 | * | ||
| 59 | * To keep the result as short as possible, especially | ||
| 60 | * since we don't shorthand, we don't want leading zeros | ||
| 61 | * in each halfword, so avoid %pI6. | ||
| 62 | */ | ||
| 63 | return snprintf(buf, buflen, "%x:%x:%x:%x:%x:%x:%x:%x", | ||
| 64 | ntohs(addr->s6_addr16[0]), ntohs(addr->s6_addr16[1]), | ||
| 65 | ntohs(addr->s6_addr16[2]), ntohs(addr->s6_addr16[3]), | ||
| 66 | ntohs(addr->s6_addr16[4]), ntohs(addr->s6_addr16[5]), | ||
| 67 | ntohs(addr->s6_addr16[6]), ntohs(addr->s6_addr16[7])); | ||
| 68 | } | ||
| 69 | |||
| 70 | static size_t rpc_ntop6(const struct sockaddr *sap, | ||
| 71 | char *buf, const size_t buflen) | ||
| 72 | { | ||
| 73 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; | ||
| 74 | char scopebuf[IPV6_SCOPE_ID_LEN]; | ||
| 75 | size_t len; | ||
| 76 | int rc; | ||
| 77 | |||
| 78 | len = rpc_ntop6_noscopeid(sap, buf, buflen); | ||
| 79 | if (unlikely(len == 0)) | ||
| 80 | return len; | ||
| 81 | |||
| 82 | if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) && | ||
| 83 | !(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_SITELOCAL)) | ||
| 84 | return len; | ||
| 85 | |||
| 86 | rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u", | ||
| 87 | IPV6_SCOPE_DELIMITER, sin6->sin6_scope_id); | ||
| 88 | if (unlikely((size_t)rc > sizeof(scopebuf))) | ||
| 89 | return 0; | ||
| 90 | |||
| 91 | len += rc; | ||
| 92 | if (unlikely(len > buflen)) | ||
| 93 | return 0; | ||
| 94 | |||
| 95 | strcat(buf, scopebuf); | ||
| 96 | return len; | ||
| 97 | } | ||
| 98 | |||
| 99 | #else /* !(defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)) */ | ||
| 100 | |||
| 101 | static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap, | ||
| 102 | char *buf, const int buflen) | ||
| 103 | { | ||
| 104 | return 0; | ||
| 105 | } | ||
| 106 | |||
| 107 | static size_t rpc_ntop6(const struct sockaddr *sap, | ||
| 108 | char *buf, const size_t buflen) | ||
| 109 | { | ||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | #endif /* !(defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)) */ | ||
| 114 | |||
| 115 | static int rpc_ntop4(const struct sockaddr *sap, | ||
| 116 | char *buf, const size_t buflen) | ||
| 117 | { | ||
| 118 | const struct sockaddr_in *sin = (struct sockaddr_in *)sap; | ||
| 119 | |||
| 120 | return snprintf(buf, buflen, "%pI4", &sin->sin_addr); | ||
| 121 | } | ||
| 122 | |||
| 123 | /** | ||
| 124 | * rpc_ntop - construct a presentation address in @buf | ||
| 125 | * @sap: socket address | ||
| 126 | * @buf: construction area | ||
| 127 | * @buflen: size of @buf, in bytes | ||
| 128 | * | ||
| 129 | * Plants a %NUL-terminated string in @buf and returns the length | ||
| 130 | * of the string, excluding the %NUL. Otherwise zero is returned. | ||
| 131 | */ | ||
| 132 | size_t rpc_ntop(const struct sockaddr *sap, char *buf, const size_t buflen) | ||
| 133 | { | ||
| 134 | switch (sap->sa_family) { | ||
| 135 | case AF_INET: | ||
| 136 | return rpc_ntop4(sap, buf, buflen); | ||
| 137 | case AF_INET6: | ||
| 138 | return rpc_ntop6(sap, buf, buflen); | ||
| 139 | } | ||
| 140 | |||
| 141 | return 0; | ||
| 142 | } | ||
| 143 | EXPORT_SYMBOL_GPL(rpc_ntop); | ||
| 144 | |||
| 145 | static size_t rpc_pton4(const char *buf, const size_t buflen, | ||
| 146 | struct sockaddr *sap, const size_t salen) | ||
| 147 | { | ||
| 148 | struct sockaddr_in *sin = (struct sockaddr_in *)sap; | ||
| 149 | u8 *addr = (u8 *)&sin->sin_addr.s_addr; | ||
| 150 | |||
| 151 | if (buflen > INET_ADDRSTRLEN || salen < sizeof(struct sockaddr_in)) | ||
| 152 | return 0; | ||
| 153 | |||
| 154 | memset(sap, 0, sizeof(struct sockaddr_in)); | ||
| 155 | |||
| 156 | if (in4_pton(buf, buflen, addr, '\0', NULL) == 0) | ||
| 157 | return 0; | ||
| 158 | |||
| 159 | sin->sin_family = AF_INET; | ||
| 160 | return sizeof(struct sockaddr_in);; | ||
| 161 | } | ||
| 162 | |||
| 163 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
| 164 | static int rpc_parse_scope_id(const char *buf, const size_t buflen, | ||
| 165 | const char *delim, struct sockaddr_in6 *sin6) | ||
| 166 | { | ||
| 167 | char *p; | ||
| 168 | size_t len; | ||
| 169 | |||
| 170 | if ((buf + buflen) == delim) | ||
| 171 | return 1; | ||
| 172 | |||
| 173 | if (*delim != IPV6_SCOPE_DELIMITER) | ||
| 174 | return 0; | ||
| 175 | |||
| 176 | if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) && | ||
| 177 | !(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_SITELOCAL)) | ||
| 178 | return 0; | ||
| 179 | |||
| 180 | len = (buf + buflen) - delim - 1; | ||
| 181 | p = kstrndup(delim + 1, len, GFP_KERNEL); | ||
| 182 | if (p) { | ||
| 183 | unsigned long scope_id = 0; | ||
| 184 | struct net_device *dev; | ||
| 185 | |||
| 186 | dev = dev_get_by_name(&init_net, p); | ||
| 187 | if (dev != NULL) { | ||
| 188 | scope_id = dev->ifindex; | ||
| 189 | dev_put(dev); | ||
| 190 | } else { | ||
| 191 | if (strict_strtoul(p, 10, &scope_id) == 0) { | ||
| 192 | kfree(p); | ||
| 193 | return 0; | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | kfree(p); | ||
| 198 | |||
| 199 | sin6->sin6_scope_id = scope_id; | ||
| 200 | return 1; | ||
| 201 | } | ||
| 202 | |||
| 203 | return 0; | ||
| 204 | } | ||
| 205 | |||
| 206 | static size_t rpc_pton6(const char *buf, const size_t buflen, | ||
| 207 | struct sockaddr *sap, const size_t salen) | ||
| 208 | { | ||
| 209 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; | ||
| 210 | u8 *addr = (u8 *)&sin6->sin6_addr.in6_u; | ||
| 211 | const char *delim; | ||
| 212 | |||
| 213 | if (buflen > (INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN) || | ||
| 214 | salen < sizeof(struct sockaddr_in6)) | ||
| 215 | return 0; | ||
| 216 | |||
| 217 | memset(sap, 0, sizeof(struct sockaddr_in6)); | ||
| 218 | |||
| 219 | if (in6_pton(buf, buflen, addr, IPV6_SCOPE_DELIMITER, &delim) == 0) | ||
| 220 | return 0; | ||
| 221 | |||
| 222 | if (!rpc_parse_scope_id(buf, buflen, delim, sin6)) | ||
| 223 | return 0; | ||
| 224 | |||
| 225 | sin6->sin6_family = AF_INET6; | ||
| 226 | return sizeof(struct sockaddr_in6); | ||
| 227 | } | ||
| 228 | #else | ||
| 229 | static size_t rpc_pton6(const char *buf, const size_t buflen, | ||
| 230 | struct sockaddr *sap, const size_t salen) | ||
| 231 | { | ||
| 232 | return 0; | ||
| 233 | } | ||
| 234 | #endif | ||
| 235 | |||
| 236 | /** | ||
| 237 | * rpc_pton - Construct a sockaddr in @sap | ||
| 238 | * @buf: C string containing presentation format IP address | ||
| 239 | * @buflen: length of presentation address in bytes | ||
| 240 | * @sap: buffer into which to plant socket address | ||
| 241 | * @salen: size of buffer in bytes | ||
| 242 | * | ||
| 243 | * Returns the size of the socket address if successful; otherwise | ||
| 244 | * zero is returned. | ||
| 245 | * | ||
| 246 | * Plants a socket address in @sap and returns the size of the | ||
| 247 | * socket address, if successful. Returns zero if an error | ||
| 248 | * occurred. | ||
| 249 | */ | ||
| 250 | size_t rpc_pton(const char *buf, const size_t buflen, | ||
| 251 | struct sockaddr *sap, const size_t salen) | ||
| 252 | { | ||
| 253 | unsigned int i; | ||
| 254 | |||
| 255 | for (i = 0; i < buflen; i++) | ||
| 256 | if (buf[i] == ':') | ||
| 257 | return rpc_pton6(buf, buflen, sap, salen); | ||
| 258 | return rpc_pton4(buf, buflen, sap, salen); | ||
| 259 | } | ||
| 260 | EXPORT_SYMBOL_GPL(rpc_pton); | ||
| 261 | |||
| 262 | /** | ||
| 263 | * rpc_sockaddr2uaddr - Construct a universal address string from @sap. | ||
| 264 | * @sap: socket address | ||
| 265 | * | ||
| 266 | * Returns a %NUL-terminated string in dynamically allocated memory; | ||
| 267 | * otherwise NULL is returned if an error occurred. Caller must | ||
| 268 | * free the returned string. | ||
| 269 | */ | ||
| 270 | char *rpc_sockaddr2uaddr(const struct sockaddr *sap) | ||
| 271 | { | ||
| 272 | char portbuf[RPCBIND_MAXUADDRPLEN]; | ||
| 273 | char addrbuf[RPCBIND_MAXUADDRLEN]; | ||
| 274 | unsigned short port; | ||
| 275 | |||
| 276 | switch (sap->sa_family) { | ||
| 277 | case AF_INET: | ||
| 278 | if (rpc_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0) | ||
| 279 | return NULL; | ||
| 280 | port = ntohs(((struct sockaddr_in *)sap)->sin_port); | ||
| 281 | break; | ||
| 282 | case AF_INET6: | ||
| 283 | if (rpc_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0) | ||
| 284 | return NULL; | ||
| 285 | port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port); | ||
| 286 | break; | ||
| 287 | default: | ||
| 288 | return NULL; | ||
| 289 | } | ||
| 290 | |||
| 291 | if (snprintf(portbuf, sizeof(portbuf), | ||
| 292 | ".%u.%u", port >> 8, port & 0xff) > (int)sizeof(portbuf)) | ||
| 293 | return NULL; | ||
| 294 | |||
| 295 | if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) > sizeof(addrbuf)) | ||
| 296 | return NULL; | ||
| 297 | |||
| 298 | return kstrdup(addrbuf, GFP_KERNEL); | ||
| 299 | } | ||
| 300 | EXPORT_SYMBOL_GPL(rpc_sockaddr2uaddr); | ||
| 301 | |||
| 302 | /** | ||
| 303 | * rpc_uaddr2sockaddr - convert a universal address to a socket address. | ||
| 304 | * @uaddr: C string containing universal address to convert | ||
| 305 | * @uaddr_len: length of universal address string | ||
| 306 | * @sap: buffer into which to plant socket address | ||
| 307 | * @salen: size of buffer | ||
| 308 | * | ||
| 309 | * Returns the size of the socket address if successful; otherwise | ||
| 310 | * zero is returned. | ||
| 311 | */ | ||
| 312 | size_t rpc_uaddr2sockaddr(const char *uaddr, const size_t uaddr_len, | ||
| 313 | struct sockaddr *sap, const size_t salen) | ||
| 314 | { | ||
| 315 | char *c, buf[RPCBIND_MAXUADDRLEN]; | ||
| 316 | unsigned long portlo, porthi; | ||
| 317 | unsigned short port; | ||
| 318 | |||
| 319 | if (uaddr_len > sizeof(buf)) | ||
| 320 | return 0; | ||
| 321 | |||
| 322 | memcpy(buf, uaddr, uaddr_len); | ||
| 323 | |||
| 324 | buf[uaddr_len] = '\n'; | ||
| 325 | buf[uaddr_len + 1] = '\0'; | ||
| 326 | |||
| 327 | c = strrchr(buf, '.'); | ||
| 328 | if (unlikely(c == NULL)) | ||
| 329 | return 0; | ||
| 330 | if (unlikely(strict_strtoul(c + 1, 10, &portlo) != 0)) | ||
| 331 | return 0; | ||
| 332 | if (unlikely(portlo > 255)) | ||
| 333 | return 0; | ||
| 334 | |||
| 335 | c[0] = '\n'; | ||
| 336 | c[1] = '\0'; | ||
| 337 | |||
| 338 | c = strrchr(buf, '.'); | ||
| 339 | if (unlikely(c == NULL)) | ||
| 340 | return 0; | ||
| 341 | if (unlikely(strict_strtoul(c + 1, 10, &porthi) != 0)) | ||
| 342 | return 0; | ||
| 343 | if (unlikely(porthi > 255)) | ||
| 344 | return 0; | ||
| 345 | |||
| 346 | port = (unsigned short)((porthi << 8) | portlo); | ||
| 347 | |||
| 348 | c[0] = '\0'; | ||
| 349 | |||
| 350 | if (rpc_pton(buf, strlen(buf), sap, salen) == 0) | ||
| 351 | return 0; | ||
| 352 | |||
| 353 | switch (sap->sa_family) { | ||
| 354 | case AF_INET: | ||
| 355 | ((struct sockaddr_in *)sap)->sin_port = htons(port); | ||
| 356 | return sizeof(struct sockaddr_in); | ||
| 357 | case AF_INET6: | ||
| 358 | ((struct sockaddr_in6 *)sap)->sin6_port = htons(port); | ||
| 359 | return sizeof(struct sockaddr_in6); | ||
| 360 | } | ||
| 361 | |||
| 362 | return 0; | ||
| 363 | } | ||
| 364 | EXPORT_SYMBOL_GPL(rpc_uaddr2sockaddr); | ||
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c index 66d458fc6920..fc6a43ccd950 100644 --- a/net/sunrpc/auth_gss/auth_gss.c +++ b/net/sunrpc/auth_gss/auth_gss.c | |||
| @@ -89,8 +89,8 @@ static struct rpc_wait_queue pipe_version_rpc_waitqueue; | |||
| 89 | static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue); | 89 | static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue); |
| 90 | 90 | ||
| 91 | static void gss_free_ctx(struct gss_cl_ctx *); | 91 | static void gss_free_ctx(struct gss_cl_ctx *); |
| 92 | static struct rpc_pipe_ops gss_upcall_ops_v0; | 92 | static const struct rpc_pipe_ops gss_upcall_ops_v0; |
| 93 | static struct rpc_pipe_ops gss_upcall_ops_v1; | 93 | static const struct rpc_pipe_ops gss_upcall_ops_v1; |
| 94 | 94 | ||
| 95 | static inline struct gss_cl_ctx * | 95 | static inline struct gss_cl_ctx * |
| 96 | gss_get_ctx(struct gss_cl_ctx *ctx) | 96 | gss_get_ctx(struct gss_cl_ctx *ctx) |
| @@ -777,7 +777,7 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor) | |||
| 777 | * that we supported only the old pipe. So we instead create | 777 | * that we supported only the old pipe. So we instead create |
| 778 | * the new pipe first. | 778 | * the new pipe first. |
| 779 | */ | 779 | */ |
| 780 | gss_auth->dentry[1] = rpc_mkpipe(clnt->cl_dentry, | 780 | gss_auth->dentry[1] = rpc_mkpipe(clnt->cl_path.dentry, |
| 781 | "gssd", | 781 | "gssd", |
| 782 | clnt, &gss_upcall_ops_v1, | 782 | clnt, &gss_upcall_ops_v1, |
| 783 | RPC_PIPE_WAIT_FOR_OPEN); | 783 | RPC_PIPE_WAIT_FOR_OPEN); |
| @@ -786,7 +786,7 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor) | |||
| 786 | goto err_put_mech; | 786 | goto err_put_mech; |
| 787 | } | 787 | } |
| 788 | 788 | ||
| 789 | gss_auth->dentry[0] = rpc_mkpipe(clnt->cl_dentry, | 789 | gss_auth->dentry[0] = rpc_mkpipe(clnt->cl_path.dentry, |
| 790 | gss_auth->mech->gm_name, | 790 | gss_auth->mech->gm_name, |
| 791 | clnt, &gss_upcall_ops_v0, | 791 | clnt, &gss_upcall_ops_v0, |
| 792 | RPC_PIPE_WAIT_FOR_OPEN); | 792 | RPC_PIPE_WAIT_FOR_OPEN); |
| @@ -1507,7 +1507,7 @@ static const struct rpc_credops gss_nullops = { | |||
| 1507 | .crunwrap_resp = gss_unwrap_resp, | 1507 | .crunwrap_resp = gss_unwrap_resp, |
| 1508 | }; | 1508 | }; |
| 1509 | 1509 | ||
| 1510 | static struct rpc_pipe_ops gss_upcall_ops_v0 = { | 1510 | static const struct rpc_pipe_ops gss_upcall_ops_v0 = { |
| 1511 | .upcall = gss_pipe_upcall, | 1511 | .upcall = gss_pipe_upcall, |
| 1512 | .downcall = gss_pipe_downcall, | 1512 | .downcall = gss_pipe_downcall, |
| 1513 | .destroy_msg = gss_pipe_destroy_msg, | 1513 | .destroy_msg = gss_pipe_destroy_msg, |
| @@ -1515,7 +1515,7 @@ static struct rpc_pipe_ops gss_upcall_ops_v0 = { | |||
| 1515 | .release_pipe = gss_pipe_release, | 1515 | .release_pipe = gss_pipe_release, |
| 1516 | }; | 1516 | }; |
| 1517 | 1517 | ||
| 1518 | static struct rpc_pipe_ops gss_upcall_ops_v1 = { | 1518 | static const struct rpc_pipe_ops gss_upcall_ops_v1 = { |
| 1519 | .upcall = gss_pipe_upcall, | 1519 | .upcall = gss_pipe_upcall, |
| 1520 | .downcall = gss_pipe_downcall, | 1520 | .downcall = gss_pipe_downcall, |
| 1521 | .destroy_msg = gss_pipe_destroy_msg, | 1521 | .destroy_msg = gss_pipe_destroy_msg, |
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 2278a50c6444..2e6a148d277c 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c | |||
| @@ -181,6 +181,11 @@ static void rsi_request(struct cache_detail *cd, | |||
| 181 | (*bpp)[-1] = '\n'; | 181 | (*bpp)[-1] = '\n'; |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | static int rsi_upcall(struct cache_detail *cd, struct cache_head *h) | ||
| 185 | { | ||
| 186 | return sunrpc_cache_pipe_upcall(cd, h, rsi_request); | ||
| 187 | } | ||
| 188 | |||
| 184 | 189 | ||
| 185 | static int rsi_parse(struct cache_detail *cd, | 190 | static int rsi_parse(struct cache_detail *cd, |
| 186 | char *mesg, int mlen) | 191 | char *mesg, int mlen) |
| @@ -270,7 +275,7 @@ static struct cache_detail rsi_cache = { | |||
| 270 | .hash_table = rsi_table, | 275 | .hash_table = rsi_table, |
| 271 | .name = "auth.rpcsec.init", | 276 | .name = "auth.rpcsec.init", |
| 272 | .cache_put = rsi_put, | 277 | .cache_put = rsi_put, |
| 273 | .cache_request = rsi_request, | 278 | .cache_upcall = rsi_upcall, |
| 274 | .cache_parse = rsi_parse, | 279 | .cache_parse = rsi_parse, |
| 275 | .match = rsi_match, | 280 | .match = rsi_match, |
| 276 | .init = rsi_init, | 281 | .init = rsi_init, |
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index ff0c23053d2f..db7720e453c3 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c | |||
| @@ -27,10 +27,12 @@ | |||
| 27 | #include <linux/net.h> | 27 | #include <linux/net.h> |
| 28 | #include <linux/workqueue.h> | 28 | #include <linux/workqueue.h> |
| 29 | #include <linux/mutex.h> | 29 | #include <linux/mutex.h> |
| 30 | #include <linux/pagemap.h> | ||
| 30 | #include <asm/ioctls.h> | 31 | #include <asm/ioctls.h> |
| 31 | #include <linux/sunrpc/types.h> | 32 | #include <linux/sunrpc/types.h> |
| 32 | #include <linux/sunrpc/cache.h> | 33 | #include <linux/sunrpc/cache.h> |
| 33 | #include <linux/sunrpc/stats.h> | 34 | #include <linux/sunrpc/stats.h> |
| 35 | #include <linux/sunrpc/rpc_pipe_fs.h> | ||
| 34 | 36 | ||
| 35 | #define RPCDBG_FACILITY RPCDBG_CACHE | 37 | #define RPCDBG_FACILITY RPCDBG_CACHE |
| 36 | 38 | ||
| @@ -175,7 +177,13 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail, | |||
| 175 | } | 177 | } |
| 176 | EXPORT_SYMBOL_GPL(sunrpc_cache_update); | 178 | EXPORT_SYMBOL_GPL(sunrpc_cache_update); |
| 177 | 179 | ||
| 178 | static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h); | 180 | static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h) |
| 181 | { | ||
| 182 | if (!cd->cache_upcall) | ||
| 183 | return -EINVAL; | ||
| 184 | return cd->cache_upcall(cd, h); | ||
| 185 | } | ||
| 186 | |||
| 179 | /* | 187 | /* |
| 180 | * This is the generic cache management routine for all | 188 | * This is the generic cache management routine for all |
| 181 | * the authentication caches. | 189 | * the authentication caches. |
| @@ -284,76 +292,11 @@ static DEFINE_SPINLOCK(cache_list_lock); | |||
| 284 | static struct cache_detail *current_detail; | 292 | static struct cache_detail *current_detail; |
| 285 | static int current_index; | 293 | static int current_index; |
| 286 | 294 | ||
| 287 | static const struct file_operations cache_file_operations; | ||
| 288 | static const struct file_operations content_file_operations; | ||
| 289 | static const struct file_operations cache_flush_operations; | ||
| 290 | |||
| 291 | static void do_cache_clean(struct work_struct *work); | 295 | static void do_cache_clean(struct work_struct *work); |
| 292 | static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean); | 296 | static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean); |
| 293 | 297 | ||
| 294 | static void remove_cache_proc_entries(struct cache_detail *cd) | 298 | static void sunrpc_init_cache_detail(struct cache_detail *cd) |
| 295 | { | ||
| 296 | if (cd->proc_ent == NULL) | ||
| 297 | return; | ||
| 298 | if (cd->flush_ent) | ||
| 299 | remove_proc_entry("flush", cd->proc_ent); | ||
| 300 | if (cd->channel_ent) | ||
| 301 | remove_proc_entry("channel", cd->proc_ent); | ||
| 302 | if (cd->content_ent) | ||
| 303 | remove_proc_entry("content", cd->proc_ent); | ||
| 304 | cd->proc_ent = NULL; | ||
| 305 | remove_proc_entry(cd->name, proc_net_rpc); | ||
| 306 | } | ||
| 307 | |||
| 308 | #ifdef CONFIG_PROC_FS | ||
| 309 | static int create_cache_proc_entries(struct cache_detail *cd) | ||
| 310 | { | ||
| 311 | struct proc_dir_entry *p; | ||
| 312 | |||
| 313 | cd->proc_ent = proc_mkdir(cd->name, proc_net_rpc); | ||
| 314 | if (cd->proc_ent == NULL) | ||
| 315 | goto out_nomem; | ||
| 316 | cd->channel_ent = cd->content_ent = NULL; | ||
| 317 | |||
| 318 | p = proc_create_data("flush", S_IFREG|S_IRUSR|S_IWUSR, | ||
| 319 | cd->proc_ent, &cache_flush_operations, cd); | ||
| 320 | cd->flush_ent = p; | ||
| 321 | if (p == NULL) | ||
| 322 | goto out_nomem; | ||
| 323 | |||
| 324 | if (cd->cache_request || cd->cache_parse) { | ||
| 325 | p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR, | ||
| 326 | cd->proc_ent, &cache_file_operations, cd); | ||
| 327 | cd->channel_ent = p; | ||
| 328 | if (p == NULL) | ||
| 329 | goto out_nomem; | ||
| 330 | } | ||
| 331 | if (cd->cache_show) { | ||
| 332 | p = proc_create_data("content", S_IFREG|S_IRUSR|S_IWUSR, | ||
| 333 | cd->proc_ent, &content_file_operations, cd); | ||
| 334 | cd->content_ent = p; | ||
| 335 | if (p == NULL) | ||
| 336 | goto out_nomem; | ||
| 337 | } | ||
| 338 | return 0; | ||
| 339 | out_nomem: | ||
| 340 | remove_cache_proc_entries(cd); | ||
| 341 | return -ENOMEM; | ||
| 342 | } | ||
| 343 | #else /* CONFIG_PROC_FS */ | ||
| 344 | static int create_cache_proc_entries(struct cache_detail *cd) | ||
| 345 | { | ||
| 346 | return 0; | ||
| 347 | } | ||
| 348 | #endif | ||
| 349 | |||
| 350 | int cache_register(struct cache_detail *cd) | ||
| 351 | { | 299 | { |
| 352 | int ret; | ||
| 353 | |||
| 354 | ret = create_cache_proc_entries(cd); | ||
| 355 | if (ret) | ||
| 356 | return ret; | ||
| 357 | rwlock_init(&cd->hash_lock); | 300 | rwlock_init(&cd->hash_lock); |
| 358 | INIT_LIST_HEAD(&cd->queue); | 301 | INIT_LIST_HEAD(&cd->queue); |
| 359 | spin_lock(&cache_list_lock); | 302 | spin_lock(&cache_list_lock); |
| @@ -367,11 +310,9 @@ int cache_register(struct cache_detail *cd) | |||
| 367 | 310 | ||
| 368 | /* start the cleaning process */ | 311 | /* start the cleaning process */ |
| 369 | schedule_delayed_work(&cache_cleaner, 0); | 312 | schedule_delayed_work(&cache_cleaner, 0); |
| 370 | return 0; | ||
| 371 | } | 313 | } |
| 372 | EXPORT_SYMBOL_GPL(cache_register); | ||
| 373 | 314 | ||
| 374 | void cache_unregister(struct cache_detail *cd) | 315 | static void sunrpc_destroy_cache_detail(struct cache_detail *cd) |
| 375 | { | 316 | { |
| 376 | cache_purge(cd); | 317 | cache_purge(cd); |
| 377 | spin_lock(&cache_list_lock); | 318 | spin_lock(&cache_list_lock); |
| @@ -386,7 +327,6 @@ void cache_unregister(struct cache_detail *cd) | |||
| 386 | list_del_init(&cd->others); | 327 | list_del_init(&cd->others); |
| 387 | write_unlock(&cd->hash_lock); | 328 | write_unlock(&cd->hash_lock); |
| 388 | spin_unlock(&cache_list_lock); | 329 | spin_unlock(&cache_list_lock); |
| 389 | remove_cache_proc_entries(cd); | ||
| 390 | if (list_empty(&cache_list)) { | 330 | if (list_empty(&cache_list)) { |
| 391 | /* module must be being unloaded so its safe to kill the worker */ | 331 | /* module must be being unloaded so its safe to kill the worker */ |
| 392 | cancel_delayed_work_sync(&cache_cleaner); | 332 | cancel_delayed_work_sync(&cache_cleaner); |
| @@ -395,7 +335,6 @@ void cache_unregister(struct cache_detail *cd) | |||
| 395 | out: | 335 | out: |
| 396 | printk(KERN_ERR "nfsd: failed to unregister %s cache\n", cd->name); | 336 | printk(KERN_ERR "nfsd: failed to unregister %s cache\n", cd->name); |
| 397 | } | 337 | } |
| 398 | EXPORT_SYMBOL_GPL(cache_unregister); | ||
| 399 | 338 | ||
| 400 | /* clean cache tries to find something to clean | 339 | /* clean cache tries to find something to clean |
| 401 | * and cleans it. | 340 | * and cleans it. |
| @@ -687,18 +626,18 @@ struct cache_reader { | |||
| 687 | int offset; /* if non-0, we have a refcnt on next request */ | 626 | int offset; /* if non-0, we have a refcnt on next request */ |
| 688 | }; | 627 | }; |
| 689 | 628 | ||
| 690 | static ssize_t | 629 | static ssize_t cache_read(struct file *filp, char __user *buf, size_t count, |
| 691 | cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) | 630 | loff_t *ppos, struct cache_detail *cd) |
| 692 | { | 631 | { |
| 693 | struct cache_reader *rp = filp->private_data; | 632 | struct cache_reader *rp = filp->private_data; |
| 694 | struct cache_request *rq; | 633 | struct cache_request *rq; |
| 695 | struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; | 634 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 696 | int err; | 635 | int err; |
| 697 | 636 | ||
| 698 | if (count == 0) | 637 | if (count == 0) |
| 699 | return 0; | 638 | return 0; |
| 700 | 639 | ||
| 701 | mutex_lock(&queue_io_mutex); /* protect against multiple concurrent | 640 | mutex_lock(&inode->i_mutex); /* protect against multiple concurrent |
| 702 | * readers on this file */ | 641 | * readers on this file */ |
| 703 | again: | 642 | again: |
| 704 | spin_lock(&queue_lock); | 643 | spin_lock(&queue_lock); |
| @@ -711,7 +650,7 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) | |||
| 711 | } | 650 | } |
| 712 | if (rp->q.list.next == &cd->queue) { | 651 | if (rp->q.list.next == &cd->queue) { |
| 713 | spin_unlock(&queue_lock); | 652 | spin_unlock(&queue_lock); |
| 714 | mutex_unlock(&queue_io_mutex); | 653 | mutex_unlock(&inode->i_mutex); |
| 715 | BUG_ON(rp->offset); | 654 | BUG_ON(rp->offset); |
| 716 | return 0; | 655 | return 0; |
| 717 | } | 656 | } |
| @@ -758,49 +697,90 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) | |||
| 758 | } | 697 | } |
| 759 | if (err == -EAGAIN) | 698 | if (err == -EAGAIN) |
| 760 | goto again; | 699 | goto again; |
| 761 | mutex_unlock(&queue_io_mutex); | 700 | mutex_unlock(&inode->i_mutex); |
| 762 | return err ? err : count; | 701 | return err ? err : count; |
| 763 | } | 702 | } |
| 764 | 703 | ||
| 765 | static char write_buf[8192]; /* protected by queue_io_mutex */ | 704 | static ssize_t cache_do_downcall(char *kaddr, const char __user *buf, |
| 705 | size_t count, struct cache_detail *cd) | ||
| 706 | { | ||
| 707 | ssize_t ret; | ||
| 708 | |||
| 709 | if (copy_from_user(kaddr, buf, count)) | ||
| 710 | return -EFAULT; | ||
| 711 | kaddr[count] = '\0'; | ||
| 712 | ret = cd->cache_parse(cd, kaddr, count); | ||
| 713 | if (!ret) | ||
| 714 | ret = count; | ||
| 715 | return ret; | ||
| 716 | } | ||
| 766 | 717 | ||
| 767 | static ssize_t | 718 | static ssize_t cache_slow_downcall(const char __user *buf, |
| 768 | cache_write(struct file *filp, const char __user *buf, size_t count, | 719 | size_t count, struct cache_detail *cd) |
| 769 | loff_t *ppos) | ||
| 770 | { | 720 | { |
| 771 | int err; | 721 | static char write_buf[8192]; /* protected by queue_io_mutex */ |
| 772 | struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; | 722 | ssize_t ret = -EINVAL; |
| 773 | 723 | ||
| 774 | if (count == 0) | ||
| 775 | return 0; | ||
| 776 | if (count >= sizeof(write_buf)) | 724 | if (count >= sizeof(write_buf)) |
| 777 | return -EINVAL; | 725 | goto out; |
| 778 | |||
| 779 | mutex_lock(&queue_io_mutex); | 726 | mutex_lock(&queue_io_mutex); |
| 727 | ret = cache_do_downcall(write_buf, buf, count, cd); | ||
| 728 | mutex_unlock(&queue_io_mutex); | ||
| 729 | out: | ||
| 730 | return ret; | ||
| 731 | } | ||
| 780 | 732 | ||
| 781 | if (copy_from_user(write_buf, buf, count)) { | 733 | static ssize_t cache_downcall(struct address_space *mapping, |
| 782 | mutex_unlock(&queue_io_mutex); | 734 | const char __user *buf, |
| 783 | return -EFAULT; | 735 | size_t count, struct cache_detail *cd) |
| 784 | } | 736 | { |
| 785 | write_buf[count] = '\0'; | 737 | struct page *page; |
| 786 | if (cd->cache_parse) | 738 | char *kaddr; |
| 787 | err = cd->cache_parse(cd, write_buf, count); | 739 | ssize_t ret = -ENOMEM; |
| 788 | else | 740 | |
| 789 | err = -EINVAL; | 741 | if (count >= PAGE_CACHE_SIZE) |
| 742 | goto out_slow; | ||
| 743 | |||
| 744 | page = find_or_create_page(mapping, 0, GFP_KERNEL); | ||
| 745 | if (!page) | ||
| 746 | goto out_slow; | ||
| 747 | |||
| 748 | kaddr = kmap(page); | ||
| 749 | ret = cache_do_downcall(kaddr, buf, count, cd); | ||
| 750 | kunmap(page); | ||
| 751 | unlock_page(page); | ||
| 752 | page_cache_release(page); | ||
| 753 | return ret; | ||
| 754 | out_slow: | ||
| 755 | return cache_slow_downcall(buf, count, cd); | ||
| 756 | } | ||
| 790 | 757 | ||
| 791 | mutex_unlock(&queue_io_mutex); | 758 | static ssize_t cache_write(struct file *filp, const char __user *buf, |
| 792 | return err ? err : count; | 759 | size_t count, loff_t *ppos, |
| 760 | struct cache_detail *cd) | ||
| 761 | { | ||
| 762 | struct address_space *mapping = filp->f_mapping; | ||
| 763 | struct inode *inode = filp->f_path.dentry->d_inode; | ||
| 764 | ssize_t ret = -EINVAL; | ||
| 765 | |||
| 766 | if (!cd->cache_parse) | ||
| 767 | goto out; | ||
| 768 | |||
| 769 | mutex_lock(&inode->i_mutex); | ||
| 770 | ret = cache_downcall(mapping, buf, count, cd); | ||
| 771 | mutex_unlock(&inode->i_mutex); | ||
| 772 | out: | ||
| 773 | return ret; | ||
| 793 | } | 774 | } |
| 794 | 775 | ||
| 795 | static DECLARE_WAIT_QUEUE_HEAD(queue_wait); | 776 | static DECLARE_WAIT_QUEUE_HEAD(queue_wait); |
| 796 | 777 | ||
| 797 | static unsigned int | 778 | static unsigned int cache_poll(struct file *filp, poll_table *wait, |
| 798 | cache_poll(struct file *filp, poll_table *wait) | 779 | struct cache_detail *cd) |
| 799 | { | 780 | { |
| 800 | unsigned int mask; | 781 | unsigned int mask; |
| 801 | struct cache_reader *rp = filp->private_data; | 782 | struct cache_reader *rp = filp->private_data; |
| 802 | struct cache_queue *cq; | 783 | struct cache_queue *cq; |
| 803 | struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; | ||
| 804 | 784 | ||
| 805 | poll_wait(filp, &queue_wait, wait); | 785 | poll_wait(filp, &queue_wait, wait); |
| 806 | 786 | ||
| @@ -822,14 +802,13 @@ cache_poll(struct file *filp, poll_table *wait) | |||
| 822 | return mask; | 802 | return mask; |
| 823 | } | 803 | } |
| 824 | 804 | ||
| 825 | static int | 805 | static int cache_ioctl(struct inode *ino, struct file *filp, |
| 826 | cache_ioctl(struct inode *ino, struct file *filp, | 806 | unsigned int cmd, unsigned long arg, |
| 827 | unsigned int cmd, unsigned long arg) | 807 | struct cache_detail *cd) |
| 828 | { | 808 | { |
| 829 | int len = 0; | 809 | int len = 0; |
| 830 | struct cache_reader *rp = filp->private_data; | 810 | struct cache_reader *rp = filp->private_data; |
| 831 | struct cache_queue *cq; | 811 | struct cache_queue *cq; |
| 832 | struct cache_detail *cd = PDE(ino)->data; | ||
| 833 | 812 | ||
| 834 | if (cmd != FIONREAD || !rp) | 813 | if (cmd != FIONREAD || !rp) |
| 835 | return -EINVAL; | 814 | return -EINVAL; |
| @@ -852,15 +831,13 @@ cache_ioctl(struct inode *ino, struct file *filp, | |||
| 852 | return put_user(len, (int __user *)arg); | 831 | return put_user(len, (int __user *)arg); |
| 853 | } | 832 | } |
| 854 | 833 | ||
| 855 | static int | 834 | static int cache_open(struct inode *inode, struct file *filp, |
| 856 | cache_open(struct inode *inode, struct file *filp) | 835 | struct cache_detail *cd) |
| 857 | { | 836 | { |
| 858 | struct cache_reader *rp = NULL; | 837 | struct cache_reader *rp = NULL; |
| 859 | 838 | ||
| 860 | nonseekable_open(inode, filp); | 839 | nonseekable_open(inode, filp); |
| 861 | if (filp->f_mode & FMODE_READ) { | 840 | if (filp->f_mode & FMODE_READ) { |
| 862 | struct cache_detail *cd = PDE(inode)->data; | ||
| 863 | |||
| 864 | rp = kmalloc(sizeof(*rp), GFP_KERNEL); | 841 | rp = kmalloc(sizeof(*rp), GFP_KERNEL); |
| 865 | if (!rp) | 842 | if (!rp) |
| 866 | return -ENOMEM; | 843 | return -ENOMEM; |
| @@ -875,11 +852,10 @@ cache_open(struct inode *inode, struct file *filp) | |||
| 875 | return 0; | 852 | return 0; |
| 876 | } | 853 | } |
| 877 | 854 | ||
| 878 | static int | 855 | static int cache_release(struct inode *inode, struct file *filp, |
| 879 | cache_release(struct inode *inode, struct file *filp) | 856 | struct cache_detail *cd) |
| 880 | { | 857 | { |
| 881 | struct cache_reader *rp = filp->private_data; | 858 | struct cache_reader *rp = filp->private_data; |
| 882 | struct cache_detail *cd = PDE(inode)->data; | ||
| 883 | 859 | ||
| 884 | if (rp) { | 860 | if (rp) { |
| 885 | spin_lock(&queue_lock); | 861 | spin_lock(&queue_lock); |
| @@ -908,18 +884,6 @@ cache_release(struct inode *inode, struct file *filp) | |||
| 908 | 884 | ||
| 909 | 885 | ||
| 910 | 886 | ||
| 911 | static const struct file_operations cache_file_operations = { | ||
| 912 | .owner = THIS_MODULE, | ||
| 913 | .llseek = no_llseek, | ||
| 914 | .read = cache_read, | ||
| 915 | .write = cache_write, | ||
| 916 | .poll = cache_poll, | ||
| 917 | .ioctl = cache_ioctl, /* for FIONREAD */ | ||
| 918 | .open = cache_open, | ||
| 919 | .release = cache_release, | ||
| 920 | }; | ||
| 921 | |||
| 922 | |||
| 923 | static void queue_loose(struct cache_detail *detail, struct cache_head *ch) | 887 | static void queue_loose(struct cache_detail *detail, struct cache_head *ch) |
| 924 | { | 888 | { |
| 925 | struct cache_queue *cq; | 889 | struct cache_queue *cq; |
| @@ -1020,15 +984,21 @@ static void warn_no_listener(struct cache_detail *detail) | |||
| 1020 | if (detail->last_warn != detail->last_close) { | 984 | if (detail->last_warn != detail->last_close) { |
| 1021 | detail->last_warn = detail->last_close; | 985 | detail->last_warn = detail->last_close; |
| 1022 | if (detail->warn_no_listener) | 986 | if (detail->warn_no_listener) |
| 1023 | detail->warn_no_listener(detail); | 987 | detail->warn_no_listener(detail, detail->last_close != 0); |
| 1024 | } | 988 | } |
| 1025 | } | 989 | } |
| 1026 | 990 | ||
| 1027 | /* | 991 | /* |
| 1028 | * register an upcall request to user-space. | 992 | * register an upcall request to user-space and queue it up for read() by the |
| 993 | * upcall daemon. | ||
| 994 | * | ||
| 1029 | * Each request is at most one page long. | 995 | * Each request is at most one page long. |
| 1030 | */ | 996 | */ |
| 1031 | static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h) | 997 | int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h, |
| 998 | void (*cache_request)(struct cache_detail *, | ||
| 999 | struct cache_head *, | ||
| 1000 | char **, | ||
| 1001 | int *)) | ||
| 1032 | { | 1002 | { |
| 1033 | 1003 | ||
| 1034 | char *buf; | 1004 | char *buf; |
| @@ -1036,9 +1006,6 @@ static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h) | |||
| 1036 | char *bp; | 1006 | char *bp; |
| 1037 | int len; | 1007 | int len; |
| 1038 | 1008 | ||
| 1039 | if (detail->cache_request == NULL) | ||
| 1040 | return -EINVAL; | ||
| 1041 | |||
| 1042 | if (atomic_read(&detail->readers) == 0 && | 1009 | if (atomic_read(&detail->readers) == 0 && |
| 1043 | detail->last_close < get_seconds() - 30) { | 1010 | detail->last_close < get_seconds() - 30) { |
| 1044 | warn_no_listener(detail); | 1011 | warn_no_listener(detail); |
| @@ -1057,7 +1024,7 @@ static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h) | |||
| 1057 | 1024 | ||
| 1058 | bp = buf; len = PAGE_SIZE; | 1025 | bp = buf; len = PAGE_SIZE; |
| 1059 | 1026 | ||
| 1060 | detail->cache_request(detail, h, &bp, &len); | 1027 | cache_request(detail, h, &bp, &len); |
| 1061 | 1028 | ||
| 1062 | if (len < 0) { | 1029 | if (len < 0) { |
| 1063 | kfree(buf); | 1030 | kfree(buf); |
| @@ -1075,6 +1042,7 @@ static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h) | |||
| 1075 | wake_up(&queue_wait); | 1042 | wake_up(&queue_wait); |
| 1076 | return 0; | 1043 | return 0; |
| 1077 | } | 1044 | } |
| 1045 | EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall); | ||
| 1078 | 1046 | ||
| 1079 | /* | 1047 | /* |
| 1080 | * parse a message from user-space and pass it | 1048 | * parse a message from user-space and pass it |
| @@ -1242,10 +1210,10 @@ static const struct seq_operations cache_content_op = { | |||
| 1242 | .show = c_show, | 1210 | .show = c_show, |
| 1243 | }; | 1211 | }; |
| 1244 | 1212 | ||
| 1245 | static int content_open(struct inode *inode, struct file *file) | 1213 | static int content_open(struct inode *inode, struct file *file, |
| 1214 | struct cache_detail *cd) | ||
| 1246 | { | 1215 | { |
| 1247 | struct handle *han; | 1216 | struct handle *han; |
| 1248 | struct cache_detail *cd = PDE(inode)->data; | ||
| 1249 | 1217 | ||
| 1250 | han = __seq_open_private(file, &cache_content_op, sizeof(*han)); | 1218 | han = __seq_open_private(file, &cache_content_op, sizeof(*han)); |
| 1251 | if (han == NULL) | 1219 | if (han == NULL) |
| @@ -1255,17 +1223,10 @@ static int content_open(struct inode *inode, struct file *file) | |||
| 1255 | return 0; | 1223 | return 0; |
| 1256 | } | 1224 | } |
| 1257 | 1225 | ||
| 1258 | static const struct file_operations content_file_operations = { | ||
| 1259 | .open = content_open, | ||
| 1260 | .read = seq_read, | ||
| 1261 | .llseek = seq_lseek, | ||
| 1262 | .release = seq_release_private, | ||
| 1263 | }; | ||
| 1264 | |||
| 1265 | static ssize_t read_flush(struct file *file, char __user *buf, | 1226 | static ssize_t read_flush(struct file *file, char __user *buf, |
| 1266 | size_t count, loff_t *ppos) | 1227 | size_t count, loff_t *ppos, |
| 1228 | struct cache_detail *cd) | ||
| 1267 | { | 1229 | { |
| 1268 | struct cache_detail *cd = PDE(file->f_path.dentry->d_inode)->data; | ||
| 1269 | char tbuf[20]; | 1230 | char tbuf[20]; |
| 1270 | unsigned long p = *ppos; | 1231 | unsigned long p = *ppos; |
| 1271 | size_t len; | 1232 | size_t len; |
| @@ -1283,10 +1244,10 @@ static ssize_t read_flush(struct file *file, char __user *buf, | |||
| 1283 | return len; | 1244 | return len; |
| 1284 | } | 1245 | } |
| 1285 | 1246 | ||
| 1286 | static ssize_t write_flush(struct file * file, const char __user * buf, | 1247 | static ssize_t write_flush(struct file *file, const char __user *buf, |
| 1287 | size_t count, loff_t *ppos) | 1248 | size_t count, loff_t *ppos, |
| 1249 | struct cache_detail *cd) | ||
| 1288 | { | 1250 | { |
| 1289 | struct cache_detail *cd = PDE(file->f_path.dentry->d_inode)->data; | ||
| 1290 | char tbuf[20]; | 1251 | char tbuf[20]; |
| 1291 | char *ep; | 1252 | char *ep; |
| 1292 | long flushtime; | 1253 | long flushtime; |
| @@ -1307,8 +1268,299 @@ static ssize_t write_flush(struct file * file, const char __user * buf, | |||
| 1307 | return count; | 1268 | return count; |
| 1308 | } | 1269 | } |
| 1309 | 1270 | ||
| 1310 | static const struct file_operations cache_flush_operations = { | 1271 | static ssize_t cache_read_procfs(struct file *filp, char __user *buf, |
| 1272 | size_t count, loff_t *ppos) | ||
| 1273 | { | ||
| 1274 | struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; | ||
| 1275 | |||
| 1276 | return cache_read(filp, buf, count, ppos, cd); | ||
| 1277 | } | ||
| 1278 | |||
| 1279 | static ssize_t cache_write_procfs(struct file *filp, const char __user *buf, | ||
| 1280 | size_t count, loff_t *ppos) | ||
| 1281 | { | ||
| 1282 | struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; | ||
| 1283 | |||
| 1284 | return cache_write(filp, buf, count, ppos, cd); | ||
| 1285 | } | ||
| 1286 | |||
| 1287 | static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait) | ||
| 1288 | { | ||
| 1289 | struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; | ||
| 1290 | |||
| 1291 | return cache_poll(filp, wait, cd); | ||
| 1292 | } | ||
| 1293 | |||
| 1294 | static int cache_ioctl_procfs(struct inode *inode, struct file *filp, | ||
| 1295 | unsigned int cmd, unsigned long arg) | ||
| 1296 | { | ||
| 1297 | struct cache_detail *cd = PDE(inode)->data; | ||
| 1298 | |||
| 1299 | return cache_ioctl(inode, filp, cmd, arg, cd); | ||
| 1300 | } | ||
| 1301 | |||
| 1302 | static int cache_open_procfs(struct inode *inode, struct file *filp) | ||
| 1303 | { | ||
| 1304 | struct cache_detail *cd = PDE(inode)->data; | ||
| 1305 | |||
| 1306 | return cache_open(inode, filp, cd); | ||
| 1307 | } | ||
| 1308 | |||
| 1309 | static int cache_release_procfs(struct inode *inode, struct file *filp) | ||
| 1310 | { | ||
| 1311 | struct cache_detail *cd = PDE(inode)->data; | ||
| 1312 | |||
| 1313 | return cache_release(inode, filp, cd); | ||
| 1314 | } | ||
| 1315 | |||
| 1316 | static const struct file_operations cache_file_operations_procfs = { | ||
| 1317 | .owner = THIS_MODULE, | ||
| 1318 | .llseek = no_llseek, | ||
| 1319 | .read = cache_read_procfs, | ||
| 1320 | .write = cache_write_procfs, | ||
| 1321 | .poll = cache_poll_procfs, | ||
| 1322 | .ioctl = cache_ioctl_procfs, /* for FIONREAD */ | ||
| 1323 | .open = cache_open_procfs, | ||
| 1324 | .release = cache_release_procfs, | ||
| 1325 | }; | ||
| 1326 | |||
| 1327 | static int content_open_procfs(struct inode *inode, struct file *filp) | ||
| 1328 | { | ||
| 1329 | struct cache_detail *cd = PDE(inode)->data; | ||
| 1330 | |||
| 1331 | return content_open(inode, filp, cd); | ||
| 1332 | } | ||
| 1333 | |||
| 1334 | static const struct file_operations content_file_operations_procfs = { | ||
| 1335 | .open = content_open_procfs, | ||
| 1336 | .read = seq_read, | ||
| 1337 | .llseek = seq_lseek, | ||
| 1338 | .release = seq_release_private, | ||
| 1339 | }; | ||
| 1340 | |||
| 1341 | static ssize_t read_flush_procfs(struct file *filp, char __user *buf, | ||
| 1342 | size_t count, loff_t *ppos) | ||
| 1343 | { | ||
| 1344 | struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; | ||
| 1345 | |||
| 1346 | return read_flush(filp, buf, count, ppos, cd); | ||
| 1347 | } | ||
| 1348 | |||
| 1349 | static ssize_t write_flush_procfs(struct file *filp, | ||
| 1350 | const char __user *buf, | ||
| 1351 | size_t count, loff_t *ppos) | ||
| 1352 | { | ||
| 1353 | struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; | ||
| 1354 | |||
| 1355 | return write_flush(filp, buf, count, ppos, cd); | ||
| 1356 | } | ||
| 1357 | |||
| 1358 | static const struct file_operations cache_flush_operations_procfs = { | ||
| 1359 | .open = nonseekable_open, | ||
| 1360 | .read = read_flush_procfs, | ||
| 1361 | .write = write_flush_procfs, | ||
| 1362 | }; | ||
| 1363 | |||
| 1364 | static void remove_cache_proc_entries(struct cache_detail *cd) | ||
| 1365 | { | ||
| 1366 | if (cd->u.procfs.proc_ent == NULL) | ||
| 1367 | return; | ||
| 1368 | if (cd->u.procfs.flush_ent) | ||
| 1369 | remove_proc_entry("flush", cd->u.procfs.proc_ent); | ||
| 1370 | if (cd->u.procfs.channel_ent) | ||
| 1371 | remove_proc_entry("channel", cd->u.procfs.proc_ent); | ||
| 1372 | if (cd->u.procfs.content_ent) | ||
| 1373 | remove_proc_entry("content", cd->u.procfs.proc_ent); | ||
| 1374 | cd->u.procfs.proc_ent = NULL; | ||
| 1375 | remove_proc_entry(cd->name, proc_net_rpc); | ||
| 1376 | } | ||
| 1377 | |||
| 1378 | #ifdef CONFIG_PROC_FS | ||
| 1379 | static int create_cache_proc_entries(struct cache_detail *cd) | ||
| 1380 | { | ||
| 1381 | struct proc_dir_entry *p; | ||
| 1382 | |||
| 1383 | cd->u.procfs.proc_ent = proc_mkdir(cd->name, proc_net_rpc); | ||
| 1384 | if (cd->u.procfs.proc_ent == NULL) | ||
| 1385 | goto out_nomem; | ||
| 1386 | cd->u.procfs.channel_ent = NULL; | ||
| 1387 | cd->u.procfs.content_ent = NULL; | ||
| 1388 | |||
| 1389 | p = proc_create_data("flush", S_IFREG|S_IRUSR|S_IWUSR, | ||
| 1390 | cd->u.procfs.proc_ent, | ||
| 1391 | &cache_flush_operations_procfs, cd); | ||
| 1392 | cd->u.procfs.flush_ent = p; | ||
| 1393 | if (p == NULL) | ||
| 1394 | goto out_nomem; | ||
| 1395 | |||
| 1396 | if (cd->cache_upcall || cd->cache_parse) { | ||
| 1397 | p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR, | ||
| 1398 | cd->u.procfs.proc_ent, | ||
| 1399 | &cache_file_operations_procfs, cd); | ||
| 1400 | cd->u.procfs.channel_ent = p; | ||
| 1401 | if (p == NULL) | ||
| 1402 | goto out_nomem; | ||
| 1403 | } | ||
| 1404 | if (cd->cache_show) { | ||
| 1405 | p = proc_create_data("content", S_IFREG|S_IRUSR|S_IWUSR, | ||
| 1406 | cd->u.procfs.proc_ent, | ||
| 1407 | &content_file_operations_procfs, cd); | ||
| 1408 | cd->u.procfs.content_ent = p; | ||
| 1409 | if (p == NULL) | ||
| 1410 | goto out_nomem; | ||
| 1411 | } | ||
| 1412 | return 0; | ||
| 1413 | out_nomem: | ||
| 1414 | remove_cache_proc_entries(cd); | ||
| 1415 | return -ENOMEM; | ||
| 1416 | } | ||
| 1417 | #else /* CONFIG_PROC_FS */ | ||
| 1418 | static int create_cache_proc_entries(struct cache_detail *cd) | ||
| 1419 | { | ||
| 1420 | return 0; | ||
| 1421 | } | ||
| 1422 | #endif | ||
| 1423 | |||
| 1424 | int cache_register(struct cache_detail *cd) | ||
| 1425 | { | ||
| 1426 | int ret; | ||
| 1427 | |||
| 1428 | sunrpc_init_cache_detail(cd); | ||
| 1429 | ret = create_cache_proc_entries(cd); | ||
| 1430 | if (ret) | ||
| 1431 | sunrpc_destroy_cache_detail(cd); | ||
| 1432 | return ret; | ||
| 1433 | } | ||
| 1434 | EXPORT_SYMBOL_GPL(cache_register); | ||
| 1435 | |||
| 1436 | void cache_unregister(struct cache_detail *cd) | ||
| 1437 | { | ||
| 1438 | remove_cache_proc_entries(cd); | ||
| 1439 | sunrpc_destroy_cache_detail(cd); | ||
| 1440 | } | ||
| 1441 | EXPORT_SYMBOL_GPL(cache_unregister); | ||
| 1442 | |||
| 1443 | static ssize_t cache_read_pipefs(struct file *filp, char __user *buf, | ||
| 1444 | size_t count, loff_t *ppos) | ||
| 1445 | { | ||
| 1446 | struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private; | ||
| 1447 | |||
| 1448 | return cache_read(filp, buf, count, ppos, cd); | ||
| 1449 | } | ||
| 1450 | |||
| 1451 | static ssize_t cache_write_pipefs(struct file *filp, const char __user *buf, | ||
| 1452 | size_t count, loff_t *ppos) | ||
| 1453 | { | ||
| 1454 | struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private; | ||
| 1455 | |||
| 1456 | return cache_write(filp, buf, count, ppos, cd); | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | static unsigned int cache_poll_pipefs(struct file *filp, poll_table *wait) | ||
| 1460 | { | ||
| 1461 | struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private; | ||
| 1462 | |||
| 1463 | return cache_poll(filp, wait, cd); | ||
| 1464 | } | ||
| 1465 | |||
| 1466 | static int cache_ioctl_pipefs(struct inode *inode, struct file *filp, | ||
| 1467 | unsigned int cmd, unsigned long arg) | ||
| 1468 | { | ||
| 1469 | struct cache_detail *cd = RPC_I(inode)->private; | ||
| 1470 | |||
| 1471 | return cache_ioctl(inode, filp, cmd, arg, cd); | ||
| 1472 | } | ||
| 1473 | |||
| 1474 | static int cache_open_pipefs(struct inode *inode, struct file *filp) | ||
| 1475 | { | ||
| 1476 | struct cache_detail *cd = RPC_I(inode)->private; | ||
| 1477 | |||
| 1478 | return cache_open(inode, filp, cd); | ||
| 1479 | } | ||
| 1480 | |||
| 1481 | static int cache_release_pipefs(struct inode *inode, struct file *filp) | ||
| 1482 | { | ||
| 1483 | struct cache_detail *cd = RPC_I(inode)->private; | ||
| 1484 | |||
| 1485 | return cache_release(inode, filp, cd); | ||
| 1486 | } | ||
| 1487 | |||
| 1488 | const struct file_operations cache_file_operations_pipefs = { | ||
| 1489 | .owner = THIS_MODULE, | ||
| 1490 | .llseek = no_llseek, | ||
| 1491 | .read = cache_read_pipefs, | ||
| 1492 | .write = cache_write_pipefs, | ||
| 1493 | .poll = cache_poll_pipefs, | ||
| 1494 | .ioctl = cache_ioctl_pipefs, /* for FIONREAD */ | ||
| 1495 | .open = cache_open_pipefs, | ||
| 1496 | .release = cache_release_pipefs, | ||
| 1497 | }; | ||
| 1498 | |||
| 1499 | static int content_open_pipefs(struct inode *inode, struct file *filp) | ||
| 1500 | { | ||
| 1501 | struct cache_detail *cd = RPC_I(inode)->private; | ||
| 1502 | |||
| 1503 | return content_open(inode, filp, cd); | ||
| 1504 | } | ||
| 1505 | |||
| 1506 | const struct file_operations content_file_operations_pipefs = { | ||
| 1507 | .open = content_open_pipefs, | ||
| 1508 | .read = seq_read, | ||
| 1509 | .llseek = seq_lseek, | ||
| 1510 | .release = seq_release_private, | ||
| 1511 | }; | ||
| 1512 | |||
| 1513 | static ssize_t read_flush_pipefs(struct file *filp, char __user *buf, | ||
| 1514 | size_t count, loff_t *ppos) | ||
| 1515 | { | ||
| 1516 | struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private; | ||
| 1517 | |||
| 1518 | return read_flush(filp, buf, count, ppos, cd); | ||
| 1519 | } | ||
| 1520 | |||
| 1521 | static ssize_t write_flush_pipefs(struct file *filp, | ||
| 1522 | const char __user *buf, | ||
| 1523 | size_t count, loff_t *ppos) | ||
| 1524 | { | ||
| 1525 | struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private; | ||
| 1526 | |||
| 1527 | return write_flush(filp, buf, count, ppos, cd); | ||
| 1528 | } | ||
| 1529 | |||
| 1530 | const struct file_operations cache_flush_operations_pipefs = { | ||
| 1311 | .open = nonseekable_open, | 1531 | .open = nonseekable_open, |
| 1312 | .read = read_flush, | 1532 | .read = read_flush_pipefs, |
| 1313 | .write = write_flush, | 1533 | .write = write_flush_pipefs, |
| 1314 | }; | 1534 | }; |
| 1535 | |||
| 1536 | int sunrpc_cache_register_pipefs(struct dentry *parent, | ||
| 1537 | const char *name, mode_t umode, | ||
| 1538 | struct cache_detail *cd) | ||
| 1539 | { | ||
| 1540 | struct qstr q; | ||
| 1541 | struct dentry *dir; | ||
| 1542 | int ret = 0; | ||
| 1543 | |||
| 1544 | sunrpc_init_cache_detail(cd); | ||
| 1545 | q.name = name; | ||
| 1546 | q.len = strlen(name); | ||
| 1547 | q.hash = full_name_hash(q.name, q.len); | ||
| 1548 | dir = rpc_create_cache_dir(parent, &q, umode, cd); | ||
| 1549 | if (!IS_ERR(dir)) | ||
| 1550 | cd->u.pipefs.dir = dir; | ||
| 1551 | else { | ||
| 1552 | sunrpc_destroy_cache_detail(cd); | ||
| 1553 | ret = PTR_ERR(dir); | ||
| 1554 | } | ||
| 1555 | return ret; | ||
| 1556 | } | ||
| 1557 | EXPORT_SYMBOL_GPL(sunrpc_cache_register_pipefs); | ||
| 1558 | |||
| 1559 | void sunrpc_cache_unregister_pipefs(struct cache_detail *cd) | ||
| 1560 | { | ||
| 1561 | rpc_remove_cache_dir(cd->u.pipefs.dir); | ||
| 1562 | cd->u.pipefs.dir = NULL; | ||
| 1563 | sunrpc_destroy_cache_detail(cd); | ||
| 1564 | } | ||
| 1565 | EXPORT_SYMBOL_GPL(sunrpc_cache_unregister_pipefs); | ||
| 1566 | |||
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index ebfcf9b89909..c1e467e1b07d 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c | |||
| @@ -27,6 +27,8 @@ | |||
| 27 | #include <linux/types.h> | 27 | #include <linux/types.h> |
| 28 | #include <linux/kallsyms.h> | 28 | #include <linux/kallsyms.h> |
| 29 | #include <linux/mm.h> | 29 | #include <linux/mm.h> |
| 30 | #include <linux/namei.h> | ||
| 31 | #include <linux/mount.h> | ||
| 30 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
| 31 | #include <linux/utsname.h> | 33 | #include <linux/utsname.h> |
| 32 | #include <linux/workqueue.h> | 34 | #include <linux/workqueue.h> |
| @@ -97,33 +99,49 @@ static int | |||
| 97 | rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name) | 99 | rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name) |
| 98 | { | 100 | { |
| 99 | static uint32_t clntid; | 101 | static uint32_t clntid; |
| 102 | struct nameidata nd; | ||
| 103 | struct path path; | ||
| 104 | char name[15]; | ||
| 105 | struct qstr q = { | ||
| 106 | .name = name, | ||
| 107 | }; | ||
| 100 | int error; | 108 | int error; |
| 101 | 109 | ||
| 102 | clnt->cl_vfsmnt = ERR_PTR(-ENOENT); | 110 | clnt->cl_path.mnt = ERR_PTR(-ENOENT); |
| 103 | clnt->cl_dentry = ERR_PTR(-ENOENT); | 111 | clnt->cl_path.dentry = ERR_PTR(-ENOENT); |
| 104 | if (dir_name == NULL) | 112 | if (dir_name == NULL) |
| 105 | return 0; | 113 | return 0; |
| 106 | 114 | ||
| 107 | clnt->cl_vfsmnt = rpc_get_mount(); | 115 | path.mnt = rpc_get_mount(); |
| 108 | if (IS_ERR(clnt->cl_vfsmnt)) | 116 | if (IS_ERR(path.mnt)) |
| 109 | return PTR_ERR(clnt->cl_vfsmnt); | 117 | return PTR_ERR(path.mnt); |
| 118 | error = vfs_path_lookup(path.mnt->mnt_root, path.mnt, dir_name, 0, &nd); | ||
| 119 | if (error) | ||
| 120 | goto err; | ||
| 110 | 121 | ||
| 111 | for (;;) { | 122 | for (;;) { |
| 112 | snprintf(clnt->cl_pathname, sizeof(clnt->cl_pathname), | 123 | q.len = snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++); |
| 113 | "%s/clnt%x", dir_name, | 124 | name[sizeof(name) - 1] = '\0'; |
| 114 | (unsigned int)clntid++); | 125 | q.hash = full_name_hash(q.name, q.len); |
| 115 | clnt->cl_pathname[sizeof(clnt->cl_pathname) - 1] = '\0'; | 126 | path.dentry = rpc_create_client_dir(nd.path.dentry, &q, clnt); |
| 116 | clnt->cl_dentry = rpc_mkdir(clnt->cl_pathname, clnt); | 127 | if (!IS_ERR(path.dentry)) |
| 117 | if (!IS_ERR(clnt->cl_dentry)) | 128 | break; |
| 118 | return 0; | 129 | error = PTR_ERR(path.dentry); |
| 119 | error = PTR_ERR(clnt->cl_dentry); | ||
| 120 | if (error != -EEXIST) { | 130 | if (error != -EEXIST) { |
| 121 | printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n", | 131 | printk(KERN_INFO "RPC: Couldn't create pipefs entry" |
| 122 | clnt->cl_pathname, error); | 132 | " %s/%s, error %d\n", |
| 123 | rpc_put_mount(); | 133 | dir_name, name, error); |
| 124 | return error; | 134 | goto err_path_put; |
| 125 | } | 135 | } |
| 126 | } | 136 | } |
| 137 | path_put(&nd.path); | ||
| 138 | clnt->cl_path = path; | ||
| 139 | return 0; | ||
| 140 | err_path_put: | ||
| 141 | path_put(&nd.path); | ||
| 142 | err: | ||
| 143 | rpc_put_mount(); | ||
| 144 | return error; | ||
| 127 | } | 145 | } |
| 128 | 146 | ||
| 129 | static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, struct rpc_xprt *xprt) | 147 | static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, struct rpc_xprt *xprt) |
| @@ -231,8 +249,8 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, stru | |||
| 231 | return clnt; | 249 | return clnt; |
| 232 | 250 | ||
| 233 | out_no_auth: | 251 | out_no_auth: |
| 234 | if (!IS_ERR(clnt->cl_dentry)) { | 252 | if (!IS_ERR(clnt->cl_path.dentry)) { |
| 235 | rpc_rmdir(clnt->cl_dentry); | 253 | rpc_remove_client_dir(clnt->cl_path.dentry); |
| 236 | rpc_put_mount(); | 254 | rpc_put_mount(); |
| 237 | } | 255 | } |
| 238 | out_no_path: | 256 | out_no_path: |
| @@ -423,8 +441,8 @@ rpc_free_client(struct kref *kref) | |||
| 423 | 441 | ||
| 424 | dprintk("RPC: destroying %s client for %s\n", | 442 | dprintk("RPC: destroying %s client for %s\n", |
| 425 | clnt->cl_protname, clnt->cl_server); | 443 | clnt->cl_protname, clnt->cl_server); |
| 426 | if (!IS_ERR(clnt->cl_dentry)) { | 444 | if (!IS_ERR(clnt->cl_path.dentry)) { |
| 427 | rpc_rmdir(clnt->cl_dentry); | 445 | rpc_remove_client_dir(clnt->cl_path.dentry); |
| 428 | rpc_put_mount(); | 446 | rpc_put_mount(); |
| 429 | } | 447 | } |
| 430 | if (clnt->cl_parent != clnt) { | 448 | if (clnt->cl_parent != clnt) { |
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c index 9ced0628d69c..8dd81535e08f 100644 --- a/net/sunrpc/rpc_pipe.c +++ b/net/sunrpc/rpc_pipe.c | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include <linux/sunrpc/clnt.h> | 26 | #include <linux/sunrpc/clnt.h> |
| 27 | #include <linux/workqueue.h> | 27 | #include <linux/workqueue.h> |
| 28 | #include <linux/sunrpc/rpc_pipe_fs.h> | 28 | #include <linux/sunrpc/rpc_pipe_fs.h> |
| 29 | #include <linux/sunrpc/cache.h> | ||
| 29 | 30 | ||
| 30 | static struct vfsmount *rpc_mount __read_mostly; | 31 | static struct vfsmount *rpc_mount __read_mostly; |
| 31 | static int rpc_mount_count; | 32 | static int rpc_mount_count; |
| @@ -125,7 +126,7 @@ static void | |||
| 125 | rpc_close_pipes(struct inode *inode) | 126 | rpc_close_pipes(struct inode *inode) |
| 126 | { | 127 | { |
| 127 | struct rpc_inode *rpci = RPC_I(inode); | 128 | struct rpc_inode *rpci = RPC_I(inode); |
| 128 | struct rpc_pipe_ops *ops; | 129 | const struct rpc_pipe_ops *ops; |
| 129 | int need_release; | 130 | int need_release; |
| 130 | 131 | ||
| 131 | mutex_lock(&inode->i_mutex); | 132 | mutex_lock(&inode->i_mutex); |
| @@ -398,66 +399,12 @@ static const struct file_operations rpc_info_operations = { | |||
| 398 | 399 | ||
| 399 | 400 | ||
| 400 | /* | 401 | /* |
| 401 | * We have a single directory with 1 node in it. | ||
| 402 | */ | ||
| 403 | enum { | ||
| 404 | RPCAUTH_Root = 1, | ||
| 405 | RPCAUTH_lockd, | ||
| 406 | RPCAUTH_mount, | ||
| 407 | RPCAUTH_nfs, | ||
| 408 | RPCAUTH_portmap, | ||
| 409 | RPCAUTH_statd, | ||
| 410 | RPCAUTH_nfsd4_cb, | ||
| 411 | RPCAUTH_RootEOF | ||
| 412 | }; | ||
| 413 | |||
| 414 | /* | ||
| 415 | * Description of fs contents. | 402 | * Description of fs contents. |
| 416 | */ | 403 | */ |
| 417 | struct rpc_filelist { | 404 | struct rpc_filelist { |
| 418 | char *name; | 405 | const char *name; |
| 419 | const struct file_operations *i_fop; | 406 | const struct file_operations *i_fop; |
| 420 | int mode; | 407 | umode_t mode; |
| 421 | }; | ||
| 422 | |||
| 423 | static struct rpc_filelist files[] = { | ||
| 424 | [RPCAUTH_lockd] = { | ||
| 425 | .name = "lockd", | ||
| 426 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 427 | }, | ||
| 428 | [RPCAUTH_mount] = { | ||
| 429 | .name = "mount", | ||
| 430 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 431 | }, | ||
| 432 | [RPCAUTH_nfs] = { | ||
| 433 | .name = "nfs", | ||
| 434 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 435 | }, | ||
| 436 | [RPCAUTH_portmap] = { | ||
| 437 | .name = "portmap", | ||
| 438 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 439 | }, | ||
| 440 | [RPCAUTH_statd] = { | ||
| 441 | .name = "statd", | ||
| 442 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 443 | }, | ||
| 444 | [RPCAUTH_nfsd4_cb] = { | ||
| 445 | .name = "nfsd4_cb", | ||
| 446 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 447 | }, | ||
| 448 | }; | ||
| 449 | |||
| 450 | enum { | ||
| 451 | RPCAUTH_info = 2, | ||
| 452 | RPCAUTH_EOF | ||
| 453 | }; | ||
| 454 | |||
| 455 | static struct rpc_filelist authfiles[] = { | ||
| 456 | [RPCAUTH_info] = { | ||
| 457 | .name = "info", | ||
| 458 | .i_fop = &rpc_info_operations, | ||
| 459 | .mode = S_IFREG | S_IRUSR, | ||
| 460 | }, | ||
| 461 | }; | 408 | }; |
| 462 | 409 | ||
| 463 | struct vfsmount *rpc_get_mount(void) | 410 | struct vfsmount *rpc_get_mount(void) |
| @@ -484,39 +431,8 @@ static const struct dentry_operations rpc_dentry_operations = { | |||
| 484 | .d_delete = rpc_delete_dentry, | 431 | .d_delete = rpc_delete_dentry, |
| 485 | }; | 432 | }; |
| 486 | 433 | ||
| 487 | static int | ||
| 488 | rpc_lookup_parent(char *path, struct nameidata *nd) | ||
| 489 | { | ||
| 490 | struct vfsmount *mnt; | ||
| 491 | |||
| 492 | if (path[0] == '\0') | ||
| 493 | return -ENOENT; | ||
| 494 | |||
| 495 | mnt = rpc_get_mount(); | ||
| 496 | if (IS_ERR(mnt)) { | ||
| 497 | printk(KERN_WARNING "%s: %s failed to mount " | ||
| 498 | "pseudofilesystem \n", __FILE__, __func__); | ||
| 499 | return PTR_ERR(mnt); | ||
| 500 | } | ||
| 501 | |||
| 502 | if (vfs_path_lookup(mnt->mnt_root, mnt, path, LOOKUP_PARENT, nd)) { | ||
| 503 | printk(KERN_WARNING "%s: %s failed to find path %s\n", | ||
| 504 | __FILE__, __func__, path); | ||
| 505 | rpc_put_mount(); | ||
| 506 | return -ENOENT; | ||
| 507 | } | ||
| 508 | return 0; | ||
| 509 | } | ||
| 510 | |||
| 511 | static void | ||
| 512 | rpc_release_path(struct nameidata *nd) | ||
| 513 | { | ||
| 514 | path_put(&nd->path); | ||
| 515 | rpc_put_mount(); | ||
| 516 | } | ||
| 517 | |||
| 518 | static struct inode * | 434 | static struct inode * |
| 519 | rpc_get_inode(struct super_block *sb, int mode) | 435 | rpc_get_inode(struct super_block *sb, umode_t mode) |
| 520 | { | 436 | { |
| 521 | struct inode *inode = new_inode(sb); | 437 | struct inode *inode = new_inode(sb); |
| 522 | if (!inode) | 438 | if (!inode) |
| @@ -534,212 +450,274 @@ rpc_get_inode(struct super_block *sb, int mode) | |||
| 534 | return inode; | 450 | return inode; |
| 535 | } | 451 | } |
| 536 | 452 | ||
| 537 | /* | 453 | static int __rpc_create_common(struct inode *dir, struct dentry *dentry, |
| 538 | * FIXME: This probably has races. | 454 | umode_t mode, |
| 539 | */ | 455 | const struct file_operations *i_fop, |
| 540 | static void rpc_depopulate(struct dentry *parent, | 456 | void *private) |
| 541 | unsigned long start, unsigned long eof) | ||
| 542 | { | 457 | { |
| 543 | struct inode *dir = parent->d_inode; | 458 | struct inode *inode; |
| 544 | struct list_head *pos, *next; | ||
| 545 | struct dentry *dentry, *dvec[10]; | ||
| 546 | int n = 0; | ||
| 547 | 459 | ||
| 548 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_CHILD); | 460 | BUG_ON(!d_unhashed(dentry)); |
| 549 | repeat: | 461 | inode = rpc_get_inode(dir->i_sb, mode); |
| 550 | spin_lock(&dcache_lock); | 462 | if (!inode) |
| 551 | list_for_each_safe(pos, next, &parent->d_subdirs) { | 463 | goto out_err; |
| 552 | dentry = list_entry(pos, struct dentry, d_u.d_child); | 464 | inode->i_ino = iunique(dir->i_sb, 100); |
| 553 | if (!dentry->d_inode || | 465 | if (i_fop) |
| 554 | dentry->d_inode->i_ino < start || | 466 | inode->i_fop = i_fop; |
| 555 | dentry->d_inode->i_ino >= eof) | 467 | if (private) |
| 556 | continue; | 468 | rpc_inode_setowner(inode, private); |
| 557 | spin_lock(&dentry->d_lock); | 469 | d_add(dentry, inode); |
| 558 | if (!d_unhashed(dentry)) { | 470 | return 0; |
| 559 | dget_locked(dentry); | 471 | out_err: |
| 560 | __d_drop(dentry); | 472 | printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %s\n", |
| 561 | spin_unlock(&dentry->d_lock); | 473 | __FILE__, __func__, dentry->d_name.name); |
| 562 | dvec[n++] = dentry; | 474 | dput(dentry); |
| 563 | if (n == ARRAY_SIZE(dvec)) | 475 | return -ENOMEM; |
| 564 | break; | ||
| 565 | } else | ||
| 566 | spin_unlock(&dentry->d_lock); | ||
| 567 | } | ||
| 568 | spin_unlock(&dcache_lock); | ||
| 569 | if (n) { | ||
| 570 | do { | ||
| 571 | dentry = dvec[--n]; | ||
| 572 | if (S_ISREG(dentry->d_inode->i_mode)) | ||
| 573 | simple_unlink(dir, dentry); | ||
| 574 | else if (S_ISDIR(dentry->d_inode->i_mode)) | ||
| 575 | simple_rmdir(dir, dentry); | ||
| 576 | d_delete(dentry); | ||
| 577 | dput(dentry); | ||
| 578 | } while (n); | ||
| 579 | goto repeat; | ||
| 580 | } | ||
| 581 | mutex_unlock(&dir->i_mutex); | ||
| 582 | } | 476 | } |
| 583 | 477 | ||
| 584 | static int | 478 | static int __rpc_create(struct inode *dir, struct dentry *dentry, |
| 585 | rpc_populate(struct dentry *parent, | 479 | umode_t mode, |
| 586 | struct rpc_filelist *files, | 480 | const struct file_operations *i_fop, |
| 587 | int start, int eof) | 481 | void *private) |
| 588 | { | 482 | { |
| 589 | struct inode *inode, *dir = parent->d_inode; | 483 | int err; |
| 590 | void *private = RPC_I(dir)->private; | ||
| 591 | struct dentry *dentry; | ||
| 592 | int mode, i; | ||
| 593 | 484 | ||
| 594 | mutex_lock(&dir->i_mutex); | 485 | err = __rpc_create_common(dir, dentry, S_IFREG | mode, i_fop, private); |
| 595 | for (i = start; i < eof; i++) { | 486 | if (err) |
| 596 | dentry = d_alloc_name(parent, files[i].name); | 487 | return err; |
| 597 | if (!dentry) | 488 | fsnotify_create(dir, dentry); |
| 598 | goto out_bad; | ||
| 599 | dentry->d_op = &rpc_dentry_operations; | ||
| 600 | mode = files[i].mode; | ||
| 601 | inode = rpc_get_inode(dir->i_sb, mode); | ||
| 602 | if (!inode) { | ||
| 603 | dput(dentry); | ||
| 604 | goto out_bad; | ||
| 605 | } | ||
| 606 | inode->i_ino = i; | ||
| 607 | if (files[i].i_fop) | ||
| 608 | inode->i_fop = files[i].i_fop; | ||
| 609 | if (private) | ||
| 610 | rpc_inode_setowner(inode, private); | ||
| 611 | if (S_ISDIR(mode)) | ||
| 612 | inc_nlink(dir); | ||
| 613 | d_add(dentry, inode); | ||
| 614 | fsnotify_create(dir, dentry); | ||
| 615 | } | ||
| 616 | mutex_unlock(&dir->i_mutex); | ||
| 617 | return 0; | 489 | return 0; |
| 618 | out_bad: | ||
| 619 | mutex_unlock(&dir->i_mutex); | ||
| 620 | printk(KERN_WARNING "%s: %s failed to populate directory %s\n", | ||
| 621 | __FILE__, __func__, parent->d_name.name); | ||
| 622 | return -ENOMEM; | ||
| 623 | } | 490 | } |
| 624 | 491 | ||
| 625 | static int | 492 | static int __rpc_mkdir(struct inode *dir, struct dentry *dentry, |
| 626 | __rpc_mkdir(struct inode *dir, struct dentry *dentry) | 493 | umode_t mode, |
| 494 | const struct file_operations *i_fop, | ||
| 495 | void *private) | ||
| 627 | { | 496 | { |
| 628 | struct inode *inode; | 497 | int err; |
| 629 | 498 | ||
| 630 | inode = rpc_get_inode(dir->i_sb, S_IFDIR | S_IRUGO | S_IXUGO); | 499 | err = __rpc_create_common(dir, dentry, S_IFDIR | mode, i_fop, private); |
| 631 | if (!inode) | 500 | if (err) |
| 632 | goto out_err; | 501 | return err; |
| 633 | inode->i_ino = iunique(dir->i_sb, 100); | ||
| 634 | d_instantiate(dentry, inode); | ||
| 635 | inc_nlink(dir); | 502 | inc_nlink(dir); |
| 636 | fsnotify_mkdir(dir, dentry); | 503 | fsnotify_mkdir(dir, dentry); |
| 637 | return 0; | 504 | return 0; |
| 638 | out_err: | ||
| 639 | printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %s\n", | ||
| 640 | __FILE__, __func__, dentry->d_name.name); | ||
| 641 | return -ENOMEM; | ||
| 642 | } | 505 | } |
| 643 | 506 | ||
| 644 | static int | 507 | static int __rpc_mkpipe(struct inode *dir, struct dentry *dentry, |
| 645 | __rpc_rmdir(struct inode *dir, struct dentry *dentry) | 508 | umode_t mode, |
| 509 | const struct file_operations *i_fop, | ||
| 510 | void *private, | ||
| 511 | const struct rpc_pipe_ops *ops, | ||
| 512 | int flags) | ||
| 646 | { | 513 | { |
| 647 | int error; | 514 | struct rpc_inode *rpci; |
| 648 | error = simple_rmdir(dir, dentry); | 515 | int err; |
| 649 | if (!error) | 516 | |
| 650 | d_delete(dentry); | 517 | err = __rpc_create_common(dir, dentry, S_IFIFO | mode, i_fop, private); |
| 651 | return error; | 518 | if (err) |
| 519 | return err; | ||
| 520 | rpci = RPC_I(dentry->d_inode); | ||
| 521 | rpci->nkern_readwriters = 1; | ||
| 522 | rpci->private = private; | ||
| 523 | rpci->flags = flags; | ||
| 524 | rpci->ops = ops; | ||
| 525 | fsnotify_create(dir, dentry); | ||
| 526 | return 0; | ||
| 652 | } | 527 | } |
| 653 | 528 | ||
| 654 | static struct dentry * | 529 | static int __rpc_rmdir(struct inode *dir, struct dentry *dentry) |
| 655 | rpc_lookup_create(struct dentry *parent, const char *name, int len, int exclusive) | 530 | { |
| 531 | int ret; | ||
| 532 | |||
| 533 | dget(dentry); | ||
| 534 | ret = simple_rmdir(dir, dentry); | ||
| 535 | d_delete(dentry); | ||
| 536 | dput(dentry); | ||
| 537 | return ret; | ||
| 538 | } | ||
| 539 | |||
| 540 | static int __rpc_unlink(struct inode *dir, struct dentry *dentry) | ||
| 541 | { | ||
| 542 | int ret; | ||
| 543 | |||
| 544 | dget(dentry); | ||
| 545 | ret = simple_unlink(dir, dentry); | ||
| 546 | d_delete(dentry); | ||
| 547 | dput(dentry); | ||
| 548 | return ret; | ||
| 549 | } | ||
| 550 | |||
| 551 | static int __rpc_rmpipe(struct inode *dir, struct dentry *dentry) | ||
| 552 | { | ||
| 553 | struct inode *inode = dentry->d_inode; | ||
| 554 | struct rpc_inode *rpci = RPC_I(inode); | ||
| 555 | |||
| 556 | rpci->nkern_readwriters--; | ||
| 557 | if (rpci->nkern_readwriters != 0) | ||
| 558 | return 0; | ||
| 559 | rpc_close_pipes(inode); | ||
| 560 | return __rpc_unlink(dir, dentry); | ||
| 561 | } | ||
| 562 | |||
| 563 | static struct dentry *__rpc_lookup_create(struct dentry *parent, | ||
| 564 | struct qstr *name) | ||
| 656 | { | 565 | { |
| 657 | struct inode *dir = parent->d_inode; | ||
| 658 | struct dentry *dentry; | 566 | struct dentry *dentry; |
| 659 | 567 | ||
| 660 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); | 568 | dentry = d_lookup(parent, name); |
| 661 | dentry = lookup_one_len(name, parent, len); | 569 | if (!dentry) { |
| 662 | if (IS_ERR(dentry)) | 570 | dentry = d_alloc(parent, name); |
| 663 | goto out_err; | 571 | if (!dentry) { |
| 572 | dentry = ERR_PTR(-ENOMEM); | ||
| 573 | goto out_err; | ||
| 574 | } | ||
| 575 | } | ||
| 664 | if (!dentry->d_inode) | 576 | if (!dentry->d_inode) |
| 665 | dentry->d_op = &rpc_dentry_operations; | 577 | dentry->d_op = &rpc_dentry_operations; |
| 666 | else if (exclusive) { | ||
| 667 | dput(dentry); | ||
| 668 | dentry = ERR_PTR(-EEXIST); | ||
| 669 | goto out_err; | ||
| 670 | } | ||
| 671 | return dentry; | ||
| 672 | out_err: | 578 | out_err: |
| 673 | mutex_unlock(&dir->i_mutex); | ||
| 674 | return dentry; | 579 | return dentry; |
| 675 | } | 580 | } |
| 676 | 581 | ||
| 677 | static struct dentry * | 582 | static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent, |
| 678 | rpc_lookup_negative(char *path, struct nameidata *nd) | 583 | struct qstr *name) |
| 679 | { | 584 | { |
| 680 | struct dentry *dentry; | 585 | struct dentry *dentry; |
| 681 | int error; | ||
| 682 | 586 | ||
| 683 | if ((error = rpc_lookup_parent(path, nd)) != 0) | 587 | dentry = __rpc_lookup_create(parent, name); |
| 684 | return ERR_PTR(error); | 588 | if (dentry->d_inode == NULL) |
| 685 | dentry = rpc_lookup_create(nd->path.dentry, nd->last.name, nd->last.len, | 589 | return dentry; |
| 686 | 1); | 590 | dput(dentry); |
| 687 | if (IS_ERR(dentry)) | 591 | return ERR_PTR(-EEXIST); |
| 688 | rpc_release_path(nd); | ||
| 689 | return dentry; | ||
| 690 | } | 592 | } |
| 691 | 593 | ||
| 692 | /** | 594 | /* |
| 693 | * rpc_mkdir - Create a new directory in rpc_pipefs | 595 | * FIXME: This probably has races. |
| 694 | * @path: path from the rpc_pipefs root to the new directory | ||
| 695 | * @rpc_client: rpc client to associate with this directory | ||
| 696 | * | ||
| 697 | * This creates a directory at the given @path associated with | ||
| 698 | * @rpc_clnt, which will contain a file named "info" with some basic | ||
| 699 | * information about the client, together with any "pipes" that may | ||
| 700 | * later be created using rpc_mkpipe(). | ||
| 701 | */ | 596 | */ |
| 702 | struct dentry * | 597 | static void __rpc_depopulate(struct dentry *parent, |
| 703 | rpc_mkdir(char *path, struct rpc_clnt *rpc_client) | 598 | const struct rpc_filelist *files, |
| 599 | int start, int eof) | ||
| 704 | { | 600 | { |
| 705 | struct nameidata nd; | 601 | struct inode *dir = parent->d_inode; |
| 706 | struct dentry *dentry; | 602 | struct dentry *dentry; |
| 707 | struct inode *dir; | 603 | struct qstr name; |
| 604 | int i; | ||
| 605 | |||
| 606 | for (i = start; i < eof; i++) { | ||
| 607 | name.name = files[i].name; | ||
| 608 | name.len = strlen(files[i].name); | ||
| 609 | name.hash = full_name_hash(name.name, name.len); | ||
| 610 | dentry = d_lookup(parent, &name); | ||
| 611 | |||
| 612 | if (dentry == NULL) | ||
| 613 | continue; | ||
| 614 | if (dentry->d_inode == NULL) | ||
| 615 | goto next; | ||
| 616 | switch (dentry->d_inode->i_mode & S_IFMT) { | ||
| 617 | default: | ||
| 618 | BUG(); | ||
| 619 | case S_IFREG: | ||
| 620 | __rpc_unlink(dir, dentry); | ||
| 621 | break; | ||
| 622 | case S_IFDIR: | ||
| 623 | __rpc_rmdir(dir, dentry); | ||
| 624 | } | ||
| 625 | next: | ||
| 626 | dput(dentry); | ||
| 627 | } | ||
| 628 | } | ||
| 629 | |||
| 630 | static void rpc_depopulate(struct dentry *parent, | ||
| 631 | const struct rpc_filelist *files, | ||
| 632 | int start, int eof) | ||
| 633 | { | ||
| 634 | struct inode *dir = parent->d_inode; | ||
| 635 | |||
| 636 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_CHILD); | ||
| 637 | __rpc_depopulate(parent, files, start, eof); | ||
| 638 | mutex_unlock(&dir->i_mutex); | ||
| 639 | } | ||
| 640 | |||
| 641 | static int rpc_populate(struct dentry *parent, | ||
| 642 | const struct rpc_filelist *files, | ||
| 643 | int start, int eof, | ||
| 644 | void *private) | ||
| 645 | { | ||
| 646 | struct inode *dir = parent->d_inode; | ||
| 647 | struct dentry *dentry; | ||
| 648 | int i, err; | ||
| 649 | |||
| 650 | mutex_lock(&dir->i_mutex); | ||
| 651 | for (i = start; i < eof; i++) { | ||
| 652 | struct qstr q; | ||
| 653 | |||
| 654 | q.name = files[i].name; | ||
| 655 | q.len = strlen(files[i].name); | ||
| 656 | q.hash = full_name_hash(q.name, q.len); | ||
| 657 | dentry = __rpc_lookup_create_exclusive(parent, &q); | ||
| 658 | err = PTR_ERR(dentry); | ||
| 659 | if (IS_ERR(dentry)) | ||
| 660 | goto out_bad; | ||
| 661 | switch (files[i].mode & S_IFMT) { | ||
| 662 | default: | ||
| 663 | BUG(); | ||
| 664 | case S_IFREG: | ||
| 665 | err = __rpc_create(dir, dentry, | ||
| 666 | files[i].mode, | ||
| 667 | files[i].i_fop, | ||
| 668 | private); | ||
| 669 | break; | ||
| 670 | case S_IFDIR: | ||
| 671 | err = __rpc_mkdir(dir, dentry, | ||
| 672 | files[i].mode, | ||
| 673 | NULL, | ||
| 674 | private); | ||
| 675 | } | ||
| 676 | if (err != 0) | ||
| 677 | goto out_bad; | ||
| 678 | } | ||
| 679 | mutex_unlock(&dir->i_mutex); | ||
| 680 | return 0; | ||
| 681 | out_bad: | ||
| 682 | __rpc_depopulate(parent, files, start, eof); | ||
| 683 | mutex_unlock(&dir->i_mutex); | ||
| 684 | printk(KERN_WARNING "%s: %s failed to populate directory %s\n", | ||
| 685 | __FILE__, __func__, parent->d_name.name); | ||
| 686 | return err; | ||
| 687 | } | ||
| 688 | |||
| 689 | static struct dentry *rpc_mkdir_populate(struct dentry *parent, | ||
| 690 | struct qstr *name, umode_t mode, void *private, | ||
| 691 | int (*populate)(struct dentry *, void *), void *args_populate) | ||
| 692 | { | ||
| 693 | struct dentry *dentry; | ||
| 694 | struct inode *dir = parent->d_inode; | ||
| 708 | int error; | 695 | int error; |
| 709 | 696 | ||
| 710 | dentry = rpc_lookup_negative(path, &nd); | 697 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); |
| 698 | dentry = __rpc_lookup_create_exclusive(parent, name); | ||
| 711 | if (IS_ERR(dentry)) | 699 | if (IS_ERR(dentry)) |
| 712 | return dentry; | 700 | goto out; |
| 713 | dir = nd.path.dentry->d_inode; | 701 | error = __rpc_mkdir(dir, dentry, mode, NULL, private); |
| 714 | if ((error = __rpc_mkdir(dir, dentry)) != 0) | 702 | if (error != 0) |
| 715 | goto err_dput; | 703 | goto out_err; |
| 716 | RPC_I(dentry->d_inode)->private = rpc_client; | 704 | if (populate != NULL) { |
| 717 | error = rpc_populate(dentry, authfiles, | 705 | error = populate(dentry, args_populate); |
| 718 | RPCAUTH_info, RPCAUTH_EOF); | 706 | if (error) |
| 719 | if (error) | 707 | goto err_rmdir; |
| 720 | goto err_depopulate; | 708 | } |
| 721 | dget(dentry); | ||
| 722 | out: | 709 | out: |
| 723 | mutex_unlock(&dir->i_mutex); | 710 | mutex_unlock(&dir->i_mutex); |
| 724 | rpc_release_path(&nd); | ||
| 725 | return dentry; | 711 | return dentry; |
| 726 | err_depopulate: | 712 | err_rmdir: |
| 727 | rpc_depopulate(dentry, RPCAUTH_info, RPCAUTH_EOF); | ||
| 728 | __rpc_rmdir(dir, dentry); | 713 | __rpc_rmdir(dir, dentry); |
| 729 | err_dput: | 714 | out_err: |
| 730 | dput(dentry); | ||
| 731 | printk(KERN_WARNING "%s: %s() failed to create directory %s (errno = %d)\n", | ||
| 732 | __FILE__, __func__, path, error); | ||
| 733 | dentry = ERR_PTR(error); | 715 | dentry = ERR_PTR(error); |
| 734 | goto out; | 716 | goto out; |
| 735 | } | 717 | } |
| 736 | 718 | ||
| 737 | /** | 719 | static int rpc_rmdir_depopulate(struct dentry *dentry, |
| 738 | * rpc_rmdir - Remove a directory created with rpc_mkdir() | 720 | void (*depopulate)(struct dentry *)) |
| 739 | * @dentry: directory to remove | ||
| 740 | */ | ||
| 741 | int | ||
| 742 | rpc_rmdir(struct dentry *dentry) | ||
| 743 | { | 721 | { |
| 744 | struct dentry *parent; | 722 | struct dentry *parent; |
| 745 | struct inode *dir; | 723 | struct inode *dir; |
| @@ -748,9 +726,9 @@ rpc_rmdir(struct dentry *dentry) | |||
| 748 | parent = dget_parent(dentry); | 726 | parent = dget_parent(dentry); |
| 749 | dir = parent->d_inode; | 727 | dir = parent->d_inode; |
| 750 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); | 728 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); |
| 751 | rpc_depopulate(dentry, RPCAUTH_info, RPCAUTH_EOF); | 729 | if (depopulate != NULL) |
| 730 | depopulate(dentry); | ||
| 752 | error = __rpc_rmdir(dir, dentry); | 731 | error = __rpc_rmdir(dir, dentry); |
| 753 | dput(dentry); | ||
| 754 | mutex_unlock(&dir->i_mutex); | 732 | mutex_unlock(&dir->i_mutex); |
| 755 | dput(parent); | 733 | dput(parent); |
| 756 | return error; | 734 | return error; |
| @@ -776,50 +754,54 @@ rpc_rmdir(struct dentry *dentry) | |||
| 776 | * The @private argument passed here will be available to all these methods | 754 | * The @private argument passed here will be available to all these methods |
| 777 | * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private. | 755 | * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private. |
| 778 | */ | 756 | */ |
| 779 | struct dentry * | 757 | struct dentry *rpc_mkpipe(struct dentry *parent, const char *name, |
| 780 | rpc_mkpipe(struct dentry *parent, const char *name, void *private, struct rpc_pipe_ops *ops, int flags) | 758 | void *private, const struct rpc_pipe_ops *ops, |
| 759 | int flags) | ||
| 781 | { | 760 | { |
| 782 | struct dentry *dentry; | 761 | struct dentry *dentry; |
| 783 | struct inode *dir, *inode; | 762 | struct inode *dir = parent->d_inode; |
| 784 | struct rpc_inode *rpci; | 763 | umode_t umode = S_IFIFO | S_IRUSR | S_IWUSR; |
| 764 | struct qstr q; | ||
| 765 | int err; | ||
| 785 | 766 | ||
| 786 | dentry = rpc_lookup_create(parent, name, strlen(name), 0); | 767 | if (ops->upcall == NULL) |
| 768 | umode &= ~S_IRUGO; | ||
| 769 | if (ops->downcall == NULL) | ||
| 770 | umode &= ~S_IWUGO; | ||
| 771 | |||
| 772 | q.name = name; | ||
| 773 | q.len = strlen(name); | ||
| 774 | q.hash = full_name_hash(q.name, q.len), | ||
| 775 | |||
| 776 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); | ||
| 777 | dentry = __rpc_lookup_create(parent, &q); | ||
| 787 | if (IS_ERR(dentry)) | 778 | if (IS_ERR(dentry)) |
| 788 | return dentry; | 779 | goto out; |
| 789 | dir = parent->d_inode; | ||
| 790 | if (dentry->d_inode) { | 780 | if (dentry->d_inode) { |
| 791 | rpci = RPC_I(dentry->d_inode); | 781 | struct rpc_inode *rpci = RPC_I(dentry->d_inode); |
| 792 | if (rpci->private != private || | 782 | if (rpci->private != private || |
| 793 | rpci->ops != ops || | 783 | rpci->ops != ops || |
| 794 | rpci->flags != flags) { | 784 | rpci->flags != flags) { |
| 795 | dput (dentry); | 785 | dput (dentry); |
| 796 | dentry = ERR_PTR(-EBUSY); | 786 | err = -EBUSY; |
| 787 | goto out_err; | ||
| 797 | } | 788 | } |
| 798 | rpci->nkern_readwriters++; | 789 | rpci->nkern_readwriters++; |
| 799 | goto out; | 790 | goto out; |
| 800 | } | 791 | } |
| 801 | inode = rpc_get_inode(dir->i_sb, S_IFIFO | S_IRUSR | S_IWUSR); | 792 | |
| 802 | if (!inode) | 793 | err = __rpc_mkpipe(dir, dentry, umode, &rpc_pipe_fops, |
| 803 | goto err_dput; | 794 | private, ops, flags); |
| 804 | inode->i_ino = iunique(dir->i_sb, 100); | 795 | if (err) |
| 805 | inode->i_fop = &rpc_pipe_fops; | 796 | goto out_err; |
| 806 | d_instantiate(dentry, inode); | ||
| 807 | rpci = RPC_I(inode); | ||
| 808 | rpci->private = private; | ||
| 809 | rpci->flags = flags; | ||
| 810 | rpci->ops = ops; | ||
| 811 | rpci->nkern_readwriters = 1; | ||
| 812 | fsnotify_create(dir, dentry); | ||
| 813 | dget(dentry); | ||
| 814 | out: | 797 | out: |
| 815 | mutex_unlock(&dir->i_mutex); | 798 | mutex_unlock(&dir->i_mutex); |
| 816 | return dentry; | 799 | return dentry; |
| 817 | err_dput: | 800 | out_err: |
| 818 | dput(dentry); | 801 | dentry = ERR_PTR(err); |
| 819 | dentry = ERR_PTR(-ENOMEM); | ||
| 820 | printk(KERN_WARNING "%s: %s() failed to create pipe %s/%s (errno = %d)\n", | 802 | printk(KERN_WARNING "%s: %s() failed to create pipe %s/%s (errno = %d)\n", |
| 821 | __FILE__, __func__, parent->d_name.name, name, | 803 | __FILE__, __func__, parent->d_name.name, name, |
| 822 | -ENOMEM); | 804 | err); |
| 823 | goto out; | 805 | goto out; |
| 824 | } | 806 | } |
| 825 | EXPORT_SYMBOL_GPL(rpc_mkpipe); | 807 | EXPORT_SYMBOL_GPL(rpc_mkpipe); |
| @@ -842,19 +824,107 @@ rpc_unlink(struct dentry *dentry) | |||
| 842 | parent = dget_parent(dentry); | 824 | parent = dget_parent(dentry); |
| 843 | dir = parent->d_inode; | 825 | dir = parent->d_inode; |
| 844 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); | 826 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); |
| 845 | if (--RPC_I(dentry->d_inode)->nkern_readwriters == 0) { | 827 | error = __rpc_rmpipe(dir, dentry); |
| 846 | rpc_close_pipes(dentry->d_inode); | ||
| 847 | error = simple_unlink(dir, dentry); | ||
| 848 | if (!error) | ||
| 849 | d_delete(dentry); | ||
| 850 | } | ||
| 851 | dput(dentry); | ||
| 852 | mutex_unlock(&dir->i_mutex); | 828 | mutex_unlock(&dir->i_mutex); |
| 853 | dput(parent); | 829 | dput(parent); |
| 854 | return error; | 830 | return error; |
| 855 | } | 831 | } |
| 856 | EXPORT_SYMBOL_GPL(rpc_unlink); | 832 | EXPORT_SYMBOL_GPL(rpc_unlink); |
| 857 | 833 | ||
| 834 | enum { | ||
| 835 | RPCAUTH_info, | ||
| 836 | RPCAUTH_EOF | ||
| 837 | }; | ||
| 838 | |||
| 839 | static const struct rpc_filelist authfiles[] = { | ||
| 840 | [RPCAUTH_info] = { | ||
| 841 | .name = "info", | ||
| 842 | .i_fop = &rpc_info_operations, | ||
| 843 | .mode = S_IFREG | S_IRUSR, | ||
| 844 | }, | ||
| 845 | }; | ||
| 846 | |||
| 847 | static int rpc_clntdir_populate(struct dentry *dentry, void *private) | ||
| 848 | { | ||
| 849 | return rpc_populate(dentry, | ||
| 850 | authfiles, RPCAUTH_info, RPCAUTH_EOF, | ||
| 851 | private); | ||
| 852 | } | ||
| 853 | |||
| 854 | static void rpc_clntdir_depopulate(struct dentry *dentry) | ||
| 855 | { | ||
| 856 | rpc_depopulate(dentry, authfiles, RPCAUTH_info, RPCAUTH_EOF); | ||
| 857 | } | ||
| 858 | |||
| 859 | /** | ||
| 860 | * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs | ||
| 861 | * @path: path from the rpc_pipefs root to the new directory | ||
| 862 | * @rpc_client: rpc client to associate with this directory | ||
| 863 | * | ||
| 864 | * This creates a directory at the given @path associated with | ||
| 865 | * @rpc_clnt, which will contain a file named "info" with some basic | ||
| 866 | * information about the client, together with any "pipes" that may | ||
| 867 | * later be created using rpc_mkpipe(). | ||
| 868 | */ | ||
| 869 | struct dentry *rpc_create_client_dir(struct dentry *dentry, | ||
| 870 | struct qstr *name, | ||
| 871 | struct rpc_clnt *rpc_client) | ||
| 872 | { | ||
| 873 | return rpc_mkdir_populate(dentry, name, S_IRUGO | S_IXUGO, NULL, | ||
| 874 | rpc_clntdir_populate, rpc_client); | ||
| 875 | } | ||
| 876 | |||
| 877 | /** | ||
| 878 | * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir() | ||
| 879 | * @dentry: directory to remove | ||
| 880 | */ | ||
| 881 | int rpc_remove_client_dir(struct dentry *dentry) | ||
| 882 | { | ||
| 883 | return rpc_rmdir_depopulate(dentry, rpc_clntdir_depopulate); | ||
| 884 | } | ||
| 885 | |||
| 886 | static const struct rpc_filelist cache_pipefs_files[3] = { | ||
| 887 | [0] = { | ||
| 888 | .name = "channel", | ||
| 889 | .i_fop = &cache_file_operations_pipefs, | ||
| 890 | .mode = S_IFIFO|S_IRUSR|S_IWUSR, | ||
| 891 | }, | ||
| 892 | [1] = { | ||
| 893 | .name = "content", | ||
| 894 | .i_fop = &content_file_operations_pipefs, | ||
| 895 | .mode = S_IFREG|S_IRUSR, | ||
| 896 | }, | ||
| 897 | [2] = { | ||
| 898 | .name = "flush", | ||
| 899 | .i_fop = &cache_flush_operations_pipefs, | ||
| 900 | .mode = S_IFREG|S_IRUSR|S_IWUSR, | ||
| 901 | }, | ||
| 902 | }; | ||
| 903 | |||
| 904 | static int rpc_cachedir_populate(struct dentry *dentry, void *private) | ||
| 905 | { | ||
| 906 | return rpc_populate(dentry, | ||
| 907 | cache_pipefs_files, 0, 3, | ||
| 908 | private); | ||
| 909 | } | ||
| 910 | |||
| 911 | static void rpc_cachedir_depopulate(struct dentry *dentry) | ||
| 912 | { | ||
| 913 | rpc_depopulate(dentry, cache_pipefs_files, 0, 3); | ||
| 914 | } | ||
| 915 | |||
| 916 | struct dentry *rpc_create_cache_dir(struct dentry *parent, struct qstr *name, | ||
| 917 | mode_t umode, struct cache_detail *cd) | ||
| 918 | { | ||
| 919 | return rpc_mkdir_populate(parent, name, umode, NULL, | ||
| 920 | rpc_cachedir_populate, cd); | ||
| 921 | } | ||
| 922 | |||
| 923 | void rpc_remove_cache_dir(struct dentry *dentry) | ||
| 924 | { | ||
| 925 | rpc_rmdir_depopulate(dentry, rpc_cachedir_depopulate); | ||
| 926 | } | ||
| 927 | |||
| 858 | /* | 928 | /* |
| 859 | * populate the filesystem | 929 | * populate the filesystem |
| 860 | */ | 930 | */ |
| @@ -866,6 +936,46 @@ static struct super_operations s_ops = { | |||
| 866 | 936 | ||
| 867 | #define RPCAUTH_GSSMAGIC 0x67596969 | 937 | #define RPCAUTH_GSSMAGIC 0x67596969 |
| 868 | 938 | ||
| 939 | /* | ||
| 940 | * We have a single directory with 1 node in it. | ||
| 941 | */ | ||
| 942 | enum { | ||
| 943 | RPCAUTH_lockd, | ||
| 944 | RPCAUTH_mount, | ||
| 945 | RPCAUTH_nfs, | ||
| 946 | RPCAUTH_portmap, | ||
| 947 | RPCAUTH_statd, | ||
| 948 | RPCAUTH_nfsd4_cb, | ||
| 949 | RPCAUTH_RootEOF | ||
| 950 | }; | ||
| 951 | |||
| 952 | static const struct rpc_filelist files[] = { | ||
| 953 | [RPCAUTH_lockd] = { | ||
| 954 | .name = "lockd", | ||
| 955 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 956 | }, | ||
| 957 | [RPCAUTH_mount] = { | ||
| 958 | .name = "mount", | ||
| 959 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 960 | }, | ||
| 961 | [RPCAUTH_nfs] = { | ||
| 962 | .name = "nfs", | ||
| 963 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 964 | }, | ||
| 965 | [RPCAUTH_portmap] = { | ||
| 966 | .name = "portmap", | ||
| 967 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 968 | }, | ||
| 969 | [RPCAUTH_statd] = { | ||
| 970 | .name = "statd", | ||
| 971 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 972 | }, | ||
| 973 | [RPCAUTH_nfsd4_cb] = { | ||
| 974 | .name = "nfsd4_cb", | ||
| 975 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, | ||
| 976 | }, | ||
| 977 | }; | ||
| 978 | |||
| 869 | static int | 979 | static int |
| 870 | rpc_fill_super(struct super_block *sb, void *data, int silent) | 980 | rpc_fill_super(struct super_block *sb, void *data, int silent) |
| 871 | { | 981 | { |
| @@ -886,7 +996,7 @@ rpc_fill_super(struct super_block *sb, void *data, int silent) | |||
| 886 | iput(inode); | 996 | iput(inode); |
| 887 | return -ENOMEM; | 997 | return -ENOMEM; |
| 888 | } | 998 | } |
| 889 | if (rpc_populate(root, files, RPCAUTH_Root + 1, RPCAUTH_RootEOF)) | 999 | if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL)) |
| 890 | goto out; | 1000 | goto out; |
| 891 | sb->s_root = root; | 1001 | sb->s_root = root; |
| 892 | return 0; | 1002 | return 0; |
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c index beee6da33035..830faf4d9997 100644 --- a/net/sunrpc/rpcb_clnt.c +++ b/net/sunrpc/rpcb_clnt.c | |||
| @@ -75,6 +75,37 @@ enum { | |||
| 75 | #define RPCB_OWNER_STRING "0" | 75 | #define RPCB_OWNER_STRING "0" |
| 76 | #define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING) | 76 | #define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING) |
| 77 | 77 | ||
| 78 | /* | ||
| 79 | * XDR data type sizes | ||
| 80 | */ | ||
| 81 | #define RPCB_program_sz (1) | ||
| 82 | #define RPCB_version_sz (1) | ||
| 83 | #define RPCB_protocol_sz (1) | ||
| 84 | #define RPCB_port_sz (1) | ||
| 85 | #define RPCB_boolean_sz (1) | ||
| 86 | |||
| 87 | #define RPCB_netid_sz (1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN)) | ||
| 88 | #define RPCB_addr_sz (1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN)) | ||
| 89 | #define RPCB_ownerstring_sz (1 + XDR_QUADLEN(RPCB_MAXOWNERLEN)) | ||
| 90 | |||
| 91 | /* | ||
| 92 | * XDR argument and result sizes | ||
| 93 | */ | ||
| 94 | #define RPCB_mappingargs_sz (RPCB_program_sz + RPCB_version_sz + \ | ||
| 95 | RPCB_protocol_sz + RPCB_port_sz) | ||
| 96 | #define RPCB_getaddrargs_sz (RPCB_program_sz + RPCB_version_sz + \ | ||
| 97 | RPCB_netid_sz + RPCB_addr_sz + \ | ||
| 98 | RPCB_ownerstring_sz) | ||
| 99 | |||
| 100 | #define RPCB_getportres_sz RPCB_port_sz | ||
| 101 | #define RPCB_setres_sz RPCB_boolean_sz | ||
| 102 | |||
| 103 | /* | ||
| 104 | * Note that RFC 1833 does not put any size restrictions on the | ||
| 105 | * address string returned by the remote rpcbind database. | ||
| 106 | */ | ||
| 107 | #define RPCB_getaddrres_sz RPCB_addr_sz | ||
| 108 | |||
| 78 | static void rpcb_getport_done(struct rpc_task *, void *); | 109 | static void rpcb_getport_done(struct rpc_task *, void *); |
| 79 | static void rpcb_map_release(void *data); | 110 | static void rpcb_map_release(void *data); |
| 80 | static struct rpc_program rpcb_program; | 111 | static struct rpc_program rpcb_program; |
| @@ -122,6 +153,7 @@ static void rpcb_map_release(void *data) | |||
| 122 | 153 | ||
| 123 | rpcb_wake_rpcbind_waiters(map->r_xprt, map->r_status); | 154 | rpcb_wake_rpcbind_waiters(map->r_xprt, map->r_status); |
| 124 | xprt_put(map->r_xprt); | 155 | xprt_put(map->r_xprt); |
| 156 | kfree(map->r_addr); | ||
| 125 | kfree(map); | 157 | kfree(map); |
| 126 | } | 158 | } |
| 127 | 159 | ||
| @@ -268,12 +300,9 @@ static int rpcb_register_inet4(const struct sockaddr *sap, | |||
| 268 | const struct sockaddr_in *sin = (const struct sockaddr_in *)sap; | 300 | const struct sockaddr_in *sin = (const struct sockaddr_in *)sap; |
| 269 | struct rpcbind_args *map = msg->rpc_argp; | 301 | struct rpcbind_args *map = msg->rpc_argp; |
| 270 | unsigned short port = ntohs(sin->sin_port); | 302 | unsigned short port = ntohs(sin->sin_port); |
| 271 | char buf[32]; | 303 | int result; |
| 272 | 304 | ||
| 273 | /* Construct AF_INET universal address */ | 305 | map->r_addr = rpc_sockaddr2uaddr(sap); |
| 274 | snprintf(buf, sizeof(buf), "%pI4.%u.%u", | ||
| 275 | &sin->sin_addr.s_addr, port >> 8, port & 0xff); | ||
| 276 | map->r_addr = buf; | ||
| 277 | 306 | ||
| 278 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " | 307 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " |
| 279 | "local rpcbind\n", (port ? "" : "un"), | 308 | "local rpcbind\n", (port ? "" : "un"), |
| @@ -284,7 +313,9 @@ static int rpcb_register_inet4(const struct sockaddr *sap, | |||
| 284 | if (port) | 313 | if (port) |
| 285 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; | 314 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; |
| 286 | 315 | ||
| 287 | return rpcb_register_call(RPCBVERS_4, msg); | 316 | result = rpcb_register_call(RPCBVERS_4, msg); |
| 317 | kfree(map->r_addr); | ||
| 318 | return result; | ||
| 288 | } | 319 | } |
| 289 | 320 | ||
| 290 | /* | 321 | /* |
| @@ -296,16 +327,9 @@ static int rpcb_register_inet6(const struct sockaddr *sap, | |||
| 296 | const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap; | 327 | const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap; |
| 297 | struct rpcbind_args *map = msg->rpc_argp; | 328 | struct rpcbind_args *map = msg->rpc_argp; |
| 298 | unsigned short port = ntohs(sin6->sin6_port); | 329 | unsigned short port = ntohs(sin6->sin6_port); |
| 299 | char buf[64]; | 330 | int result; |
| 300 | 331 | ||
| 301 | /* Construct AF_INET6 universal address */ | 332 | map->r_addr = rpc_sockaddr2uaddr(sap); |
| 302 | if (ipv6_addr_any(&sin6->sin6_addr)) | ||
| 303 | snprintf(buf, sizeof(buf), "::.%u.%u", | ||
| 304 | port >> 8, port & 0xff); | ||
| 305 | else | ||
| 306 | snprintf(buf, sizeof(buf), "%pI6.%u.%u", | ||
| 307 | &sin6->sin6_addr, port >> 8, port & 0xff); | ||
| 308 | map->r_addr = buf; | ||
| 309 | 333 | ||
| 310 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " | 334 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " |
| 311 | "local rpcbind\n", (port ? "" : "un"), | 335 | "local rpcbind\n", (port ? "" : "un"), |
| @@ -316,7 +340,9 @@ static int rpcb_register_inet6(const struct sockaddr *sap, | |||
| 316 | if (port) | 340 | if (port) |
| 317 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; | 341 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; |
| 318 | 342 | ||
| 319 | return rpcb_register_call(RPCBVERS_4, msg); | 343 | result = rpcb_register_call(RPCBVERS_4, msg); |
| 344 | kfree(map->r_addr); | ||
| 345 | return result; | ||
| 320 | } | 346 | } |
| 321 | 347 | ||
| 322 | static int rpcb_unregister_all_protofamilies(struct rpc_message *msg) | 348 | static int rpcb_unregister_all_protofamilies(struct rpc_message *msg) |
| @@ -428,7 +454,7 @@ int rpcb_getport_sync(struct sockaddr_in *sin, u32 prog, u32 vers, int prot) | |||
| 428 | struct rpc_message msg = { | 454 | struct rpc_message msg = { |
| 429 | .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT], | 455 | .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT], |
| 430 | .rpc_argp = &map, | 456 | .rpc_argp = &map, |
| 431 | .rpc_resp = &map.r_port, | 457 | .rpc_resp = &map, |
| 432 | }; | 458 | }; |
| 433 | struct rpc_clnt *rpcb_clnt; | 459 | struct rpc_clnt *rpcb_clnt; |
| 434 | int status; | 460 | int status; |
| @@ -458,7 +484,7 @@ static struct rpc_task *rpcb_call_async(struct rpc_clnt *rpcb_clnt, struct rpcbi | |||
| 458 | struct rpc_message msg = { | 484 | struct rpc_message msg = { |
| 459 | .rpc_proc = proc, | 485 | .rpc_proc = proc, |
| 460 | .rpc_argp = map, | 486 | .rpc_argp = map, |
| 461 | .rpc_resp = &map->r_port, | 487 | .rpc_resp = map, |
| 462 | }; | 488 | }; |
| 463 | struct rpc_task_setup task_setup_data = { | 489 | struct rpc_task_setup task_setup_data = { |
| 464 | .rpc_client = rpcb_clnt, | 490 | .rpc_client = rpcb_clnt, |
| @@ -539,6 +565,7 @@ void rpcb_getport_async(struct rpc_task *task) | |||
| 539 | goto bailout_nofree; | 565 | goto bailout_nofree; |
| 540 | } | 566 | } |
| 541 | 567 | ||
| 568 | /* Parent transport's destination address */ | ||
| 542 | salen = rpc_peeraddr(clnt, sap, sizeof(addr)); | 569 | salen = rpc_peeraddr(clnt, sap, sizeof(addr)); |
| 543 | 570 | ||
| 544 | /* Don't ever use rpcbind v2 for AF_INET6 requests */ | 571 | /* Don't ever use rpcbind v2 for AF_INET6 requests */ |
| @@ -589,11 +616,22 @@ void rpcb_getport_async(struct rpc_task *task) | |||
| 589 | map->r_prot = xprt->prot; | 616 | map->r_prot = xprt->prot; |
| 590 | map->r_port = 0; | 617 | map->r_port = 0; |
| 591 | map->r_xprt = xprt_get(xprt); | 618 | map->r_xprt = xprt_get(xprt); |
| 592 | map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID); | ||
| 593 | map->r_addr = rpc_peeraddr2str(rpcb_clnt, RPC_DISPLAY_UNIVERSAL_ADDR); | ||
| 594 | map->r_owner = ""; | ||
| 595 | map->r_status = -EIO; | 619 | map->r_status = -EIO; |
| 596 | 620 | ||
| 621 | switch (bind_version) { | ||
| 622 | case RPCBVERS_4: | ||
| 623 | case RPCBVERS_3: | ||
| 624 | map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID); | ||
| 625 | map->r_addr = rpc_sockaddr2uaddr(sap); | ||
| 626 | map->r_owner = ""; | ||
| 627 | break; | ||
| 628 | case RPCBVERS_2: | ||
| 629 | map->r_addr = NULL; | ||
| 630 | break; | ||
| 631 | default: | ||
| 632 | BUG(); | ||
| 633 | } | ||
| 634 | |||
| 597 | child = rpcb_call_async(rpcb_clnt, map, proc); | 635 | child = rpcb_call_async(rpcb_clnt, map, proc); |
| 598 | rpc_release_client(rpcb_clnt); | 636 | rpc_release_client(rpcb_clnt); |
| 599 | if (IS_ERR(child)) { | 637 | if (IS_ERR(child)) { |
| @@ -656,176 +694,278 @@ static void rpcb_getport_done(struct rpc_task *child, void *data) | |||
| 656 | * XDR functions for rpcbind | 694 | * XDR functions for rpcbind |
| 657 | */ | 695 | */ |
| 658 | 696 | ||
| 659 | static int rpcb_encode_mapping(struct rpc_rqst *req, __be32 *p, | 697 | static int rpcb_enc_mapping(struct rpc_rqst *req, __be32 *p, |
| 660 | struct rpcbind_args *rpcb) | 698 | const struct rpcbind_args *rpcb) |
| 661 | { | 699 | { |
| 662 | dprintk("RPC: encoding rpcb request (%u, %u, %d, %u)\n", | 700 | struct rpc_task *task = req->rq_task; |
| 701 | struct xdr_stream xdr; | ||
| 702 | |||
| 703 | dprintk("RPC: %5u encoding PMAP_%s call (%u, %u, %d, %u)\n", | ||
| 704 | task->tk_pid, task->tk_msg.rpc_proc->p_name, | ||
| 663 | rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port); | 705 | rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port); |
| 706 | |||
| 707 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | ||
| 708 | |||
| 709 | p = xdr_reserve_space(&xdr, sizeof(__be32) * RPCB_mappingargs_sz); | ||
| 710 | if (unlikely(p == NULL)) | ||
| 711 | return -EIO; | ||
| 712 | |||
| 664 | *p++ = htonl(rpcb->r_prog); | 713 | *p++ = htonl(rpcb->r_prog); |
| 665 | *p++ = htonl(rpcb->r_vers); | 714 | *p++ = htonl(rpcb->r_vers); |
| 666 | *p++ = htonl(rpcb->r_prot); | 715 | *p++ = htonl(rpcb->r_prot); |
| 667 | *p++ = htonl(rpcb->r_port); | 716 | *p = htonl(rpcb->r_port); |
| 668 | 717 | ||
| 669 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
| 670 | return 0; | 718 | return 0; |
| 671 | } | 719 | } |
| 672 | 720 | ||
| 673 | static int rpcb_decode_getport(struct rpc_rqst *req, __be32 *p, | 721 | static int rpcb_dec_getport(struct rpc_rqst *req, __be32 *p, |
| 674 | unsigned short *portp) | 722 | struct rpcbind_args *rpcb) |
| 675 | { | 723 | { |
| 676 | *portp = (unsigned short) ntohl(*p++); | 724 | struct rpc_task *task = req->rq_task; |
| 677 | dprintk("RPC: rpcb getport result: %u\n", | 725 | struct xdr_stream xdr; |
| 678 | *portp); | 726 | unsigned long port; |
| 727 | |||
| 728 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | ||
| 729 | |||
| 730 | rpcb->r_port = 0; | ||
| 731 | |||
| 732 | p = xdr_inline_decode(&xdr, sizeof(__be32)); | ||
| 733 | if (unlikely(p == NULL)) | ||
| 734 | return -EIO; | ||
| 735 | |||
| 736 | port = ntohl(*p); | ||
| 737 | dprintk("RPC: %5u PMAP_%s result: %lu\n", task->tk_pid, | ||
| 738 | task->tk_msg.rpc_proc->p_name, port); | ||
| 739 | if (unlikely(port > USHORT_MAX)) | ||
| 740 | return -EIO; | ||
| 741 | |||
| 742 | rpcb->r_port = port; | ||
| 679 | return 0; | 743 | return 0; |
| 680 | } | 744 | } |
| 681 | 745 | ||
| 682 | static int rpcb_decode_set(struct rpc_rqst *req, __be32 *p, | 746 | static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p, |
| 683 | unsigned int *boolp) | 747 | unsigned int *boolp) |
| 684 | { | 748 | { |
| 685 | *boolp = (unsigned int) ntohl(*p++); | 749 | struct rpc_task *task = req->rq_task; |
| 686 | dprintk("RPC: rpcb set/unset call %s\n", | 750 | struct xdr_stream xdr; |
| 751 | |||
| 752 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | ||
| 753 | |||
| 754 | p = xdr_inline_decode(&xdr, sizeof(__be32)); | ||
| 755 | if (unlikely(p == NULL)) | ||
| 756 | return -EIO; | ||
| 757 | |||
| 758 | *boolp = 0; | ||
| 759 | if (*p) | ||
| 760 | *boolp = 1; | ||
| 761 | |||
| 762 | dprintk("RPC: %5u RPCB_%s call %s\n", | ||
| 763 | task->tk_pid, task->tk_msg.rpc_proc->p_name, | ||
| 687 | (*boolp ? "succeeded" : "failed")); | 764 | (*boolp ? "succeeded" : "failed")); |
| 688 | return 0; | 765 | return 0; |
| 689 | } | 766 | } |
| 690 | 767 | ||
| 691 | static int rpcb_encode_getaddr(struct rpc_rqst *req, __be32 *p, | 768 | static int encode_rpcb_string(struct xdr_stream *xdr, const char *string, |
| 692 | struct rpcbind_args *rpcb) | 769 | const u32 maxstrlen) |
| 693 | { | 770 | { |
| 694 | dprintk("RPC: encoding rpcb request (%u, %u, %s)\n", | 771 | u32 len; |
| 695 | rpcb->r_prog, rpcb->r_vers, rpcb->r_addr); | 772 | __be32 *p; |
| 696 | *p++ = htonl(rpcb->r_prog); | ||
| 697 | *p++ = htonl(rpcb->r_vers); | ||
| 698 | 773 | ||
| 699 | p = xdr_encode_string(p, rpcb->r_netid); | 774 | if (unlikely(string == NULL)) |
| 700 | p = xdr_encode_string(p, rpcb->r_addr); | 775 | return -EIO; |
| 701 | p = xdr_encode_string(p, rpcb->r_owner); | 776 | len = strlen(string); |
| 777 | if (unlikely(len > maxstrlen)) | ||
| 778 | return -EIO; | ||
| 702 | 779 | ||
| 703 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 780 | p = xdr_reserve_space(xdr, sizeof(__be32) + len); |
| 781 | if (unlikely(p == NULL)) | ||
| 782 | return -EIO; | ||
| 783 | xdr_encode_opaque(p, string, len); | ||
| 704 | 784 | ||
| 705 | return 0; | 785 | return 0; |
| 706 | } | 786 | } |
| 707 | 787 | ||
| 708 | static int rpcb_decode_getaddr(struct rpc_rqst *req, __be32 *p, | 788 | static int rpcb_enc_getaddr(struct rpc_rqst *req, __be32 *p, |
| 709 | unsigned short *portp) | 789 | const struct rpcbind_args *rpcb) |
| 710 | { | 790 | { |
| 711 | char *addr; | 791 | struct rpc_task *task = req->rq_task; |
| 712 | u32 addr_len; | 792 | struct xdr_stream xdr; |
| 713 | int c, i, f, first, val; | ||
| 714 | 793 | ||
| 715 | *portp = 0; | 794 | dprintk("RPC: %5u encoding RPCB_%s call (%u, %u, '%s', '%s')\n", |
| 716 | addr_len = ntohl(*p++); | 795 | task->tk_pid, task->tk_msg.rpc_proc->p_name, |
| 796 | rpcb->r_prog, rpcb->r_vers, | ||
| 797 | rpcb->r_netid, rpcb->r_addr); | ||
| 717 | 798 | ||
| 718 | if (addr_len == 0) { | 799 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 719 | dprintk("RPC: rpcb_decode_getaddr: " | ||
| 720 | "service is not registered\n"); | ||
| 721 | return 0; | ||
| 722 | } | ||
| 723 | 800 | ||
| 724 | /* | 801 | p = xdr_reserve_space(&xdr, |
| 725 | * Simple sanity check. | 802 | sizeof(__be32) * (RPCB_program_sz + RPCB_version_sz)); |
| 726 | */ | 803 | if (unlikely(p == NULL)) |
| 727 | if (addr_len > RPCBIND_MAXUADDRLEN) | 804 | return -EIO; |
| 728 | goto out_err; | 805 | *p++ = htonl(rpcb->r_prog); |
| 729 | 806 | *p = htonl(rpcb->r_vers); | |
| 730 | /* | ||
| 731 | * Start at the end and walk backwards until the first dot | ||
| 732 | * is encountered. When the second dot is found, we have | ||
| 733 | * both parts of the port number. | ||
| 734 | */ | ||
| 735 | addr = (char *)p; | ||
| 736 | val = 0; | ||
| 737 | first = 1; | ||
| 738 | f = 1; | ||
| 739 | for (i = addr_len - 1; i > 0; i--) { | ||
| 740 | c = addr[i]; | ||
| 741 | if (c >= '0' && c <= '9') { | ||
| 742 | val += (c - '0') * f; | ||
| 743 | f *= 10; | ||
| 744 | } else if (c == '.') { | ||
| 745 | if (first) { | ||
| 746 | *portp = val; | ||
| 747 | val = first = 0; | ||
| 748 | f = 1; | ||
| 749 | } else { | ||
| 750 | *portp |= (val << 8); | ||
| 751 | break; | ||
| 752 | } | ||
| 753 | } | ||
| 754 | } | ||
| 755 | 807 | ||
| 756 | /* | 808 | if (encode_rpcb_string(&xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN)) |
| 757 | * Simple sanity check. If we never saw a dot in the reply, | 809 | return -EIO; |
| 758 | * then this was probably just garbage. | 810 | if (encode_rpcb_string(&xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN)) |
| 759 | */ | 811 | return -EIO; |
| 760 | if (first) | 812 | if (encode_rpcb_string(&xdr, rpcb->r_owner, RPCB_MAXOWNERLEN)) |
| 761 | goto out_err; | 813 | return -EIO; |
| 762 | 814 | ||
| 763 | dprintk("RPC: rpcb_decode_getaddr port=%u\n", *portp); | ||
| 764 | return 0; | 815 | return 0; |
| 765 | |||
| 766 | out_err: | ||
| 767 | dprintk("RPC: rpcbind server returned malformed reply\n"); | ||
| 768 | return -EIO; | ||
| 769 | } | 816 | } |
| 770 | 817 | ||
| 771 | #define RPCB_program_sz (1u) | 818 | static int rpcb_dec_getaddr(struct rpc_rqst *req, __be32 *p, |
| 772 | #define RPCB_version_sz (1u) | 819 | struct rpcbind_args *rpcb) |
| 773 | #define RPCB_protocol_sz (1u) | 820 | { |
| 774 | #define RPCB_port_sz (1u) | 821 | struct sockaddr_storage address; |
| 775 | #define RPCB_boolean_sz (1u) | 822 | struct sockaddr *sap = (struct sockaddr *)&address; |
| 823 | struct rpc_task *task = req->rq_task; | ||
| 824 | struct xdr_stream xdr; | ||
| 825 | u32 len; | ||
| 776 | 826 | ||
| 777 | #define RPCB_netid_sz (1+XDR_QUADLEN(RPCBIND_MAXNETIDLEN)) | 827 | rpcb->r_port = 0; |
| 778 | #define RPCB_addr_sz (1+XDR_QUADLEN(RPCBIND_MAXUADDRLEN)) | ||
| 779 | #define RPCB_ownerstring_sz (1+XDR_QUADLEN(RPCB_MAXOWNERLEN)) | ||
| 780 | 828 | ||
| 781 | #define RPCB_mappingargs_sz RPCB_program_sz+RPCB_version_sz+ \ | 829 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 782 | RPCB_protocol_sz+RPCB_port_sz | ||
| 783 | #define RPCB_getaddrargs_sz RPCB_program_sz+RPCB_version_sz+ \ | ||
| 784 | RPCB_netid_sz+RPCB_addr_sz+ \ | ||
| 785 | RPCB_ownerstring_sz | ||
| 786 | 830 | ||
| 787 | #define RPCB_setres_sz RPCB_boolean_sz | 831 | p = xdr_inline_decode(&xdr, sizeof(__be32)); |
| 788 | #define RPCB_getportres_sz RPCB_port_sz | 832 | if (unlikely(p == NULL)) |
| 789 | 833 | goto out_fail; | |
| 790 | /* | 834 | len = ntohl(*p); |
| 791 | * Note that RFC 1833 does not put any size restrictions on the | ||
| 792 | * address string returned by the remote rpcbind database. | ||
| 793 | */ | ||
| 794 | #define RPCB_getaddrres_sz RPCB_addr_sz | ||
| 795 | 835 | ||
| 796 | #define PROC(proc, argtype, restype) \ | 836 | /* |
| 797 | [RPCBPROC_##proc] = { \ | 837 | * If the returned universal address is a null string, |
| 798 | .p_proc = RPCBPROC_##proc, \ | 838 | * the requested RPC service was not registered. |
| 799 | .p_encode = (kxdrproc_t) rpcb_encode_##argtype, \ | 839 | */ |
| 800 | .p_decode = (kxdrproc_t) rpcb_decode_##restype, \ | 840 | if (len == 0) { |
| 801 | .p_arglen = RPCB_##argtype##args_sz, \ | 841 | dprintk("RPC: %5u RPCB reply: program not registered\n", |
| 802 | .p_replen = RPCB_##restype##res_sz, \ | 842 | task->tk_pid); |
| 803 | .p_statidx = RPCBPROC_##proc, \ | 843 | return 0; |
| 804 | .p_timer = 0, \ | ||
| 805 | .p_name = #proc, \ | ||
| 806 | } | 844 | } |
| 807 | 845 | ||
| 846 | if (unlikely(len > RPCBIND_MAXUADDRLEN)) | ||
| 847 | goto out_fail; | ||
| 848 | |||
| 849 | p = xdr_inline_decode(&xdr, len); | ||
| 850 | if (unlikely(p == NULL)) | ||
| 851 | goto out_fail; | ||
| 852 | dprintk("RPC: %5u RPCB_%s reply: %s\n", task->tk_pid, | ||
| 853 | task->tk_msg.rpc_proc->p_name, (char *)p); | ||
| 854 | |||
| 855 | if (rpc_uaddr2sockaddr((char *)p, len, sap, sizeof(address)) == 0) | ||
| 856 | goto out_fail; | ||
| 857 | rpcb->r_port = rpc_get_port(sap); | ||
| 858 | |||
| 859 | return 0; | ||
| 860 | |||
| 861 | out_fail: | ||
| 862 | dprintk("RPC: %5u malformed RPCB_%s reply\n", | ||
| 863 | task->tk_pid, task->tk_msg.rpc_proc->p_name); | ||
| 864 | return -EIO; | ||
| 865 | } | ||
| 866 | |||
| 808 | /* | 867 | /* |
| 809 | * Not all rpcbind procedures described in RFC 1833 are implemented | 868 | * Not all rpcbind procedures described in RFC 1833 are implemented |
| 810 | * since the Linux kernel RPC code requires only these. | 869 | * since the Linux kernel RPC code requires only these. |
| 811 | */ | 870 | */ |
| 871 | |||
| 812 | static struct rpc_procinfo rpcb_procedures2[] = { | 872 | static struct rpc_procinfo rpcb_procedures2[] = { |
| 813 | PROC(SET, mapping, set), | 873 | [RPCBPROC_SET] = { |
| 814 | PROC(UNSET, mapping, set), | 874 | .p_proc = RPCBPROC_SET, |
| 815 | PROC(GETPORT, mapping, getport), | 875 | .p_encode = (kxdrproc_t)rpcb_enc_mapping, |
| 876 | .p_decode = (kxdrproc_t)rpcb_dec_set, | ||
| 877 | .p_arglen = RPCB_mappingargs_sz, | ||
| 878 | .p_replen = RPCB_setres_sz, | ||
| 879 | .p_statidx = RPCBPROC_SET, | ||
| 880 | .p_timer = 0, | ||
| 881 | .p_name = "SET", | ||
| 882 | }, | ||
| 883 | [RPCBPROC_UNSET] = { | ||
| 884 | .p_proc = RPCBPROC_UNSET, | ||
| 885 | .p_encode = (kxdrproc_t)rpcb_enc_mapping, | ||
| 886 | .p_decode = (kxdrproc_t)rpcb_dec_set, | ||
| 887 | .p_arglen = RPCB_mappingargs_sz, | ||
| 888 | .p_replen = RPCB_setres_sz, | ||
| 889 | .p_statidx = RPCBPROC_UNSET, | ||
| 890 | .p_timer = 0, | ||
| 891 | .p_name = "UNSET", | ||
| 892 | }, | ||
| 893 | [RPCBPROC_GETPORT] = { | ||
| 894 | .p_proc = RPCBPROC_GETPORT, | ||
| 895 | .p_encode = (kxdrproc_t)rpcb_enc_mapping, | ||
| 896 | .p_decode = (kxdrproc_t)rpcb_dec_getport, | ||
| 897 | .p_arglen = RPCB_mappingargs_sz, | ||
| 898 | .p_replen = RPCB_getportres_sz, | ||
| 899 | .p_statidx = RPCBPROC_GETPORT, | ||
| 900 | .p_timer = 0, | ||
| 901 | .p_name = "GETPORT", | ||
| 902 | }, | ||
| 816 | }; | 903 | }; |
| 817 | 904 | ||
| 818 | static struct rpc_procinfo rpcb_procedures3[] = { | 905 | static struct rpc_procinfo rpcb_procedures3[] = { |
| 819 | PROC(SET, getaddr, set), | 906 | [RPCBPROC_SET] = { |
| 820 | PROC(UNSET, getaddr, set), | 907 | .p_proc = RPCBPROC_SET, |
| 821 | PROC(GETADDR, getaddr, getaddr), | 908 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, |
| 909 | .p_decode = (kxdrproc_t)rpcb_dec_set, | ||
| 910 | .p_arglen = RPCB_getaddrargs_sz, | ||
| 911 | .p_replen = RPCB_setres_sz, | ||
| 912 | .p_statidx = RPCBPROC_SET, | ||
| 913 | .p_timer = 0, | ||
| 914 | .p_name = "SET", | ||
| 915 | }, | ||
| 916 | [RPCBPROC_UNSET] = { | ||
| 917 | .p_proc = RPCBPROC_UNSET, | ||
| 918 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, | ||
| 919 | .p_decode = (kxdrproc_t)rpcb_dec_set, | ||
| 920 | .p_arglen = RPCB_getaddrargs_sz, | ||
| 921 | .p_replen = RPCB_setres_sz, | ||
| 922 | .p_statidx = RPCBPROC_UNSET, | ||
| 923 | .p_timer = 0, | ||
| 924 | .p_name = "UNSET", | ||
| 925 | }, | ||
| 926 | [RPCBPROC_GETADDR] = { | ||
| 927 | .p_proc = RPCBPROC_GETADDR, | ||
| 928 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, | ||
| 929 | .p_decode = (kxdrproc_t)rpcb_dec_getaddr, | ||
| 930 | .p_arglen = RPCB_getaddrargs_sz, | ||
| 931 | .p_replen = RPCB_getaddrres_sz, | ||
| 932 | .p_statidx = RPCBPROC_GETADDR, | ||
| 933 | .p_timer = 0, | ||
| 934 | .p_name = "GETADDR", | ||
| 935 | }, | ||
| 822 | }; | 936 | }; |
| 823 | 937 | ||
| 824 | static struct rpc_procinfo rpcb_procedures4[] = { | 938 | static struct rpc_procinfo rpcb_procedures4[] = { |
| 825 | PROC(SET, getaddr, set), | 939 | [RPCBPROC_SET] = { |
| 826 | PROC(UNSET, getaddr, set), | 940 | .p_proc = RPCBPROC_SET, |
| 827 | PROC(GETADDR, getaddr, getaddr), | 941 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, |
| 828 | PROC(GETVERSADDR, getaddr, getaddr), | 942 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
| 943 | .p_arglen = RPCB_getaddrargs_sz, | ||
| 944 | .p_replen = RPCB_setres_sz, | ||
| 945 | .p_statidx = RPCBPROC_SET, | ||
| 946 | .p_timer = 0, | ||
| 947 | .p_name = "SET", | ||
| 948 | }, | ||
| 949 | [RPCBPROC_UNSET] = { | ||
| 950 | .p_proc = RPCBPROC_UNSET, | ||
| 951 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, | ||
| 952 | .p_decode = (kxdrproc_t)rpcb_dec_set, | ||
| 953 | .p_arglen = RPCB_getaddrargs_sz, | ||
| 954 | .p_replen = RPCB_setres_sz, | ||
| 955 | .p_statidx = RPCBPROC_UNSET, | ||
| 956 | .p_timer = 0, | ||
| 957 | .p_name = "UNSET", | ||
| 958 | }, | ||
| 959 | [RPCBPROC_GETADDR] = { | ||
| 960 | .p_proc = RPCBPROC_GETADDR, | ||
| 961 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, | ||
| 962 | .p_decode = (kxdrproc_t)rpcb_dec_getaddr, | ||
| 963 | .p_arglen = RPCB_getaddrargs_sz, | ||
| 964 | .p_replen = RPCB_getaddrres_sz, | ||
| 965 | .p_statidx = RPCBPROC_GETADDR, | ||
| 966 | .p_timer = 0, | ||
| 967 | .p_name = "GETADDR", | ||
| 968 | }, | ||
| 829 | }; | 969 | }; |
| 830 | 970 | ||
| 831 | static struct rpcb_info rpcb_next_version[] = { | 971 | static struct rpcb_info rpcb_next_version[] = { |
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index 5c865e2d299e..6caffa34ac01 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c | |||
| @@ -171,6 +171,11 @@ static void ip_map_request(struct cache_detail *cd, | |||
| 171 | (*bpp)[-1] = '\n'; | 171 | (*bpp)[-1] = '\n'; |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | static int ip_map_upcall(struct cache_detail *cd, struct cache_head *h) | ||
| 175 | { | ||
| 176 | return sunrpc_cache_pipe_upcall(cd, h, ip_map_request); | ||
| 177 | } | ||
| 178 | |||
| 174 | static struct ip_map *ip_map_lookup(char *class, struct in6_addr *addr); | 179 | static struct ip_map *ip_map_lookup(char *class, struct in6_addr *addr); |
| 175 | static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry); | 180 | static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry); |
| 176 | 181 | ||
| @@ -289,7 +294,7 @@ struct cache_detail ip_map_cache = { | |||
| 289 | .hash_table = ip_table, | 294 | .hash_table = ip_table, |
| 290 | .name = "auth.unix.ip", | 295 | .name = "auth.unix.ip", |
| 291 | .cache_put = ip_map_put, | 296 | .cache_put = ip_map_put, |
| 292 | .cache_request = ip_map_request, | 297 | .cache_upcall = ip_map_upcall, |
| 293 | .cache_parse = ip_map_parse, | 298 | .cache_parse = ip_map_parse, |
| 294 | .cache_show = ip_map_show, | 299 | .cache_show = ip_map_show, |
| 295 | .match = ip_map_match, | 300 | .match = ip_map_match, |
| @@ -523,6 +528,11 @@ static void unix_gid_request(struct cache_detail *cd, | |||
| 523 | (*bpp)[-1] = '\n'; | 528 | (*bpp)[-1] = '\n'; |
| 524 | } | 529 | } |
| 525 | 530 | ||
| 531 | static int unix_gid_upcall(struct cache_detail *cd, struct cache_head *h) | ||
| 532 | { | ||
| 533 | return sunrpc_cache_pipe_upcall(cd, h, unix_gid_request); | ||
| 534 | } | ||
| 535 | |||
| 526 | static struct unix_gid *unix_gid_lookup(uid_t uid); | 536 | static struct unix_gid *unix_gid_lookup(uid_t uid); |
| 527 | extern struct cache_detail unix_gid_cache; | 537 | extern struct cache_detail unix_gid_cache; |
| 528 | 538 | ||
| @@ -622,7 +632,7 @@ struct cache_detail unix_gid_cache = { | |||
| 622 | .hash_table = gid_table, | 632 | .hash_table = gid_table, |
| 623 | .name = "auth.unix.gid", | 633 | .name = "auth.unix.gid", |
| 624 | .cache_put = unix_gid_put, | 634 | .cache_put = unix_gid_put, |
| 625 | .cache_request = unix_gid_request, | 635 | .cache_upcall = unix_gid_upcall, |
| 626 | .cache_parse = unix_gid_parse, | 636 | .cache_parse = unix_gid_parse, |
| 627 | .cache_show = unix_gid_show, | 637 | .cache_show = unix_gid_show, |
| 628 | .match = unix_gid_match, | 638 | .match = unix_gid_match, |
diff --git a/net/sunrpc/timer.c b/net/sunrpc/timer.c index 31becbf09263..dd824341c349 100644 --- a/net/sunrpc/timer.c +++ b/net/sunrpc/timer.c | |||
| @@ -25,8 +25,13 @@ | |||
| 25 | #define RPC_RTO_INIT (HZ/5) | 25 | #define RPC_RTO_INIT (HZ/5) |
| 26 | #define RPC_RTO_MIN (HZ/10) | 26 | #define RPC_RTO_MIN (HZ/10) |
| 27 | 27 | ||
| 28 | void | 28 | /** |
| 29 | rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo) | 29 | * rpc_init_rtt - Initialize an RPC RTT estimator context |
| 30 | * @rt: context to initialize | ||
| 31 | * @timeo: initial timeout value, in jiffies | ||
| 32 | * | ||
| 33 | */ | ||
| 34 | void rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo) | ||
| 30 | { | 35 | { |
| 31 | unsigned long init = 0; | 36 | unsigned long init = 0; |
| 32 | unsigned i; | 37 | unsigned i; |
| @@ -43,12 +48,16 @@ rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo) | |||
| 43 | } | 48 | } |
| 44 | EXPORT_SYMBOL_GPL(rpc_init_rtt); | 49 | EXPORT_SYMBOL_GPL(rpc_init_rtt); |
| 45 | 50 | ||
| 46 | /* | 51 | /** |
| 52 | * rpc_update_rtt - Update an RPC RTT estimator context | ||
| 53 | * @rt: context to update | ||
| 54 | * @timer: timer array index (request type) | ||
| 55 | * @m: recent actual RTT, in jiffies | ||
| 56 | * | ||
| 47 | * NB: When computing the smoothed RTT and standard deviation, | 57 | * NB: When computing the smoothed RTT and standard deviation, |
| 48 | * be careful not to produce negative intermediate results. | 58 | * be careful not to produce negative intermediate results. |
| 49 | */ | 59 | */ |
| 50 | void | 60 | void rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m) |
| 51 | rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m) | ||
| 52 | { | 61 | { |
| 53 | long *srtt, *sdrtt; | 62 | long *srtt, *sdrtt; |
| 54 | 63 | ||
| @@ -79,21 +88,25 @@ rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m) | |||
| 79 | } | 88 | } |
| 80 | EXPORT_SYMBOL_GPL(rpc_update_rtt); | 89 | EXPORT_SYMBOL_GPL(rpc_update_rtt); |
| 81 | 90 | ||
| 82 | /* | 91 | /** |
| 83 | * Estimate rto for an nfs rpc sent via. an unreliable datagram. | 92 | * rpc_calc_rto - Provide an estimated timeout value |
| 84 | * Use the mean and mean deviation of rtt for the appropriate type of rpc | 93 | * @rt: context to use for calculation |
| 85 | * for the frequent rpcs and a default for the others. | 94 | * @timer: timer array index (request type) |
| 86 | * The justification for doing "other" this way is that these rpcs | 95 | * |
| 87 | * happen so infrequently that timer est. would probably be stale. | 96 | * Estimate RTO for an NFS RPC sent via an unreliable datagram. Use |
| 88 | * Also, since many of these rpcs are | 97 | * the mean and mean deviation of RTT for the appropriate type of RPC |
| 89 | * non-idempotent, a conservative timeout is desired. | 98 | * for frequently issued RPCs, and a fixed default for the others. |
| 99 | * | ||
| 100 | * The justification for doing "other" this way is that these RPCs | ||
| 101 | * happen so infrequently that timer estimation would probably be | ||
| 102 | * stale. Also, since many of these RPCs are non-idempotent, a | ||
| 103 | * conservative timeout is desired. | ||
| 104 | * | ||
| 90 | * getattr, lookup, | 105 | * getattr, lookup, |
| 91 | * read, write, commit - A+4D | 106 | * read, write, commit - A+4D |
| 92 | * other - timeo | 107 | * other - timeo |
| 93 | */ | 108 | */ |
| 94 | 109 | unsigned long rpc_calc_rto(struct rpc_rtt *rt, unsigned timer) | |
| 95 | unsigned long | ||
| 96 | rpc_calc_rto(struct rpc_rtt *rt, unsigned timer) | ||
| 97 | { | 110 | { |
| 98 | unsigned long res; | 111 | unsigned long res; |
| 99 | 112 | ||
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c index 1dd6123070e9..9a63f669ece4 100644 --- a/net/sunrpc/xprtrdma/transport.c +++ b/net/sunrpc/xprtrdma/transport.c | |||
| @@ -168,47 +168,25 @@ static struct rpc_xprt_ops xprt_rdma_procs; /* forward reference */ | |||
| 168 | static void | 168 | static void |
| 169 | xprt_rdma_format_addresses(struct rpc_xprt *xprt) | 169 | xprt_rdma_format_addresses(struct rpc_xprt *xprt) |
| 170 | { | 170 | { |
| 171 | struct sockaddr_in *addr = (struct sockaddr_in *) | 171 | struct sockaddr *sap = (struct sockaddr *) |
| 172 | &rpcx_to_rdmad(xprt).addr; | 172 | &rpcx_to_rdmad(xprt).addr; |
| 173 | char *buf; | 173 | struct sockaddr_in *sin = (struct sockaddr_in *)sap; |
| 174 | char buf[64]; | ||
| 174 | 175 | ||
| 175 | buf = kzalloc(20, GFP_KERNEL); | 176 | (void)rpc_ntop(sap, buf, sizeof(buf)); |
| 176 | if (buf) | 177 | xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL); |
| 177 | snprintf(buf, 20, "%pI4", &addr->sin_addr.s_addr); | ||
| 178 | xprt->address_strings[RPC_DISPLAY_ADDR] = buf; | ||
| 179 | 178 | ||
| 180 | buf = kzalloc(8, GFP_KERNEL); | 179 | (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap)); |
| 181 | if (buf) | 180 | xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL); |
| 182 | snprintf(buf, 8, "%u", ntohs(addr->sin_port)); | ||
| 183 | xprt->address_strings[RPC_DISPLAY_PORT] = buf; | ||
| 184 | 181 | ||
| 185 | xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma"; | 182 | xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma"; |
| 186 | 183 | ||
| 187 | buf = kzalloc(48, GFP_KERNEL); | 184 | (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x", |
| 188 | if (buf) | 185 | NIPQUAD(sin->sin_addr.s_addr)); |
| 189 | snprintf(buf, 48, "addr=%pI4 port=%u proto=%s", | 186 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL); |
| 190 | &addr->sin_addr.s_addr, | 187 | |
| 191 | ntohs(addr->sin_port), "rdma"); | 188 | (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap)); |
| 192 | xprt->address_strings[RPC_DISPLAY_ALL] = buf; | 189 | xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL); |
| 193 | |||
| 194 | buf = kzalloc(10, GFP_KERNEL); | ||
| 195 | if (buf) | ||
| 196 | snprintf(buf, 10, "%02x%02x%02x%02x", | ||
| 197 | NIPQUAD(addr->sin_addr.s_addr)); | ||
| 198 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf; | ||
| 199 | |||
| 200 | buf = kzalloc(8, GFP_KERNEL); | ||
| 201 | if (buf) | ||
| 202 | snprintf(buf, 8, "%4hx", ntohs(addr->sin_port)); | ||
| 203 | xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf; | ||
| 204 | |||
| 205 | buf = kzalloc(30, GFP_KERNEL); | ||
| 206 | if (buf) | ||
| 207 | snprintf(buf, 30, "%pI4.%u.%u", | ||
| 208 | &addr->sin_addr.s_addr, | ||
| 209 | ntohs(addr->sin_port) >> 8, | ||
| 210 | ntohs(addr->sin_port) & 0xff); | ||
| 211 | xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; | ||
| 212 | 190 | ||
| 213 | /* netid */ | 191 | /* netid */ |
| 214 | xprt->address_strings[RPC_DISPLAY_NETID] = "rdma"; | 192 | xprt->address_strings[RPC_DISPLAY_NETID] = "rdma"; |
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 83c73c4d017a..62438f3a914d 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c | |||
| @@ -248,8 +248,8 @@ struct sock_xprt { | |||
| 248 | * Connection of transports | 248 | * Connection of transports |
| 249 | */ | 249 | */ |
| 250 | struct delayed_work connect_worker; | 250 | struct delayed_work connect_worker; |
| 251 | struct sockaddr_storage addr; | 251 | struct sockaddr_storage srcaddr; |
| 252 | unsigned short port; | 252 | unsigned short srcport; |
| 253 | 253 | ||
| 254 | /* | 254 | /* |
| 255 | * UDP socket buffer size parameters | 255 | * UDP socket buffer size parameters |
| @@ -296,117 +296,60 @@ static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt) | |||
| 296 | return (struct sockaddr_in6 *) &xprt->addr; | 296 | return (struct sockaddr_in6 *) &xprt->addr; |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt, | 299 | static void xs_format_common_peer_addresses(struct rpc_xprt *xprt) |
| 300 | const char *protocol, | ||
| 301 | const char *netid) | ||
| 302 | { | 300 | { |
| 303 | struct sockaddr_in *addr = xs_addr_in(xprt); | 301 | struct sockaddr *sap = xs_addr(xprt); |
| 304 | char *buf; | 302 | struct sockaddr_in6 *sin6; |
| 303 | struct sockaddr_in *sin; | ||
| 304 | char buf[128]; | ||
| 305 | 305 | ||
| 306 | buf = kzalloc(20, GFP_KERNEL); | 306 | (void)rpc_ntop(sap, buf, sizeof(buf)); |
| 307 | if (buf) { | 307 | xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL); |
| 308 | snprintf(buf, 20, "%pI4", &addr->sin_addr.s_addr); | ||
| 309 | } | ||
| 310 | xprt->address_strings[RPC_DISPLAY_ADDR] = buf; | ||
| 311 | |||
| 312 | buf = kzalloc(8, GFP_KERNEL); | ||
| 313 | if (buf) { | ||
| 314 | snprintf(buf, 8, "%u", | ||
| 315 | ntohs(addr->sin_port)); | ||
| 316 | } | ||
| 317 | xprt->address_strings[RPC_DISPLAY_PORT] = buf; | ||
| 318 | |||
| 319 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; | ||
| 320 | |||
| 321 | buf = kzalloc(48, GFP_KERNEL); | ||
| 322 | if (buf) { | ||
| 323 | snprintf(buf, 48, "addr=%pI4 port=%u proto=%s", | ||
| 324 | &addr->sin_addr.s_addr, | ||
| 325 | ntohs(addr->sin_port), | ||
| 326 | protocol); | ||
| 327 | } | ||
| 328 | xprt->address_strings[RPC_DISPLAY_ALL] = buf; | ||
| 329 | |||
| 330 | buf = kzalloc(10, GFP_KERNEL); | ||
| 331 | if (buf) { | ||
| 332 | snprintf(buf, 10, "%02x%02x%02x%02x", | ||
| 333 | NIPQUAD(addr->sin_addr.s_addr)); | ||
| 334 | } | ||
| 335 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf; | ||
| 336 | 308 | ||
| 337 | buf = kzalloc(8, GFP_KERNEL); | 309 | switch (sap->sa_family) { |
| 338 | if (buf) { | 310 | case AF_INET: |
| 339 | snprintf(buf, 8, "%4hx", | 311 | sin = xs_addr_in(xprt); |
| 340 | ntohs(addr->sin_port)); | 312 | (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x", |
| 341 | } | 313 | NIPQUAD(sin->sin_addr.s_addr)); |
| 342 | xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf; | 314 | break; |
| 343 | 315 | case AF_INET6: | |
| 344 | buf = kzalloc(30, GFP_KERNEL); | 316 | sin6 = xs_addr_in6(xprt); |
| 345 | if (buf) { | 317 | (void)snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr); |
| 346 | snprintf(buf, 30, "%pI4.%u.%u", | 318 | break; |
| 347 | &addr->sin_addr.s_addr, | 319 | default: |
| 348 | ntohs(addr->sin_port) >> 8, | 320 | BUG(); |
| 349 | ntohs(addr->sin_port) & 0xff); | ||
| 350 | } | 321 | } |
| 351 | xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; | 322 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL); |
| 352 | |||
| 353 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; | ||
| 354 | } | 323 | } |
| 355 | 324 | ||
| 356 | static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt, | 325 | static void xs_format_common_peer_ports(struct rpc_xprt *xprt) |
| 357 | const char *protocol, | ||
| 358 | const char *netid) | ||
| 359 | { | 326 | { |
| 360 | struct sockaddr_in6 *addr = xs_addr_in6(xprt); | 327 | struct sockaddr *sap = xs_addr(xprt); |
| 361 | char *buf; | 328 | char buf[128]; |
| 362 | 329 | ||
| 363 | buf = kzalloc(40, GFP_KERNEL); | 330 | (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap)); |
| 364 | if (buf) { | 331 | xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL); |
| 365 | snprintf(buf, 40, "%pI6",&addr->sin6_addr); | ||
| 366 | } | ||
| 367 | xprt->address_strings[RPC_DISPLAY_ADDR] = buf; | ||
| 368 | 332 | ||
| 369 | buf = kzalloc(8, GFP_KERNEL); | 333 | (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap)); |
| 370 | if (buf) { | 334 | xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL); |
| 371 | snprintf(buf, 8, "%u", | 335 | } |
| 372 | ntohs(addr->sin6_port)); | ||
| 373 | } | ||
| 374 | xprt->address_strings[RPC_DISPLAY_PORT] = buf; | ||
| 375 | 336 | ||
| 337 | static void xs_format_peer_addresses(struct rpc_xprt *xprt, | ||
| 338 | const char *protocol, | ||
| 339 | const char *netid) | ||
| 340 | { | ||
| 376 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; | 341 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; |
| 342 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; | ||
| 343 | xs_format_common_peer_addresses(xprt); | ||
| 344 | xs_format_common_peer_ports(xprt); | ||
| 345 | } | ||
| 377 | 346 | ||
| 378 | buf = kzalloc(64, GFP_KERNEL); | 347 | static void xs_update_peer_port(struct rpc_xprt *xprt) |
| 379 | if (buf) { | 348 | { |
| 380 | snprintf(buf, 64, "addr=%pI6 port=%u proto=%s", | 349 | kfree(xprt->address_strings[RPC_DISPLAY_HEX_PORT]); |
| 381 | &addr->sin6_addr, | 350 | kfree(xprt->address_strings[RPC_DISPLAY_PORT]); |
| 382 | ntohs(addr->sin6_port), | ||
| 383 | protocol); | ||
| 384 | } | ||
| 385 | xprt->address_strings[RPC_DISPLAY_ALL] = buf; | ||
| 386 | |||
| 387 | buf = kzalloc(36, GFP_KERNEL); | ||
| 388 | if (buf) | ||
| 389 | snprintf(buf, 36, "%pi6", &addr->sin6_addr); | ||
| 390 | |||
| 391 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf; | ||
| 392 | |||
| 393 | buf = kzalloc(8, GFP_KERNEL); | ||
| 394 | if (buf) { | ||
| 395 | snprintf(buf, 8, "%4hx", | ||
| 396 | ntohs(addr->sin6_port)); | ||
| 397 | } | ||
| 398 | xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf; | ||
| 399 | |||
| 400 | buf = kzalloc(50, GFP_KERNEL); | ||
| 401 | if (buf) { | ||
| 402 | snprintf(buf, 50, "%pI6.%u.%u", | ||
| 403 | &addr->sin6_addr, | ||
| 404 | ntohs(addr->sin6_port) >> 8, | ||
| 405 | ntohs(addr->sin6_port) & 0xff); | ||
| 406 | } | ||
| 407 | xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; | ||
| 408 | 351 | ||
| 409 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; | 352 | xs_format_common_peer_ports(xprt); |
| 410 | } | 353 | } |
| 411 | 354 | ||
| 412 | static void xs_free_peer_addresses(struct rpc_xprt *xprt) | 355 | static void xs_free_peer_addresses(struct rpc_xprt *xprt) |
| @@ -1587,25 +1530,15 @@ static unsigned short xs_get_random_port(void) | |||
| 1587 | */ | 1530 | */ |
| 1588 | static void xs_set_port(struct rpc_xprt *xprt, unsigned short port) | 1531 | static void xs_set_port(struct rpc_xprt *xprt, unsigned short port) |
| 1589 | { | 1532 | { |
| 1590 | struct sockaddr *addr = xs_addr(xprt); | ||
| 1591 | |||
| 1592 | dprintk("RPC: setting port for xprt %p to %u\n", xprt, port); | 1533 | dprintk("RPC: setting port for xprt %p to %u\n", xprt, port); |
| 1593 | 1534 | ||
| 1594 | switch (addr->sa_family) { | 1535 | rpc_set_port(xs_addr(xprt), port); |
| 1595 | case AF_INET: | 1536 | xs_update_peer_port(xprt); |
| 1596 | ((struct sockaddr_in *)addr)->sin_port = htons(port); | ||
| 1597 | break; | ||
| 1598 | case AF_INET6: | ||
| 1599 | ((struct sockaddr_in6 *)addr)->sin6_port = htons(port); | ||
| 1600 | break; | ||
| 1601 | default: | ||
| 1602 | BUG(); | ||
| 1603 | } | ||
| 1604 | } | 1537 | } |
| 1605 | 1538 | ||
| 1606 | static unsigned short xs_get_srcport(struct sock_xprt *transport, struct socket *sock) | 1539 | static unsigned short xs_get_srcport(struct sock_xprt *transport, struct socket *sock) |
| 1607 | { | 1540 | { |
| 1608 | unsigned short port = transport->port; | 1541 | unsigned short port = transport->srcport; |
| 1609 | 1542 | ||
| 1610 | if (port == 0 && transport->xprt.resvport) | 1543 | if (port == 0 && transport->xprt.resvport) |
| 1611 | port = xs_get_random_port(); | 1544 | port = xs_get_random_port(); |
| @@ -1614,8 +1547,8 @@ static unsigned short xs_get_srcport(struct sock_xprt *transport, struct socket | |||
| 1614 | 1547 | ||
| 1615 | static unsigned short xs_next_srcport(struct sock_xprt *transport, struct socket *sock, unsigned short port) | 1548 | static unsigned short xs_next_srcport(struct sock_xprt *transport, struct socket *sock, unsigned short port) |
| 1616 | { | 1549 | { |
| 1617 | if (transport->port != 0) | 1550 | if (transport->srcport != 0) |
| 1618 | transport->port = 0; | 1551 | transport->srcport = 0; |
| 1619 | if (!transport->xprt.resvport) | 1552 | if (!transport->xprt.resvport) |
| 1620 | return 0; | 1553 | return 0; |
| 1621 | if (port <= xprt_min_resvport || port > xprt_max_resvport) | 1554 | if (port <= xprt_min_resvport || port > xprt_max_resvport) |
| @@ -1633,7 +1566,7 @@ static int xs_bind4(struct sock_xprt *transport, struct socket *sock) | |||
| 1633 | unsigned short port = xs_get_srcport(transport, sock); | 1566 | unsigned short port = xs_get_srcport(transport, sock); |
| 1634 | unsigned short last; | 1567 | unsigned short last; |
| 1635 | 1568 | ||
| 1636 | sa = (struct sockaddr_in *)&transport->addr; | 1569 | sa = (struct sockaddr_in *)&transport->srcaddr; |
| 1637 | myaddr.sin_addr = sa->sin_addr; | 1570 | myaddr.sin_addr = sa->sin_addr; |
| 1638 | do { | 1571 | do { |
| 1639 | myaddr.sin_port = htons(port); | 1572 | myaddr.sin_port = htons(port); |
| @@ -1642,7 +1575,7 @@ static int xs_bind4(struct sock_xprt *transport, struct socket *sock) | |||
| 1642 | if (port == 0) | 1575 | if (port == 0) |
| 1643 | break; | 1576 | break; |
| 1644 | if (err == 0) { | 1577 | if (err == 0) { |
| 1645 | transport->port = port; | 1578 | transport->srcport = port; |
| 1646 | break; | 1579 | break; |
| 1647 | } | 1580 | } |
| 1648 | last = port; | 1581 | last = port; |
| @@ -1666,7 +1599,7 @@ static int xs_bind6(struct sock_xprt *transport, struct socket *sock) | |||
| 1666 | unsigned short port = xs_get_srcport(transport, sock); | 1599 | unsigned short port = xs_get_srcport(transport, sock); |
| 1667 | unsigned short last; | 1600 | unsigned short last; |
| 1668 | 1601 | ||
| 1669 | sa = (struct sockaddr_in6 *)&transport->addr; | 1602 | sa = (struct sockaddr_in6 *)&transport->srcaddr; |
| 1670 | myaddr.sin6_addr = sa->sin6_addr; | 1603 | myaddr.sin6_addr = sa->sin6_addr; |
| 1671 | do { | 1604 | do { |
| 1672 | myaddr.sin6_port = htons(port); | 1605 | myaddr.sin6_port = htons(port); |
| @@ -1675,7 +1608,7 @@ static int xs_bind6(struct sock_xprt *transport, struct socket *sock) | |||
| 1675 | if (port == 0) | 1608 | if (port == 0) |
| 1676 | break; | 1609 | break; |
| 1677 | if (err == 0) { | 1610 | if (err == 0) { |
| 1678 | transport->port = port; | 1611 | transport->srcport = port; |
| 1679 | break; | 1612 | break; |
| 1680 | } | 1613 | } |
| 1681 | last = port; | 1614 | last = port; |
| @@ -1780,8 +1713,11 @@ static void xs_udp_connect_worker4(struct work_struct *work) | |||
| 1780 | goto out; | 1713 | goto out; |
| 1781 | } | 1714 | } |
| 1782 | 1715 | ||
| 1783 | dprintk("RPC: worker connecting xprt %p to address: %s\n", | 1716 | dprintk("RPC: worker connecting xprt %p via %s to " |
| 1784 | xprt, xprt->address_strings[RPC_DISPLAY_ALL]); | 1717 | "%s (port %s)\n", xprt, |
| 1718 | xprt->address_strings[RPC_DISPLAY_PROTO], | ||
| 1719 | xprt->address_strings[RPC_DISPLAY_ADDR], | ||
| 1720 | xprt->address_strings[RPC_DISPLAY_PORT]); | ||
| 1785 | 1721 | ||
| 1786 | xs_udp_finish_connecting(xprt, sock); | 1722 | xs_udp_finish_connecting(xprt, sock); |
| 1787 | status = 0; | 1723 | status = 0; |
| @@ -1822,8 +1758,11 @@ static void xs_udp_connect_worker6(struct work_struct *work) | |||
| 1822 | goto out; | 1758 | goto out; |
| 1823 | } | 1759 | } |
| 1824 | 1760 | ||
| 1825 | dprintk("RPC: worker connecting xprt %p to address: %s\n", | 1761 | dprintk("RPC: worker connecting xprt %p via %s to " |
| 1826 | xprt, xprt->address_strings[RPC_DISPLAY_ALL]); | 1762 | "%s (port %s)\n", xprt, |
| 1763 | xprt->address_strings[RPC_DISPLAY_PROTO], | ||
| 1764 | xprt->address_strings[RPC_DISPLAY_ADDR], | ||
| 1765 | xprt->address_strings[RPC_DISPLAY_PORT]); | ||
| 1827 | 1766 | ||
| 1828 | xs_udp_finish_connecting(xprt, sock); | 1767 | xs_udp_finish_connecting(xprt, sock); |
| 1829 | status = 0; | 1768 | status = 0; |
| @@ -1948,8 +1887,11 @@ static void xs_tcp_setup_socket(struct rpc_xprt *xprt, | |||
| 1948 | goto out_eagain; | 1887 | goto out_eagain; |
| 1949 | } | 1888 | } |
| 1950 | 1889 | ||
| 1951 | dprintk("RPC: worker connecting xprt %p to address: %s\n", | 1890 | dprintk("RPC: worker connecting xprt %p via %s to " |
| 1952 | xprt, xprt->address_strings[RPC_DISPLAY_ALL]); | 1891 | "%s (port %s)\n", xprt, |
| 1892 | xprt->address_strings[RPC_DISPLAY_PROTO], | ||
| 1893 | xprt->address_strings[RPC_DISPLAY_ADDR], | ||
| 1894 | xprt->address_strings[RPC_DISPLAY_PORT]); | ||
| 1953 | 1895 | ||
| 1954 | status = xs_tcp_finish_connecting(xprt, sock); | 1896 | status = xs_tcp_finish_connecting(xprt, sock); |
| 1955 | dprintk("RPC: %p connect status %d connected %d sock state %d\n", | 1897 | dprintk("RPC: %p connect status %d connected %d sock state %d\n", |
| @@ -2120,7 +2062,7 @@ static void xs_udp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq) | |||
| 2120 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); | 2062 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
| 2121 | 2063 | ||
| 2122 | seq_printf(seq, "\txprt:\tudp %u %lu %lu %lu %lu %Lu %Lu\n", | 2064 | seq_printf(seq, "\txprt:\tudp %u %lu %lu %lu %lu %Lu %Lu\n", |
| 2123 | transport->port, | 2065 | transport->srcport, |
| 2124 | xprt->stat.bind_count, | 2066 | xprt->stat.bind_count, |
| 2125 | xprt->stat.sends, | 2067 | xprt->stat.sends, |
| 2126 | xprt->stat.recvs, | 2068 | xprt->stat.recvs, |
| @@ -2144,7 +2086,7 @@ static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq) | |||
| 2144 | idle_time = (long)(jiffies - xprt->last_used) / HZ; | 2086 | idle_time = (long)(jiffies - xprt->last_used) / HZ; |
| 2145 | 2087 | ||
| 2146 | seq_printf(seq, "\txprt:\ttcp %u %lu %lu %lu %ld %lu %lu %lu %Lu %Lu\n", | 2088 | seq_printf(seq, "\txprt:\ttcp %u %lu %lu %lu %ld %lu %lu %lu %Lu %Lu\n", |
| 2147 | transport->port, | 2089 | transport->srcport, |
| 2148 | xprt->stat.bind_count, | 2090 | xprt->stat.bind_count, |
| 2149 | xprt->stat.connect_count, | 2091 | xprt->stat.connect_count, |
| 2150 | xprt->stat.connect_time, | 2092 | xprt->stat.connect_time, |
| @@ -2223,7 +2165,7 @@ static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args, | |||
| 2223 | memcpy(&xprt->addr, args->dstaddr, args->addrlen); | 2165 | memcpy(&xprt->addr, args->dstaddr, args->addrlen); |
| 2224 | xprt->addrlen = args->addrlen; | 2166 | xprt->addrlen = args->addrlen; |
| 2225 | if (args->srcaddr) | 2167 | if (args->srcaddr) |
| 2226 | memcpy(&new->addr, args->srcaddr, args->addrlen); | 2168 | memcpy(&new->srcaddr, args->srcaddr, args->addrlen); |
| 2227 | 2169 | ||
| 2228 | return xprt; | 2170 | return xprt; |
| 2229 | } | 2171 | } |
| @@ -2272,7 +2214,7 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args) | |||
| 2272 | 2214 | ||
| 2273 | INIT_DELAYED_WORK(&transport->connect_worker, | 2215 | INIT_DELAYED_WORK(&transport->connect_worker, |
| 2274 | xs_udp_connect_worker4); | 2216 | xs_udp_connect_worker4); |
| 2275 | xs_format_ipv4_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP); | 2217 | xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP); |
| 2276 | break; | 2218 | break; |
| 2277 | case AF_INET6: | 2219 | case AF_INET6: |
| 2278 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) | 2220 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) |
| @@ -2280,15 +2222,22 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args) | |||
| 2280 | 2222 | ||
| 2281 | INIT_DELAYED_WORK(&transport->connect_worker, | 2223 | INIT_DELAYED_WORK(&transport->connect_worker, |
| 2282 | xs_udp_connect_worker6); | 2224 | xs_udp_connect_worker6); |
| 2283 | xs_format_ipv6_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6); | 2225 | xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6); |
| 2284 | break; | 2226 | break; |
| 2285 | default: | 2227 | default: |
| 2286 | kfree(xprt); | 2228 | kfree(xprt); |
| 2287 | return ERR_PTR(-EAFNOSUPPORT); | 2229 | return ERR_PTR(-EAFNOSUPPORT); |
| 2288 | } | 2230 | } |
| 2289 | 2231 | ||
| 2290 | dprintk("RPC: set up transport to address %s\n", | 2232 | if (xprt_bound(xprt)) |
| 2291 | xprt->address_strings[RPC_DISPLAY_ALL]); | 2233 | dprintk("RPC: set up xprt to %s (port %s) via %s\n", |
| 2234 | xprt->address_strings[RPC_DISPLAY_ADDR], | ||
| 2235 | xprt->address_strings[RPC_DISPLAY_PORT], | ||
| 2236 | xprt->address_strings[RPC_DISPLAY_PROTO]); | ||
| 2237 | else | ||
| 2238 | dprintk("RPC: set up xprt to %s (autobind) via %s\n", | ||
| 2239 | xprt->address_strings[RPC_DISPLAY_ADDR], | ||
| 2240 | xprt->address_strings[RPC_DISPLAY_PROTO]); | ||
| 2292 | 2241 | ||
| 2293 | if (try_module_get(THIS_MODULE)) | 2242 | if (try_module_get(THIS_MODULE)) |
| 2294 | return xprt; | 2243 | return xprt; |
| @@ -2337,23 +2286,33 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args) | |||
| 2337 | if (((struct sockaddr_in *)addr)->sin_port != htons(0)) | 2286 | if (((struct sockaddr_in *)addr)->sin_port != htons(0)) |
| 2338 | xprt_set_bound(xprt); | 2287 | xprt_set_bound(xprt); |
| 2339 | 2288 | ||
| 2340 | INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker4); | 2289 | INIT_DELAYED_WORK(&transport->connect_worker, |
| 2341 | xs_format_ipv4_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP); | 2290 | xs_tcp_connect_worker4); |
| 2291 | xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP); | ||
| 2342 | break; | 2292 | break; |
| 2343 | case AF_INET6: | 2293 | case AF_INET6: |
| 2344 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) | 2294 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) |
| 2345 | xprt_set_bound(xprt); | 2295 | xprt_set_bound(xprt); |
| 2346 | 2296 | ||
| 2347 | INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker6); | 2297 | INIT_DELAYED_WORK(&transport->connect_worker, |
| 2348 | xs_format_ipv6_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6); | 2298 | xs_tcp_connect_worker6); |
| 2299 | xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6); | ||
| 2349 | break; | 2300 | break; |
| 2350 | default: | 2301 | default: |
| 2351 | kfree(xprt); | 2302 | kfree(xprt); |
| 2352 | return ERR_PTR(-EAFNOSUPPORT); | 2303 | return ERR_PTR(-EAFNOSUPPORT); |
| 2353 | } | 2304 | } |
| 2354 | 2305 | ||
| 2355 | dprintk("RPC: set up transport to address %s\n", | 2306 | if (xprt_bound(xprt)) |
| 2356 | xprt->address_strings[RPC_DISPLAY_ALL]); | 2307 | dprintk("RPC: set up xprt to %s (port %s) via %s\n", |
| 2308 | xprt->address_strings[RPC_DISPLAY_ADDR], | ||
| 2309 | xprt->address_strings[RPC_DISPLAY_PORT], | ||
| 2310 | xprt->address_strings[RPC_DISPLAY_PROTO]); | ||
| 2311 | else | ||
| 2312 | dprintk("RPC: set up xprt to %s (autobind) via %s\n", | ||
| 2313 | xprt->address_strings[RPC_DISPLAY_ADDR], | ||
| 2314 | xprt->address_strings[RPC_DISPLAY_PROTO]); | ||
| 2315 | |||
| 2357 | 2316 | ||
| 2358 | if (try_module_get(THIS_MODULE)) | 2317 | if (try_module_get(THIS_MODULE)) |
| 2359 | return xprt; | 2318 | return xprt; |
| @@ -2412,3 +2371,55 @@ void cleanup_socket_xprt(void) | |||
| 2412 | xprt_unregister_transport(&xs_udp_transport); | 2371 | xprt_unregister_transport(&xs_udp_transport); |
| 2413 | xprt_unregister_transport(&xs_tcp_transport); | 2372 | xprt_unregister_transport(&xs_tcp_transport); |
| 2414 | } | 2373 | } |
| 2374 | |||
| 2375 | static int param_set_uint_minmax(const char *val, struct kernel_param *kp, | ||
| 2376 | unsigned int min, unsigned int max) | ||
| 2377 | { | ||
| 2378 | unsigned long num; | ||
| 2379 | int ret; | ||
| 2380 | |||
| 2381 | if (!val) | ||
| 2382 | return -EINVAL; | ||
| 2383 | ret = strict_strtoul(val, 0, &num); | ||
| 2384 | if (ret == -EINVAL || num < min || num > max) | ||
| 2385 | return -EINVAL; | ||
| 2386 | *((unsigned int *)kp->arg) = num; | ||
| 2387 | return 0; | ||
| 2388 | } | ||
| 2389 | |||
| 2390 | static int param_set_portnr(const char *val, struct kernel_param *kp) | ||
| 2391 | { | ||
| 2392 | return param_set_uint_minmax(val, kp, | ||
| 2393 | RPC_MIN_RESVPORT, | ||
| 2394 | RPC_MAX_RESVPORT); | ||
| 2395 | } | ||
| 2396 | |||
| 2397 | static int param_get_portnr(char *buffer, struct kernel_param *kp) | ||
| 2398 | { | ||
| 2399 | return param_get_uint(buffer, kp); | ||
| 2400 | } | ||
| 2401 | #define param_check_portnr(name, p) \ | ||
| 2402 | __param_check(name, p, unsigned int); | ||
| 2403 | |||
| 2404 | module_param_named(min_resvport, xprt_min_resvport, portnr, 0644); | ||
| 2405 | module_param_named(max_resvport, xprt_max_resvport, portnr, 0644); | ||
| 2406 | |||
| 2407 | static int param_set_slot_table_size(const char *val, struct kernel_param *kp) | ||
| 2408 | { | ||
| 2409 | return param_set_uint_minmax(val, kp, | ||
| 2410 | RPC_MIN_SLOT_TABLE, | ||
| 2411 | RPC_MAX_SLOT_TABLE); | ||
| 2412 | } | ||
| 2413 | |||
| 2414 | static int param_get_slot_table_size(char *buffer, struct kernel_param *kp) | ||
| 2415 | { | ||
| 2416 | return param_get_uint(buffer, kp); | ||
| 2417 | } | ||
| 2418 | #define param_check_slot_table_size(name, p) \ | ||
| 2419 | __param_check(name, p, unsigned int); | ||
| 2420 | |||
| 2421 | module_param_named(tcp_slot_table_entries, xprt_tcp_slot_table_entries, | ||
| 2422 | slot_table_size, 0644); | ||
| 2423 | module_param_named(udp_slot_table_entries, xprt_udp_slot_table_entries, | ||
| 2424 | slot_table_size, 0644); | ||
| 2425 | |||
