ReactOS 0.4.16-dev-320-g3bd9ddc
nfs41.h File Reference
#include "util.h"
#include "list.h"
Include dependency graph for nfs41.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  __nfs41_superblock
 
struct  __nfs41_superblock_list
 
struct  server_addrs
 
struct  __nfs41_server
 
struct  __nfs41_delegation_state
 
struct  __nfs41_lock_state
 
struct  __nfs41_open_state
 
struct  __nfs41_rpc_clnt
 
struct  client_state
 
struct  __nfs41_client
 
struct  __nfs41_slot_table
 
struct  __nfs41_channel_attrs
 
struct  replay_cache
 
struct  __nfs41_cb_session
 
struct  __nfs41_session
 
struct  __nfs41_root
 

Macros

#define NFS41_MAX_NUM_SLOTS   NFS41_MAX_RPC_REQS
 

Typedefs

typedef struct __nfs41_superblock nfs41_superblock
 
typedef struct __nfs41_superblock_list nfs41_superblock_list
 
typedef struct __nfs41_server nfs41_server
 
typedef struct __nfs41_delegation_state nfs41_delegation_state
 
typedef struct __nfs41_lock_state nfs41_lock_state
 
typedef struct __nfs41_open_state nfs41_open_state
 
typedef struct __nfs41_rpc_clnt nfs41_rpc_clnt
 
typedef struct __nfs41_client nfs41_client
 
typedef struct __nfs41_slot_table nfs41_slot_table
 
typedef struct __nfs41_channel_attrs nfs41_channel_attrs
 
typedef struct __nfs41_cb_session nfs41_cb_session
 
typedef struct __nfs41_session nfs41_session
 
typedef struct __nfs41_root nfs41_root
 

Enumerations

enum  delegation_status { DELEGATION_GRANTED , DELEGATION_RETURNING , DELEGATION_RETURNED }
 

Functions

int nfs41_root_create (IN const char *name, IN uint32_t sec_flavor, IN uint32_t wsize, IN uint32_t rsize, OUT nfs41_root **root_out)
 
void nfs41_root_ref (IN nfs41_root *root)
 
void nfs41_root_deref (IN nfs41_root *root)
 
int nfs41_root_mount_addrs (IN nfs41_root *root, IN const multi_addr4 *addrs, IN bool_t is_data, IN OPTIONAL uint32_t lease_time, OUT nfs41_client **client_out)
 
int nfs41_root_mount_server (IN nfs41_root *root, IN nfs41_server *server, IN bool_t is_data, IN OPTIONAL uint32_t lease_time, OUT nfs41_client **client_out)
 
int nfs41_root_mount_referral (IN nfs41_root *root, IN const fs_locations4 *locations, OUT const fs_location4 **loc_out, OUT nfs41_client **client_out)
 
static __inline nfs41_sessionnfs41_root_session (IN nfs41_root *root)
 
int nfs41_session_create (IN nfs41_client *client, IN nfs41_session **session_out)
 
int nfs41_session_renew (IN nfs41_session *session)
 
int nfs41_session_set_lease (IN nfs41_session *session, IN uint32_t lease_time)
 
void nfs41_session_free (IN nfs41_session *session)
 
void nfs41_session_bump_seq (IN nfs41_session *session, IN uint32_t slotid, IN uint32_t target_highest_slotid)
 
void nfs41_session_free_slot (IN nfs41_session *session, IN uint32_t slotid)
 
void nfs41_session_get_slot (IN nfs41_session *session, OUT uint32_t *slot, OUT uint32_t *seq, OUT uint32_t *highest)
 
int nfs41_session_recall_slot (IN nfs41_session *session, IN OUT uint32_t target_highest_slotid)
 
void nfs41_session_sequence (struct __nfs41_sequence_args *args, nfs41_session *session, bool_t cachethis)
 
int nfs41_session_bad_slot (IN nfs41_session *session, IN OUT struct __nfs41_sequence_args *args)
 
void nfs41_server_list_init ()
 
int nfs41_server_resolve (IN const char *hostname, IN unsigned short port, OUT multi_addr4 *addrs)
 
int nfs41_server_find_or_create (IN const char *server_owner_major_id, IN const char *server_scope, IN const netaddr4 *addr, OUT nfs41_server **server_out)
 
void nfs41_server_ref (IN nfs41_server *server)
 
void nfs41_server_deref (IN nfs41_server *server)
 
void nfs41_server_addrs (IN nfs41_server *server, OUT multi_addr4 *addrs)
 
int nfs41_client_owner (IN const char *name, IN uint32_t sec_flavor, OUT client_owner4 *owner)
 
uint32_t nfs41_exchange_id_flags (IN bool_t is_data)
 
int nfs41_client_create (IN nfs41_rpc_clnt *rpc, IN const client_owner4 *owner, IN bool_t is_data, IN const struct __nfs41_exchange_id_res *exchangeid, OUT nfs41_client **client_out)
 
int nfs41_client_renew (IN nfs41_client *client)
 
void nfs41_client_free (IN nfs41_client *client)
 
static __inline nfs41_serverclient_server (IN nfs41_client *client)
 
int nfs41_superblock_for_fh (IN nfs41_session *session, IN const nfs41_fsid *fsid, IN const nfs41_fh *parent OPTIONAL, OUT nfs41_path_fh *file)
 
static __inline void nfs41_superblock_getattr_mask (IN const nfs41_superblock *superblock, OUT bitmap4 *attrs)
 
static __inline void nfs41_superblock_supported_attrs (IN const nfs41_superblock *superblock, IN OUT bitmap4 *attrs)
 
static __inline void nfs41_superblock_supported_attrs_exclcreat (IN const nfs41_superblock *superblock, IN OUT bitmap4 *attrs)
 
void nfs41_superblock_fs_attributes (IN const nfs41_superblock *superblock, OUT struct _FILE_FS_ATTRIBUTE_INFORMATION *FsAttrs)
 
void nfs41_superblock_space_changed (IN nfs41_superblock *superblock)
 
void nfs41_superblock_list_init (IN nfs41_superblock_list *superblocks)
 
void nfs41_superblock_list_free (IN nfs41_superblock_list *superblocks)
 
int nfs41_rpc_clnt_create (IN const multi_addr4 *addrs, IN uint32_t wsize, IN uint32_t rsize, IN uint32_t uid, IN uint32_t gid, IN uint32_t sec_flavor, OUT nfs41_rpc_clnt **rpc_out)
 
void nfs41_rpc_clnt_free (IN nfs41_rpc_clnt *rpc)
 
int nfs41_send_compound (IN nfs41_rpc_clnt *rpc, IN char *inbuf, OUT char *outbuf)
 
static __inline netaddr4nfs41_rpc_netaddr (IN nfs41_rpc_clnt *rpc)
 
void nfs41_open_state_ref (IN nfs41_open_state *state)
 
void nfs41_open_state_deref (IN nfs41_open_state *state)
 
void nfs41_open_stateid_arg (IN nfs41_open_state *state, OUT struct __stateid_arg *arg)
 
int nfs41_ea_set (IN nfs41_open_state *state, IN struct _FILE_FULL_EA_INFORMATION *ea)
 

Macro Definition Documentation

◆ NFS41_MAX_NUM_SLOTS

#define NFS41_MAX_NUM_SLOTS   NFS41_MAX_RPC_REQS

Definition at line 218 of file nfs41.h.

Typedef Documentation

◆ nfs41_cb_session

◆ nfs41_channel_attrs

◆ nfs41_client

◆ nfs41_delegation_state

◆ nfs41_lock_state

◆ nfs41_open_state

◆ nfs41_root

◆ nfs41_rpc_clnt

◆ nfs41_server

◆ nfs41_session

◆ nfs41_slot_table

◆ nfs41_superblock

◆ nfs41_superblock_list

Enumeration Type Documentation

◆ delegation_status

Enumerator
DELEGATION_GRANTED 
DELEGATION_RETURNING 
DELEGATION_RETURNED 

Definition at line 89 of file nfs41.h.

89 {
93};
@ DELEGATION_RETURNED
Definition: nfs41.h:92
@ DELEGATION_GRANTED
Definition: nfs41.h:90
@ DELEGATION_RETURNING
Definition: nfs41.h:91

Function Documentation

◆ client_server()

static __inline nfs41_server * client_server ( IN nfs41_client client)
static

Definition at line 428 of file nfs41.h.

430{
431 /* the client's server could change during nfs41_client_renew(),
432 * so access to client->server must be protected */
434 AcquireSRWLockShared(&client->exid_lock);
435 server = client->server;
436 ReleaseSRWLockShared(&client->exid_lock);
437 return server;
438}
VOID WINAPI ReleaseSRWLockShared(PSRWLOCK Lock)
Definition: sync.c:43
VOID WINAPI AcquireSRWLockShared(PSRWLOCK Lock)
Definition: sync.c:15
static FILE * client
Definition: client.c:41
static rfbScreenInfoPtr server
Definition: vnc.c:74

Referenced by client_name_cache(), and nfs41_superblock_for_fh().

◆ nfs41_client_create()

int nfs41_client_create ( IN nfs41_rpc_clnt rpc,
IN const client_owner4 owner,
IN bool_t  is_data,
IN const struct __nfs41_exchange_id_res exchangeid,
OUT nfs41_client **  client_out 
)

Referenced by root_client_create().

◆ nfs41_client_free()

void nfs41_client_free ( IN nfs41_client client)

Definition at line 206 of file nfs41_client.c.

208{
209 dprintf(2, "nfs41_client_free(%llu)\n", client->clnt_id);
211 if (client->session) nfs41_session_free(client->session);
212 nfs41_destroy_clientid(client->rpc, client->clnt_id);
213 if (client->server) nfs41_server_deref(client->server);
215 if (client->layouts) pnfs_layout_list_free(client->layouts);
216 if (client->devices) pnfs_file_device_list_free(client->devices);
217 DeleteCriticalSection(&client->state.lock);
218 DeleteCriticalSection(&client->recovery.lock);
219 free(client);
220}
#define free
Definition: debug_ros.c:5
void nfs41_client_delegation_free(IN nfs41_client *client)
Definition: delegation.c:828
void nfs41_server_deref(IN nfs41_server *server)
Definition: nfs41_server.c:155
void nfs41_session_free(IN nfs41_session *session)
void nfs41_rpc_clnt_free(IN nfs41_rpc_clnt *rpc)
Definition: nfs41_rpc.c:243
int nfs41_destroy_clientid(IN nfs41_rpc_clnt *rpc, IN uint64_t clientid)
Definition: nfs41_ops.c:242
void pnfs_layout_list_free(IN struct pnfs_layout_list *layouts)
Definition: pnfs_layout.c:139
void pnfs_file_device_list_free(IN struct pnfs_file_device_list *devices)
Definition: pnfs_device.c:144
#define dprintf
Definition: regdump.c:33
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by nfs41_client_create(), nfs41_root_mount_addrs(), root_client_create(), and root_free().

◆ nfs41_client_owner()

int nfs41_client_owner ( IN const char name,
IN uint32_t  sec_flavor,
OUT client_owner4 owner 
)

Definition at line 358 of file nfs41_client.c.

362{
367 const ULONGLONG time_created = GetTickCount64();
368 int status;
369 char username[UNLEN + 1];
370 DWORD len = UNLEN + 1;
371
372 if (!GetUserNameA(username, &len)) {
374 eprintf("GetUserName() failed with %d\n", status);
375 goto out;
376 }
377
378 /* owner.verifier = "time created" */
379 memcpy(owner->co_verifier, &time_created, sizeof(time_created));
380
381 /* set up the md5 hash generator */
385 eprintf("CryptAcquireContext() failed with %d\n", status);
386 goto out;
387 }
388 if (!CryptCreateHash(context, CALG_MD5, 0, 0, &hash)) {
390 eprintf("CryptCreateHash() failed with %d\n", status);
391 goto out_context;
392 }
393
394 if (!CryptHashData(hash, (const BYTE*)&sec_flavor, (DWORD)sizeof(sec_flavor), 0)) {
396 eprintf("CryptHashData() failed with %d\n", status);
397 goto out_hash;
398 }
399
400 if (!CryptHashData(hash, (const BYTE*)username, (DWORD)strlen(username), 0)) {
402 eprintf("CryptHashData() failed with %d\n", status);
403 goto out_hash;
404 }
405
406 if (!CryptHashData(hash, (const BYTE*)name, (DWORD)strlen(name), 0)) {
408 eprintf("CryptHashData() failed with %d\n", status);
409 goto out_hash;
410 }
411
412 /* add the mac address from each applicable adapter to the hash */
414 if (status) {
415 eprintf("hash_mac_addrs() failed with %d\n", status);
416 goto out_hash;
417 }
418
419 /* extract the hash size (should always be 16 for md5) */
420 buffer = (PBYTE)&owner->co_ownerid_len;
421 length = (DWORD)sizeof(DWORD);
424 eprintf("CryptGetHashParam(size) failed with %d\n", status);
425 goto out_hash;
426 }
427 /* extract the hash buffer */
428 buffer = owner->co_ownerid;
429 length = owner->co_ownerid_len;
432 eprintf("CryptGetHashParam(val) failed with %d\n", status);
433 goto out_hash;
434 }
435
436out_hash:
438out_context:
440out:
441 return status;
442}
ULONGLONG WINAPI GetTickCount64(VOID)
Definition: GetTickCount64.c:9
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
#define NULL
Definition: types.h:112
BOOL WINAPI GetUserNameA(LPSTR lpszName, LPDWORD lpSize)
Definition: misc.c:246
BOOL WINAPI CryptCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
Definition: crypt.c:740
BOOL WINAPI CryptGetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1610
BOOL WINAPI CryptDestroyHash(HCRYPTHASH hHash)
Definition: crypt.c:890
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:648
BOOL WINAPI CryptHashData(HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: crypt.c:1771
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLenum GLsizei len
Definition: glext.h:6722
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static WCHAR username[]
Definition: url.c:32
static DWORD hash_mac_addrs(IN HCRYPTHASH hash)
Definition: nfs41_client.c:296
sec_flavor
Definition: nfs41_ops.h:861
#define DWORD
Definition: nt_native.h:44
BYTE * PBYTE
Definition: pedump.c:66
static FILE * out
Definition: regtests2xml.c:44
#define UNLEN
Definition: sspi.c:28
Definition: http.c:7252
Definition: _hash_fun.h:40
Definition: name.c:39
Definition: ps.c:97
uint64_t ULONGLONG
Definition: typedefs.h:67
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define HP_HASHSIZE
Definition: wincrypt.h:2184
#define PROV_RSA_FULL
Definition: wincrypt.h:2039
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define CALG_MD5
Definition: wincrypt.h:1805
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:50
#define CryptAcquireContext
Definition: wincrypt.h:4164
#define HP_HASHVAL
Definition: wincrypt.h:2183
unsigned char BYTE
Definition: xxhash.c:193

Referenced by nfs41_root_create().

◆ nfs41_client_renew()

int nfs41_client_renew ( IN nfs41_client client)

Definition at line 168 of file nfs41_client.c.

170{
171 nfs41_exchange_id_res exchangeid = { 0 };
172 int status;
173
174 status = nfs41_exchange_id(client->rpc, &client->owner,
175 nfs41_exchange_id_flags(client->is_data), &exchangeid);
176 if (status) {
177 eprintf("nfs41_exchange_id() failed with %d\n", status);
179 goto out;
180 }
181
182 if (client->is_data) { /* require USE_PNFS_DS */
183 if ((exchangeid.flags & EXCHGID4_FLAG_USE_PNFS_DS) == 0) {
184 eprintf("client expected USE_PNFS_DS\n");
186 goto out;
187 }
188 } else { /* require USE_NON_PNFS or USE_PNFS_MDS */
189 if ((exchangeid.flags & EXCHGID4_FLAG_USE_NON_PNFS) == 0 &&
190 (exchangeid.flags & EXCHGID4_FLAG_USE_PNFS_MDS) == 0) {
191 eprintf("client expected USE_NON_PNFS OR USE_PNFS_MDS\n");
193 goto out;
194 }
195 }
196
197 dprint_roles(2, exchangeid.flags);
198
199 AcquireSRWLockExclusive(&client->exid_lock);
200 status = update_exchangeid_res(client, &exchangeid);
201 ReleaseSRWLockExclusive(&client->exid_lock);
202out:
203 return status;
204}
VOID WINAPI AcquireSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:8
VOID WINAPI ReleaseSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:36
static void dprint_roles(IN int level, IN uint32_t roles)
Definition: nfs41_client.c:158
uint32_t nfs41_exchange_id_flags(IN bool_t is_data)
Definition: nfs41_client.c:36
static int update_exchangeid_res(IN nfs41_client *client, IN const nfs41_exchange_id_res *exchangeid)
Definition: nfs41_client.c:97
int nfs41_exchange_id(IN nfs41_rpc_clnt *rpc, IN client_owner4 *owner, IN uint32_t flags_in, OUT nfs41_exchange_id_res *res_out)
Definition: nfs41_ops.c:36
@ EXCHGID4_FLAG_USE_PNFS_MDS
Definition: nfs41_ops.h:101
@ EXCHGID4_FLAG_USE_NON_PNFS
Definition: nfs41_ops.h:100
@ EXCHGID4_FLAG_USE_PNFS_DS
Definition: nfs41_ops.h:102
#define ERROR_BAD_NET_RESP
Definition: winerror.h:150

Referenced by compound_encode_send_decode(), and nfs41_recover_session().

◆ nfs41_ea_set()

int nfs41_ea_set ( IN nfs41_open_state state,
IN struct _FILE_FULL_EA_INFORMATION ea 
)

◆ nfs41_exchange_id_flags()

uint32_t nfs41_exchange_id_flags ( IN bool_t  is_data)

Definition at line 36 of file nfs41_client.c.

38{
40 if (is_data)
42 else
44 return flags;
45}
UINT32 uint32_t
Definition: types.h:75
GLbitfield flags
Definition: glext.h:7161
@ EXCHGID4_FLAG_SUPP_MOVED_REFER
Definition: nfs41_ops.h:95

Referenced by nfs41_client_renew(), nfs41_root_mount_addrs(), root_client_find(), and root_client_find_addrs().

◆ nfs41_open_state_deref()

void nfs41_open_state_deref ( IN nfs41_open_state state)

Definition at line 104 of file open.c.

106{
107 const LONG count = InterlockedDecrement(&state->ref_count);
108
109 dprintf(2, "nfs41_open_state_deref(%s) count %d\n", state->path.path, count);
110 if (count == 0)
112}
static int state
Definition: maze.c:121
#define InterlockedDecrement
Definition: armddk.h:52
static void open_state_free(IN nfs41_open_state *state)
Definition: open.c:79
GLuint GLuint GLsizei count
Definition: gl.h:1545
long LONG
Definition: pedump.c:60

Referenced by cancel_open(), cleanup_close(), delegation_return(), handle_open(), and upcall_cleanup().

◆ nfs41_open_state_ref()

void nfs41_open_state_ref ( IN nfs41_open_state state)

Definition at line 96 of file open.c.

98{
99 const LONG count = InterlockedIncrement(&state->ref_count);
100
101 dprintf(2, "nfs41_open_state_ref(%s) count %d\n", state->path.path, count);
102}
#define InterlockedIncrement
Definition: armddk.h:53

Referenced by deleg_open_find(), handle_open(), and upcall_parse().

◆ nfs41_open_stateid_arg()

◆ nfs41_root_create()

int nfs41_root_create ( IN const char name,
IN uint32_t  sec_flavor,
IN uint32_t  wsize,
IN uint32_t  rsize,
OUT nfs41_root **  root_out 
)

Definition at line 37 of file namespace.c.

43{
44 int status = NO_ERROR;
46
47 dprintf(NSLVL, "--> nfs41_root_create()\n");
48
49 root = calloc(1, sizeof(nfs41_root));
50 if (root == NULL) {
52 goto out;
53 }
54
55 list_init(&root->clients);
56 root->wsize = wsize;
57 root->rsize = rsize;
59 root->ref_count = 1;
60 root->sec_flavor = sec_flavor;
61
62 /* generate a unique client_owner */
63 status = nfs41_client_owner(name, sec_flavor, &root->client_owner);
64 if (status) {
65 eprintf("nfs41_client_owner() failed with %d\n", status);
66 free(root);
67 goto out;
68 }
69
70 *root_out = root;
71out:
72 dprintf(NSLVL, "<-- nfs41_root_create() returning %d\n", status);
73 return status;
74}
static void list_init(struct list_entry *head)
Definition: list.h:51
struct _root root
#define NO_ERROR
Definition: dderror.h:5
#define NSLVL
Definition: namespace.c:30
int nfs41_client_owner(IN const char *name, IN uint32_t sec_flavor, OUT client_owner4 *owner)
Definition: nfs41_client.c:358
#define calloc
Definition: rosglue.h:14
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751

Referenced by handle_mount().

◆ nfs41_root_deref()

void nfs41_root_deref ( IN nfs41_root root)

Definition at line 100 of file namespace.c.

102{
103 const LONG count = InterlockedDecrement(&root->ref_count);
104
105 dprintf(NSLVL, "nfs41_root_deref() count %d\n", count);
106 if (count == 0)
108}
static void root_free(IN nfs41_root *root)
Definition: namespace.c:76

Referenced by cancel_mount(), delegation_recall_thread(), handle_mount(), handle_unmount(), nfs41_delegation_recall(), and upcall_cleanup().

◆ nfs41_root_mount_addrs()

int nfs41_root_mount_addrs ( IN nfs41_root root,
IN const multi_addr4 addrs,
IN bool_t  is_data,
IN OPTIONAL uint32_t  lease_time,
OUT nfs41_client **  client_out 
)

Definition at line 335 of file namespace.c.

341{
342 nfs41_exchange_id_res exchangeid = { 0 };
343 nfs41_rpc_clnt *rpc;
344 nfs41_client *client, *existing;
345 int status;
346
347 dprintf(NSLVL, "--> nfs41_root_mount_addrs()\n");
348
349 /* look for an existing client that matches the address and role */
351 status = root_client_find_addrs(root, addrs, is_data, &client);
353
354 if (status == NO_ERROR)
355 goto out;
356
357 /* create an rpc client */
358 status = nfs41_rpc_clnt_create(addrs, root->wsize, root->rsize,
359 root->uid, root->gid, root->sec_flavor, &rpc);
360 if (status) {
361 eprintf("nfs41_rpc_clnt_create() failed %d\n", status);
362 goto out;
363 }
364
365 /* get a clientid with exchangeid */
366 status = nfs41_exchange_id(rpc, &root->client_owner,
367 nfs41_exchange_id_flags(is_data), &exchangeid);
368 if (status) {
369 eprintf("nfs41_exchange_id() failed %s\n", nfs_error_string(status));
371 goto out_free_rpc;
372 }
373
374 /* attempt to match existing clients by the exchangeid response */
376 status = root_client_find(root, &exchangeid, is_data, &client);
378
379 if (status == NO_ERROR)
380 goto out_free_rpc;
381
382 /* create a client for this clientid */
383 status = root_client_create(root, rpc, is_data,
384 lease_time, &exchangeid, &client);
385 if (status) {
386 eprintf("nfs41_client_create() failed %d\n", status);
387 /* root_client_create takes care of cleaning up
388 * thus don't go to out_free_rpc */
389 goto out;
390 }
391
392 /* because we don't hold the root's lock over session creation,
393 * we could end up creating multiple clients with the same
394 * server and roles */
396 status = root_client_find(root, &exchangeid, is_data, &existing);
397
398 if (status) {
399 dprintf(NSLVL, "caching new client 0x%p\n", client);
400
401 /* the client is not a duplicate, so add it to the list */
402 list_add_tail(&root->clients, &client->root_entry);
404 } else {
405 dprintf(NSLVL, "created a duplicate client 0x%p! using "
406 "existing client 0x%p instead\n", client, existing);
407
408 /* a matching client has been created in parallel, so free
409 * the one we created and use the existing client instead */
411 client = existing;
412 }
414
415out:
416 if (status == NO_ERROR)
417 *client_out = client;
418 dprintf(NSLVL, "<-- nfs41_root_mount_addrs() returning %d\n", status);
419 return status;
420
421out_free_rpc:
423 goto out;
424}
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
static int root_client_create(IN nfs41_root *root, IN nfs41_rpc_clnt *rpc, IN bool_t is_data, IN OPTIONAL uint32_t lease_time, IN const nfs41_exchange_id_res *exchangeid, OUT nfs41_client **client_out)
Definition: namespace.c:281
static int root_client_find_addrs(IN nfs41_root *root, IN const multi_addr4 *addrs, IN bool_t is_data, OUT nfs41_client **client_out)
Definition: namespace.c:141
static int root_client_find(IN nfs41_root *root, IN const nfs41_exchange_id_res *exchangeid, IN bool_t is_data, OUT nfs41_client **client_out)
Definition: namespace.c:207
int nfs41_rpc_clnt_create(IN const multi_addr4 *addrs, IN uint32_t wsize, IN uint32_t rsize, IN uint32_t uid, IN uint32_t gid, IN uint32_t sec_flavor, OUT nfs41_rpc_clnt **rpc_out)
Definition: nfs41_rpc.c:145
uint32_t nfs41_exchange_id_flags(IN bool_t is_data)
Definition: nfs41_client.c:36
void nfs41_client_free(IN nfs41_client *client)
Definition: nfs41_client.c:206
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by handle_mount(), pnfs_data_server_client(), and referral_mount_location().

◆ nfs41_root_mount_referral()

int nfs41_root_mount_referral ( IN nfs41_root root,
IN const fs_locations4 locations,
OUT const fs_location4 **  loc_out,
OUT nfs41_client **  client_out 
)

Definition at line 459 of file namespace.c.

464{
466 uint32_t i;
467
468 /* establish a mount to the first available location */
469 for (i = 0; i < locations->location_count; i++) {
471 &locations->locations[i], client_out);
472 if (status == NO_ERROR) {
473 *loc_out = &locations->locations[i];
474 break;
475 }
476 }
477 return status;
478}
GLsizei const GLint * locations
Definition: glext.h:10542
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static int referral_mount_location(IN nfs41_root *root, IN const fs_location4 *loc, OUT nfs41_client **client_out)
Definition: namespace.c:437
#define ERROR_BAD_NET_NAME
Definition: winerror.h:159

Referenced by referral_resolve().

◆ nfs41_root_mount_server()

int nfs41_root_mount_server ( IN nfs41_root root,
IN nfs41_server server,
IN bool_t  is_data,
IN OPTIONAL uint32_t  lease_time,
OUT nfs41_client **  client_out 
)

◆ nfs41_root_ref()

void nfs41_root_ref ( IN nfs41_root root)

Definition at line 92 of file namespace.c.

94{
95 const LONG count = InterlockedIncrement(&root->ref_count);
96
97 dprintf(NSLVL, "nfs41_root_ref() count %d\n", count);
98}

Referenced by handle_mount(), nfs41_delegation_recall(), and upcall_parse().

◆ nfs41_root_session()

static __inline nfs41_session * nfs41_root_session ( IN nfs41_root root)
static

Definition at line 321 of file nfs41.h.

323{
325 /* return a session for the server at the root of the namespace.
326 * because we created it on mount, it's the first one in the list */
328 client = list_container(root->clients.next, nfs41_client, root_entry);
330 return client->session;
331}
#define list_container(entry, type, field)
Definition: list.h:33

Referenced by handle_open().

◆ nfs41_rpc_clnt_create()

int nfs41_rpc_clnt_create ( IN const multi_addr4 addrs,
IN uint32_t  wsize,
IN uint32_t  rsize,
IN uint32_t  uid,
IN uint32_t  gid,
IN uint32_t  sec_flavor,
OUT nfs41_rpc_clnt **  rpc_out 
)

Definition at line 145 of file nfs41_rpc.c.

153{
154 CLIENT *client;
155 nfs41_rpc_clnt *rpc;
156 uint32_t addr_index;
157 int status;
158 char machname[MAXHOSTNAMELEN + 1];
159 gid_t gids[1];
160 bool_t needcb = 1;
161
162 rpc = calloc(1, sizeof(nfs41_rpc_clnt));
163 if (rpc == NULL) {
165 goto out;
166 }
167#ifdef NO_CB_4_KRB5P
169 needcb = 0;
170#endif
171 rpc->needcb = needcb;
172 rpc->cond = CreateEvent(NULL, TRUE, FALSE, NULL);
173 if (rpc->cond == NULL) {
175 eprintf("CreateEvent failed %d\n", status);
176 goto out_free_rpc_clnt;
177 }
178 status = get_client_for_multi_addr(addrs, wsize, rsize, needcb?rpc:NULL,
179 rpc->server_name, &client, &addr_index);
180 if (status) {
181 clnt_pcreateerror("connecting failed");
182 goto out_free_rpc_cond;
183 }
184 if (send_null(client) != RPC_SUCCESS) {
185 // XXX Do what here?
186 eprintf("nfs41_rpc_clnt_create: send_null failed\n");
188 goto out_err_client;
189 }
190
191 rpc->sec_flavor = sec_flavor;
193 if (gethostname(machname, sizeof(machname)) == -1) {
194 eprintf("nfs41_rpc_clnt_create: gethostname failed\n");
195 goto out_err_client;
196 }
197 machname[sizeof(machname) - 1] = '\0';
198 client->cl_auth = authsys_create(machname, uid, gid, 0, gids);
199 if (client->cl_auth == NULL) {
200 eprintf("nfs41_rpc_clnt_create: failed to create rpc authsys\n");
202 goto out_err_client;
203 }
204 } else {
206 if (status) {
207 eprintf("nfs41_rpc_clnt_create: failed to establish security "
208 "context with %s\n", rpc->server_name);
210 goto out_err_client;
211 } else
212 dprintf(1, "nfs41_rpc_clnt_create: successfully created %s\n",
214 }
215 rpc->rpc = client;
216
217 /* keep a copy of the address and buffer sizes for reconnect */
218 memcpy(&rpc->addrs, addrs, sizeof(multi_addr4));
219 /* save the index of the address we connected to */
220 rpc->addr_index = addr_index;
221 rpc->wsize = wsize;
222 rpc->rsize = rsize;
223 rpc->is_valid_session = TRUE;
224 rpc->uid = uid;
225 rpc->gid = gid;
226
227 //initialize rpc client lock
228 InitializeSRWLock(&rpc->lock);
229
230 *rpc_out = rpc;
231out:
232 return status;
233out_err_client:
235out_free_rpc_cond:
236 CloseHandle(rpc->cond);
237out_free_rpc_clnt:
238 free(rpc);
239 goto out;
240}
#define authsys_create(c, i1, i2, i3, ip)
Definition: auth.h:323
#define MAXHOSTNAMELEN
Definition: ftp.c:31
#define clnt_destroy(rh)
Definition: clnt.h:276
void clnt_pcreateerror(char *s) const
Definition: clnt_perror.c:307
@ RPC_SUCCESS
Definition: clnt_stat.h:22
const char * secflavorop2name(DWORD sec_flavor)
Definition: daemon_debug.c:558
int32_t bool_t
Definition: types.h:101
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UINT gid_t
Definition: types.h:89
#define CloseHandle
Definition: compat.h:739
VOID WINAPI InitializeSRWLock(PSRWLOCK Lock)
Definition: sync.c:29
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
Definition: getxbyxx.c:397
@ RPCSEC_AUTH_SYS
Definition: nfs41_driver.h:75
@ RPCSEC_AUTHGSS_KRB5P
Definition: nfs41_driver.h:78
static int get_client_for_multi_addr(IN const multi_addr4 *addrs, IN uint32_t wsize, IN uint32_t rsize, IN nfs41_rpc_clnt *rpc, OUT OPTIONAL char *server_name, OUT CLIENT **client_out, OUT uint32_t *addr_index)
Definition: nfs41_rpc.c:83
static enum clnt_stat send_null(CLIENT *client)
Definition: nfs41_rpc.c:33
int create_rpcsec_auth_client(IN uint32_t sec_flavor, IN char *server_name, CLIENT *client)
Definition: nfs41_rpc.c:105
uint32_t uid
Definition: nfs41.h:178
uint32_t gid
Definition: nfs41.h:179
struct __rpc_client * rpc
Definition: nfs41.h:168
multi_addr4 addrs
Definition: nfs41.h:172
SRWLOCK lock
Definition: nfs41.h:169
uint32_t addr_index
Definition: nfs41.h:173
HANDLE cond
Definition: nfs41.h:170
bool_t is_valid_session
Definition: nfs41.h:181
uint32_t rsize
Definition: nfs41.h:175
uint32_t wsize
Definition: nfs41.h:174
char server_name[NI_MAXHOST]
Definition: nfs41.h:180
uint32_t sec_flavor
Definition: nfs41.h:177
bool_t needcb
Definition: nfs41.h:183
#define CreateEvent
Definition: winbase.h:3773
#define ERROR_NETWORK_UNREACHABLE
Definition: winerror.h:734

Referenced by nfs41_root_mount_addrs().

◆ nfs41_rpc_clnt_free()

void nfs41_rpc_clnt_free ( IN nfs41_rpc_clnt rpc)

Definition at line 243 of file nfs41_rpc.c.

245{
246 auth_destroy(rpc->rpc->cl_auth);
247 clnt_destroy(rpc->rpc);
248 CloseHandle(rpc->cond);
249 free(rpc);
250}
#define auth_destroy(auth)
Definition: auth.h:259

Referenced by nfs41_client_create(), nfs41_client_free(), and nfs41_root_mount_addrs().

◆ nfs41_rpc_netaddr()

static __inline netaddr4 * nfs41_rpc_netaddr ( IN nfs41_rpc_clnt rpc)
static

Definition at line 500 of file nfs41.h.

502{
503 uint32_t id;
504 AcquireSRWLockShared(&rpc->lock);
505 /* only addr_index needs to be protected, as rpc->addrs is write-once */
506 id = rpc->addr_index;
507 ReleaseSRWLockShared(&rpc->lock);
508
509 /* return the netaddr used to create the rpc client */
510 return &rpc->addrs.arr[id];
511}
GLuint id
Definition: glext.h:5910

Referenced by update_server().

◆ nfs41_send_compound()

int nfs41_send_compound ( IN nfs41_rpc_clnt rpc,
IN char inbuf,
OUT char outbuf 
)

Definition at line 337 of file nfs41_rpc.c.

341{
342 struct timeval timeout = {90, 100};
343 enum clnt_stat rpc_status;
344 int status, count = 0, one = 1, zero = 0;
346
347 try_again:
348 AcquireSRWLockShared(&rpc->lock);
349 version = rpc->version;
350 rpc_status = clnt_call(rpc->rpc, 1,
353 timeout);
354 ReleaseSRWLockShared(&rpc->lock);
355
356 if (rpc_status != RPC_SUCCESS) {
357 eprintf("clnt_call returned rpc_status = %s\n",
358 rpc_error_string(rpc_status));
359 switch(rpc_status) {
360 case RPC_CANTRECV:
361 case RPC_CANTSEND:
362 case RPC_TIMEDOUT:
363 case RPC_AUTHERROR:
364 if (++count > 3 || !rpc->is_valid_session) {
366 break;
367 }
368 if (rpc_should_retry(rpc, version))
369 goto try_again;
370 while (rpc_renew_in_progress(rpc, NULL)) {
371 status = WaitForSingleObject(rpc->cond, INFINITE);
372 if (status != WAIT_OBJECT_0) {
373 dprintf(1, "rpc_renew_in_progress: WaitForSingleObject failed\n");
376 goto out;
377 }
379 goto try_again;
380 }
382 if (rpc_status == RPC_AUTHERROR && rpc->sec_flavor != RPCSEC_AUTH_SYS) {
383 AcquireSRWLockExclusive(&rpc->lock);
384 auth_destroy(rpc->rpc->cl_auth);
385 status = create_rpcsec_auth_client(rpc->sec_flavor,
386 rpc->server_name, rpc->rpc);
387 ReleaseSRWLockExclusive(&rpc->lock);
388 if (status) {
389 eprintf("Failed to reestablish security context\n");
391 goto out;
392 }
393 } else
394 if (rpc_reconnect(rpc))
395 eprintf("rpc_reconnect: Failed to reconnect!\n");
397 goto try_again;
398 default:
399 eprintf("UNHANDLED RPC_ERROR: %d\n", rpc_status);
401 goto out;
402 }
403 goto out;
404 }
405
406 status = 0;
407out:
408 return status;
409}
static int inbuf
Definition: adnsresfilter.c:73
#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs)
Definition: clnt.h:202
clnt_stat
Definition: clnt_stat.h:21
@ RPC_TIMEDOUT
Definition: clnt_stat.h:31
@ RPC_AUTHERROR
Definition: clnt_stat.h:38
@ RPC_CANTSEND
Definition: clnt_stat.h:28
@ RPC_CANTRECV
Definition: clnt_stat.h:29
const char * rpc_error_string(int status)
Definition: daemon_debug.c:482
void print_condwait_status(int level, int status)
Definition: daemon_debug.c:513
static const WCHAR version[]
Definition: asmname.c:66
#define INFINITE
Definition: serial.h:102
static bool_t rpc_renew_in_progress(nfs41_rpc_clnt *rpc, int *value)
Definition: nfs41_rpc.c:252
static int rpc_reconnect(IN nfs41_rpc_clnt *rpc)
Definition: nfs41_rpc.c:279
static bool_t rpc_should_retry(nfs41_rpc_clnt *rpc, uint32_t version)
Definition: nfs41_rpc.c:269
bool_t nfs_encode_compound(XDR *xdr, caddr_t *pargs)
Definition: nfs41_xdr.c:3591
bool_t nfs_decode_compound(XDR *xdr, caddr_t *pres)
Definition: nfs41_xdr.c:3625
int one
Definition: sehframes.cpp:28
int zero
Definition: sehframes.cpp:29
Definition: dhcpd.h:245
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define WAIT_OBJECT_0
Definition: winbase.h:432
#define ERROR_LOCK_VIOLATION
Definition: winerror.h:136
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144

Referenced by compound_encode_send_decode(), nfs41_bind_conn_to_session(), nfs41_destroy_clientid(), and nfs41_exchange_id().

◆ nfs41_server_addrs()

void nfs41_server_addrs ( IN nfs41_server server,
OUT multi_addr4 addrs 
)

Definition at line 203 of file nfs41_server.c.

206{
207 struct server_addrs *saddrs = &server->addrs;
208 uint32_t i, j;
209
210 /* make a copy of the server's addrs, with most recent first */
211 AcquireSRWLockShared(&saddrs->lock);
212 j = saddrs->next_index;
213 for (i = 0; i < saddrs->addrs.count; i++) {
214 /* decrement/wrap j */
216 memcpy(&addrs->arr[i], &saddrs->addrs.arr[j], sizeof(netaddr4));
217 }
218 ReleaseSRWLockShared(&saddrs->lock);
219}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define NFS41_ADDRS_PER_SERVER
Definition: nfs41_const.h:49
netaddr4 arr[NFS41_ADDRS_PER_SERVER]
Definition: nfs41_types.h:91
uint32_t count
Definition: nfs41_types.h:92
uint32_t next_index
Definition: nfs41.h:75
multi_addr4 addrs
Definition: nfs41.h:74
SRWLOCK lock
Definition: nfs41.h:76

◆ nfs41_server_deref()

void nfs41_server_deref ( IN nfs41_server server)

Definition at line 155 of file nfs41_server.c.

157{
159
160 server->ref_count--;
161 dprintf(SRVLVL, "nfs41_server_deref(%s) count %d\n",
162 server->owner, server->ref_count);
163 if (server->ref_count == 0) {
164 list_remove(&server->entry);
166 }
167
169}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void server_free(IN nfs41_server *server)
Definition: nfs41_server.c:128
#define SRVLVL
Definition: nfs41_server.c:35
static struct server_list g_server_list
Definition: nfs41_server.c:43

Referenced by nfs41_client_free(), and update_server().

◆ nfs41_server_find_or_create()

int nfs41_server_find_or_create ( IN const char server_owner_major_id,
IN const char server_scope,
IN const netaddr4 addr,
OUT nfs41_server **  server_out 
)

Definition at line 221 of file nfs41_server.c.

226{
227 struct server_info info;
228 struct list_entry *entry;
230 int status;
231
232 info.owner = server_owner_major_id;
233 info.scope = server_scope;
234
235 dprintf(SRVLVL, "--> nfs41_server_find_or_create(%s)\n", info.owner);
236
238
239 /* search for an existing server */
241 if (entry == NULL) {
242 /* create a new server */
244 if (status == NO_ERROR) {
245 /* add it to the list */
246 list_add_tail(&g_server_list.head, &server->entry);
247 *server_out = server;
248
249 dprintf(SRVLVL, "<-- nfs41_server_find_or_create() "
250 "returning new server %p\n", server);
251 } else {
252 dprintf(SRVLVL, "<-- nfs41_server_find_or_create() "
253 "returning %d\n", status);
254 }
255 } else {
258
259 dprintf(SRVLVL, "<-- nfs41_server_find_or_create() "
260 "returning existing server %p\n", server);
261 }
262
263 if (server) {
264 /* register the address used to connect */
265 server_addrs_add(&server->addrs, addr);
266
268 }
269
270 *server_out = server;
272 return status;
273}
static struct list_entry * list_search(const struct list_entry *head, const void *value, list_compare_fn compare)
Definition: list.h:102
GLenum const GLvoid * addr
Definition: glext.h:9621
uint32_t entry
Definition: isohybrid.c:63
#define server_entry(pos)
Definition: nfs41_server.c:45
static __inline void server_ref_locked(IN nfs41_server *server)
Definition: nfs41_server.c:137
static void server_addrs_add(IN OUT struct server_addrs *addrs, IN const netaddr4 *addr)
Definition: nfs41_server.c:171
static int server_compare(const struct list_entry *entry, const void *value)
Definition: nfs41_server.c:75
static int server_create(IN const struct server_info *info, OUT nfs41_server **server_out)
Definition: nfs41_server.c:94
Definition: list.h:27

Referenced by update_server().

◆ nfs41_server_list_init()

void nfs41_server_list_init ( )

Definition at line 48 of file nfs41_server.c.

Referenced by ServiceStart().

◆ nfs41_server_ref()

void nfs41_server_ref ( IN nfs41_server server)

Definition at line 145 of file nfs41_server.c.

◆ nfs41_server_resolve()

int nfs41_server_resolve ( IN const char hostname,
IN unsigned short  port,
OUT multi_addr4 addrs 
)

Definition at line 275 of file nfs41_server.c.

279{
281 char service[16];
282 struct addrinfo hints = { 0 }, *res, *info;
283 struct netconfig *nconf;
284 struct netbuf addr;
285 char *netid, *uaddr;
286
287 dprintf(SRVLVL, "--> nfs41_server_resolve(%s:%u)\n",
288 hostname, port);
289
290 addrs->count = 0;
291
292 StringCchPrintfA(service, 16, "%u", port);
293
294 /* request a list of tcp addrs for the given hostname,port */
295 hints.ai_family = AF_UNSPEC;
296 hints.ai_socktype = SOCK_STREAM;
297 hints.ai_protocol = IPPROTO_TCP;
298
299 if (getaddrinfo(hostname, service, &hints, &res) != 0)
300 goto out;
301
302 for (info = res; info != NULL; info = info->ai_next) {
303 /* find the appropriate entry in /etc/netconfig */
304 switch (info->ai_family) {
305 case AF_INET: netid = "tcp"; break;
306 case AF_INET6: netid = "tcp6"; break;
307 default: continue;
308 }
309
310 nconf = getnetconfigent(netid);
311 if (nconf == NULL)
312 continue;
313
314 /* convert to a transport-independent universal address */
315 addr.buf = info->ai_addr;
316 addr.maxlen = addr.len = (unsigned int)info->ai_addrlen;
317
318 uaddr = taddr2uaddr(nconf, &addr);
319 freenetconfigent(nconf);
320
321 if (uaddr == NULL)
322 continue;
323
324 StringCchCopyA(addrs->arr[addrs->count].netid,
325 NFS41_NETWORK_ID_LEN+1, netid);
326 StringCchCopyA(addrs->arr[addrs->count].uaddr,
327 NFS41_UNIVERSAL_ADDR_LEN+1, uaddr);
328 freeuaddr(uaddr);
329
331 if (++addrs->count >= NFS41_ADDRS_PER_SERVER)
332 break;
333 }
335out:
336 if (status)
337 dprintf(SRVLVL, "<-- nfs41_server_resolve(%s:%u) returning "
338 "error %d\n", hostname, port, status);
339 else
340 dprintf(SRVLVL, "<-- nfs41_server_resolve(%s:%u) returning "
341 "%s\n", hostname, port, addrs->arr[0].uaddr);
342 return status;
343}
char * hostname
Definition: ftp.c:88
USHORT port
Definition: uri.c:228
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define IPPROTO_TCP
Definition: ip.h:196
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
void freenetconfigent(struct netconfig *netconfigp)
Definition: getnetconfig.c:530
struct netconfig * getnetconfigent(char *netid) const
Definition: getnetconfig.c:432
GLuint res
Definition: glext.h:9613
#define NFS41_UNIVERSAL_ADDR_LEN
Definition: nfs41_const.h:53
#define NFS41_NETWORK_ID_LEN
Definition: nfs41_const.h:56
char * taddr2uaddr(const struct netconfig *nconf, const struct netbuf *nbuf)
Definition: rpc_generic.c:609
void freeuaddr(char *uaddr)
Definition: rpc_generic.c:628
namespace GUID const ADDRINFOEXW * hints
Definition: sock.c:80
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
STRSAFEAPI StringCchPrintfA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:520
Definition: types.h:144
#define AF_INET6
Definition: winsock.h:369
#define AF_UNSPEC
Definition: winsock.h:344
#define getaddrinfo
Definition: wspiapi.h:44
#define freeaddrinfo
Definition: wspiapi.h:46

Referenced by handle_mount(), and referral_mount_location().

◆ nfs41_session_bad_slot()

int nfs41_session_bad_slot ( IN nfs41_session session,
IN OUT struct __nfs41_sequence_args args 
)

◆ nfs41_session_bump_seq()

void nfs41_session_bump_seq ( IN nfs41_session session,
IN uint32_t  slotid,
IN uint32_t  target_highest_slotid 
)

Definition at line 80 of file nfs41_session.c.

84{
86
87 AcquireSRWLockShared(&session->client->session_lock);
89
90 if (slotid < NFS41_MAX_NUM_SLOTS)
91 table->seq_nums[slotid]++;
92
93 /* adjust max_slots in response to changes in target_highest_slotid,
94 * but not immediately after a CB_RECALL_SLOT or NFS4ERR_BADSLOT error */
95 if (table->target_delay <= GetTickCount64())
96 resize_slot_table(table, target_highest_slotid);
97
99 ReleaseSRWLockShared(&session->client->session_lock);
100}
#define NFS41_MAX_NUM_SLOTS
Definition: nfs41.h:218
static void resize_slot_table(IN nfs41_slot_table *table, IN uint32_t target_highest_slotid)
Definition: nfs41_session.c:63

Referenced by compound_encode_send_decode().

◆ nfs41_session_create()

int nfs41_session_create ( IN nfs41_client client,
IN nfs41_session **  session_out 
)

Definition at line 278 of file nfs41_session.c.

281{
283 int status;
284
286 if (status) {
287 eprintf("session_alloc() failed with %d\n", status);
288 goto out;
289 }
290
291 AcquireSRWLockShared(&client->exid_lock);
292 if (client->rpc->needcb)
295 ReleaseSRWLockShared(&client->exid_lock);
296
298 if (status) {
299 eprintf("nfs41_create_session failed %d\n", status);
301 goto out_err;
302 }
303
304 AcquireSRWLockExclusive(&session->client->session_lock);
305 client->session = session;
306 session->isValidState = TRUE;
307 ReleaseSRWLockExclusive(&session->client->session_lock);
308 *session_out = session;
309out:
310 return status;
311
312out_err:
314 goto out;
315}
#define CREATE_SESSION4_FLAG_PERSIST
Definition: nfs41_const.h:307
#define CREATE_SESSION4_FLAG_CONN_BACK_CHAN
Definition: nfs41_const.h:308
int nfs41_create_session(nfs41_client *clnt, nfs41_session *session, bool_t try_recovery)
Definition: nfs41_ops.c:101
static int session_alloc(IN nfs41_client *client, OUT nfs41_session **session_out)
void nfs41_session_free(IN nfs41_session *session)

Referenced by root_client_create().

◆ nfs41_session_free()

void nfs41_session_free ( IN nfs41_session session)

Definition at line 363 of file nfs41_session.c.

365{
366 AcquireSRWLockExclusive(&session->client->session_lock);
367 if (valid_handle(session->renew_thread)) {
368 dprintf(1, "nfs41_session_free: terminating session renewal thread\n");
369 if (!TerminateThread(session->renew_thread, NO_ERROR))
370 eprintf("failed to terminate renewal thread %p\n",
371 session->renew_thread);
372 }
373
374 if (session->isValidState) {
375 session->client->rpc->is_valid_session = FALSE;
377 }
378 DeleteCriticalSection(&session->table.lock);
379 ReleaseSRWLockExclusive(&session->client->session_lock);
380 free(session);
381}
__inline int valid_handle(HANDLE handle)
Definition: util.h:281
BOOL WINAPI TerminateThread(IN HANDLE hThread, IN DWORD dwExitCode)
Definition: thread.c:587
int nfs41_destroy_session(IN nfs41_session *session)
Definition: nfs41_ops.c:214

Referenced by nfs41_client_free(), and nfs41_session_create().

◆ nfs41_session_free_slot()

void nfs41_session_free_slot ( IN nfs41_session session,
IN uint32_t  slotid 
)

Definition at line 102 of file nfs41_session.c.

105{
106 nfs41_slot_table *table = &session->table;
107
108 AcquireSRWLockShared(&session->client->session_lock);
110
111 /* flag the slot as unused */
112 if (slotid < NFS41_MAX_NUM_SLOTS && table->used_slots[slotid]) {
113 table->used_slots[slotid] = 0;
114 table->num_used--;
115 }
116 /* update highest_used if necessary */
117 if (slotid == table->highest_used) {
118 while (table->highest_used && !table->used_slots[table->highest_used])
119 table->highest_used--;
120 }
121 dprintf(3, "freeing slot#=%d used=%d highest=%d\n",
122 slotid, table->num_used, table->highest_used);
123
124 /* wake any threads waiting on a slot */
127
129 ReleaseSRWLockShared(&session->client->session_lock);
130}
VOID WINAPI WakeAllConditionVariable(PCONDITION_VARIABLE ConditionVariable)
Definition: sync.c:91
static int slot_table_avail(IN const nfs41_slot_table *table)
Definition: nfs41_session.c:38

Referenced by compound_encode_send_decode(), and nfs41_session_bad_slot().

◆ nfs41_session_get_slot()

void nfs41_session_get_slot ( IN nfs41_session session,
OUT uint32_t slot,
OUT uint32_t seq,
OUT uint32_t highest 
)

Definition at line 132 of file nfs41_session.c.

137{
138 nfs41_slot_table *table = &session->table;
139 uint32_t i;
140
141 AcquireSRWLockShared(&session->client->session_lock);
143
144 /* wait for an available slot */
145 while (!slot_table_avail(table))
147
148 for (i = 0; i < table->max_slots; i++) {
149 if (table->used_slots[i])
150 continue;
151
152 table->used_slots[i] = 1;
153 table->num_used++;
154 if (i > table->highest_used)
155 table->highest_used = i;
156
157 *slot = i;
158 *seqid = table->seq_nums[i];
159 *highest = table->highest_used;
160 break;
161 }
163 ReleaseSRWLockShared(&session->client->session_lock);
164
165 dprintf(2, "session %p: using slot#=%d with seq#=%d highest=%d\n",
166 session, *slot, *seqid, *highest);
167}
BOOL WINAPI SleepConditionVariableCS(PCONDITION_VARIABLE ConditionVariable, PCRITICAL_SECTION CriticalSection, DWORD Timeout)
Definition: sync.c:59
Definition: vfat.h:185

Referenced by compound_encode_send_decode(), nfs41_session_bad_slot(), and nfs41_session_sequence().

◆ nfs41_session_recall_slot()

int nfs41_session_recall_slot ( IN nfs41_session session,
IN OUT uint32_t  target_highest_slotid 
)

Definition at line 169 of file nfs41_session.c.

172{
173 nfs41_slot_table *table = &session->table;
174
175 AcquireSRWLockShared(&session->client->session_lock);
177 resize_slot_table(table, target_highest_slotid);
178 table->target_delay = GetTickCount64() + MAX_SLOTS_DELAY;
180 ReleaseSRWLockShared(&session->client->session_lock);
181
182 return NFS4_OK;
183}
@ NFS4_OK
Definition: nfs41_const.h:87
#define MAX_SLOTS_DELAY
Definition: nfs41_session.c:34

Referenced by handle_cb_recall_slot().

◆ nfs41_session_renew()

int nfs41_session_renew ( IN nfs41_session session)

Definition at line 318 of file nfs41_session.c.

320{
321 int status;
322
323 AcquireSRWLockExclusive(&session->client->session_lock);
324 session->cb_session.cb_seqnum = 0;
325 init_slot_table(&session->table);
326
328 ReleaseSRWLockExclusive(&session->client->session_lock);
329 return status;
330}
static void init_slot_table(nfs41_slot_table *table)
Definition: nfs41_session.c:45

Referenced by nfs41_recover_session().

◆ nfs41_session_sequence()

◆ nfs41_session_set_lease()

int nfs41_session_set_lease ( IN nfs41_session session,
IN uint32_t  lease_time 
)

Definition at line 332 of file nfs41_session.c.

335{
336 int status = NO_ERROR;
338
339 if (valid_handle(session->renew_thread)) {
340 eprintf("nfs41_session_set_lease(): session "
341 "renewal thread already started!\n");
342 goto out;
343 }
344
345 if (lease_time == 0) {
346 eprintf("nfs41_session_set_lease(): invalid lease_time=0\n");
348 goto out;
349 }
350
351 session->lease_time = lease_time;
352 session->renew_thread = (HANDLE)_beginthreadex(NULL,
354 if (!valid_handle(session->renew_thread)) {
356 eprintf("_beginthreadex failed %d\n", status);
357 goto out;
358 }
359out:
360 return status;
361}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static DWORD thread_id
Definition: protocol.c:159
static unsigned int WINAPI renew_session(void *args)
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
PVOID HANDLE
Definition: typedefs.h:73

Referenced by session_get_lease().

◆ nfs41_superblock_for_fh()

int nfs41_superblock_for_fh ( IN nfs41_session session,
IN const nfs41_fsid fsid,
IN const nfs41_fh *parent  OPTIONAL,
OUT nfs41_path_fh file 
)

Definition at line 233 of file nfs41_superblock.c.

238{
239 int status = NFS4_OK;
241 nfs41_superblock_list *superblocks = &server->superblocks;
243
244 dprintf(SBLVL, "--> nfs41_superblock_for_fh(fsid(%llu,%llu))\n",
245 fsid->major, fsid->minor);
246
247 /* compare with the parent's fsid, and use that if it matches */
248 if (parent && parent->superblock &&
249 compare_fsid(fsid, &parent->superblock->fsid) == 0) {
250 file->fh.superblock = parent->superblock;
251 dprintf(SBLVL, "using superblock from parent\n");
252 goto out;
253 }
254
255 /* using a shared lock, search for an existing superblock */
256 AcquireSRWLockShared(&superblocks->lock);
257 superblock = find_superblock(superblocks, fsid);
258 ReleaseSRWLockShared(&superblocks->lock);
259
260 if (superblock) {
261 dprintf(SBLVL, "found existing superblock in server list "
262 "[shared lock]\n");
263 } else {
264 AcquireSRWLockExclusive(&superblocks->lock);
265 /* must search again under an exclusive lock, in case another thread
266 * created it after our first search */
267 superblock = find_superblock(superblocks, fsid);
268 if (superblock) {
269 dprintf(SBLVL, "found newly created superblock in server list "
270 "[exclusive lock]\n");
271 } else {
272 /* create the superblock */
274 if (status == NO_ERROR) /* add it to the list */
275 list_add_tail(&superblocks->head, &superblock->entry);
276 }
277 ReleaseSRWLockExclusive(&superblocks->lock);
278 }
279
280 if (status == NO_ERROR && superblock->supported_attrs.count == 0) {
281 /* exclusive lock on the superblock while fetching attributes */
283 if (superblock->supported_attrs.count == 0)
286 }
287
288 file->fh.superblock = superblock;
289out:
290 dprintf(SBLVL, "<-- nfs41_superblock_for_fh() returning %p, status %d\n",
291 file->fh.superblock, status);
292 return status;
293}
r parent
Definition: btrfs.c:3010
static __inline nfs41_server * client_server(IN nfs41_client *client)
Definition: nfs41.h:428
static nfs41_superblock * find_superblock(IN nfs41_superblock_list *superblocks, IN const nfs41_fsid *fsid)
#define SBLVL
static int superblock_create(IN const nfs41_fsid *fsid, OUT nfs41_superblock **superblock_out)
static __inline int compare_fsid(IN const nfs41_fsid *lhs, IN const nfs41_fsid *rhs)
static int get_superblock_attrs(IN nfs41_session *session, IN nfs41_superblock *superblock, IN nfs41_path_fh *file)
struct list_entry head
Definition: nfs41.h:69
Definition: fci.c:127

Referenced by nfs41_link(), nfs41_open(), and server_lookup().

◆ nfs41_superblock_fs_attributes()

void nfs41_superblock_fs_attributes ( IN const nfs41_superblock superblock,
OUT struct _FILE_FS_ATTRIBUTE_INFORMATION FsAttrs 
)

Referenced by handle_mount(), and handle_volume().

◆ nfs41_superblock_getattr_mask()

static __inline void nfs41_superblock_getattr_mask ( IN const nfs41_superblock superblock,
OUT bitmap4 attrs 
)
static

◆ nfs41_superblock_list_free()

void nfs41_superblock_list_free ( IN nfs41_superblock_list superblocks)

Definition at line 221 of file nfs41_superblock.c.

223{
224 struct list_entry *entry, *tmp;
225
226 dprintf(SBLVL, "nfs41_superblock_list_free()\n");
227
228 list_for_each_tmp(entry, tmp, &superblocks->head)
230}
#define list_for_each_tmp(entry, tmp, head)
Definition: list.h:39
#define superblock_entry(pos)

Referenced by server_free().

◆ nfs41_superblock_list_init()

void nfs41_superblock_list_init ( IN nfs41_superblock_list superblocks)

Definition at line 214 of file nfs41_superblock.c.

216{
217 list_init(&superblocks->head);
218 InitializeSRWLock(&superblocks->lock);
219}

Referenced by server_create().

◆ nfs41_superblock_space_changed()

void nfs41_superblock_space_changed ( IN nfs41_superblock superblock)

Definition at line 295 of file nfs41_superblock.c.

297{
298 /* invalidate cached volume size attributes */
300 superblock->cache_expiration = 0;
302}

Referenced by nfs41_commit(), nfs41_create(), nfs41_link(), nfs41_open(), nfs41_remove(), nfs41_setattr(), and nfs41_write().

◆ nfs41_superblock_supported_attrs()

static __inline void nfs41_superblock_supported_attrs ( IN const nfs41_superblock superblock,
IN OUT bitmap4 attrs 
)
static

Definition at line 454 of file nfs41.h.

457{
458 bitmap_intersect(attrs, &superblock->supported_attrs);
459}
static __inline void bitmap_intersect(IN bitmap4 *dst, IN const bitmap4 *src)
Definition: util.h:85

Referenced by delegation_truncate(), get_superblock_attrs(), nfs41_create(), and nfs41_open().

◆ nfs41_superblock_supported_attrs_exclcreat()

static __inline void nfs41_superblock_supported_attrs_exclcreat ( IN const nfs41_superblock superblock,
IN OUT bitmap4 attrs 
)
static

Definition at line 460 of file nfs41.h.

463{
464 bitmap_intersect(attrs, &superblock->suppattr_exclcreat);
465}

Referenced by nfs41_open().