ReactOS  0.4.12-dev-102-g4b7f1e0
pnfs_device.c File Reference
#include <windows.h>
#include <strsafe.h>
#include <stdio.h>
#include "nfs41_ops.h"
#include "nfs41_callback.h"
#include "daemon_debug.h"
Include dependency graph for pnfs_device.c:

Go to the source code of this file.

Classes

struct  pnfs_file_device_list
 

Macros

#define FDLVL   2 /* dprintf level for file device logging */
 
#define device_entry(pos)   list_container(pos, pnfs_file_device, entry)
 

Functions

static enum pnfs_status file_device_create (IN const unsigned char *deviceid, IN struct pnfs_file_device_list *devices, OUT pnfs_file_device **device_out)
 
static void file_device_free (IN pnfs_file_device *device)
 
static int deviceid_compare (const struct list_entry *entry, const void *deviceid)
 
static enum pnfs_status file_device_find_or_create (IN const unsigned char *deviceid, IN struct pnfs_file_device_list *devices, OUT pnfs_file_device **device_out)
 
enum pnfs_status pnfs_file_device_list_create (OUT struct pnfs_file_device_list **devices_out)
 
void pnfs_file_device_list_free (IN struct pnfs_file_device_list *devices)
 
void pnfs_file_device_list_invalidate (IN struct pnfs_file_device_list *devices)
 
enum pnfs_status pnfs_file_device_get (IN nfs41_session *session, IN struct pnfs_file_device_list *devices, IN unsigned char *deviceid, OUT pnfs_file_device **device_out)
 
void pnfs_file_device_put (IN pnfs_file_device *device)
 
static enum pnfs_status data_client_status (IN pnfs_data_server *server, OUT nfs41_client **client_out)
 
enum pnfs_status pnfs_data_server_client (IN nfs41_root *root, IN pnfs_data_server *server, IN uint32_t default_lease, OUT nfs41_client **client_out)
 
enum pnfs_status pnfs_file_device_notify (IN struct pnfs_file_device_list *devices, IN const struct notify_deviceid4 *change)
 

Macro Definition Documentation

◆ device_entry

◆ FDLVL

Function Documentation

◆ data_client_status()

static enum pnfs_status data_client_status ( IN pnfs_data_server server,
OUT nfs41_client **  client_out 
)
static

Definition at line 268 of file pnfs_device.c.

Referenced by pnfs_data_server_client().

271 {
273 
274  if (server->client) {
275  dprintf(FDLVL, "pnfs_data_server_client() returning "
276  "existing client %llu\n", server->client->clnt_id);
277  *client_out = server->client;
278  status = PNFS_SUCCESS;
279  }
280  return status;
281 }
pnfs_status
Definition: pnfs.h:58
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define FDLVL
Definition: pnfs_device.c:31
#define dprintf
Definition: regdump.c:33
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ deviceid_compare()

static int deviceid_compare ( const struct list_entry entry,
const void deviceid 
)
static

Definition at line 74 of file pnfs_device.c.

Referenced by file_device_find_or_create(), and pnfs_file_device_notify().

77 {
78  const pnfs_file_device *device = device_entry(entry);
79  return memcmp(device->device.deviceid, deviceid, PNFS_DEVICEID_SIZE);
80 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
unsigned char deviceid[PNFS_DEVICEID_SIZE]
Definition: pnfs.h:116
#define PNFS_DEVICEID_SIZE
Definition: pnfs.h:111
#define device_entry(pos)
Definition: pnfs_device.c:40
Definition: devices.h:37
pnfs_device device
Definition: pnfs.h:140

◆ file_device_create()

static enum pnfs_status file_device_create ( IN const unsigned char deviceid,
IN struct pnfs_file_device_list devices,
OUT pnfs_file_device **  device_out 
)
static

Definition at line 43 of file pnfs_device.c.

Referenced by file_device_find_or_create().

47 {
50 
51  device = calloc(1, sizeof(pnfs_file_device));
52  if (device == NULL) {
53  status = PNFSERR_RESOURCES;
54  goto out;
55  }
56 
57  memcpy(device->device.deviceid, deviceid, PNFS_DEVICEID_SIZE);
58  device->devices = devices;
60  *device_out = device;
61 out:
62  return status;
63 }
pnfs_status
Definition: pnfs.h:58
const char * devices
Definition: diskspace.c:793
unsigned char deviceid[PNFS_DEVICEID_SIZE]
Definition: pnfs.h:116
#define PNFS_DEVICEID_SIZE
Definition: pnfs.h:111
CRITICAL_SECTION lock
Definition: pnfs.h:120
Definition: devices.h:37
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
smooth NULL
Definition: ftsmooth.c:416
pnfs_device device
Definition: pnfs.h:140
static FILE * out
Definition: regtests2xml.c:44
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define calloc
Definition: rosglue.h:14
static SERVICE_STATUS status
Definition: service.c:31
struct pnfs_file_device_list * devices
Definition: pnfs.h:143
Definition: ps.c:97

◆ file_device_find_or_create()

static enum pnfs_status file_device_find_or_create ( IN const unsigned char deviceid,
IN struct pnfs_file_device_list devices,
OUT pnfs_file_device **  device_out 
)
static

Definition at line 82 of file pnfs_device.c.

Referenced by pnfs_file_device_get().

86 {
87  struct list_entry *entry;
88  enum pnfs_status status;
89 
90  dprintf(FDLVL, "--> pnfs_file_device_find_or_create()\n");
91 
93 
94  /* search for an existing device */
95  entry = list_search(&devices->head, deviceid, deviceid_compare);
96  if (entry == NULL) {
97  /* create a new device */
99  status = file_device_create(deviceid, devices, &device);
100  if (status == PNFS_SUCCESS) {
101  /* add it to the list */
102  list_add_tail(&devices->head, &device->entry);
103  *device_out = device;
104 
105  dprintf(FDLVL, "<-- pnfs_file_device_find_or_create() "
106  "returning new device %p\n", device);
107  } else {
108  dprintf(FDLVL, "<-- pnfs_file_device_find_or_create() "
109  "returning %s\n", pnfs_error_string(status));
110  }
111  } else {
112  *device_out = device_entry(entry);
113  status = PNFS_SUCCESS;
114 
115  dprintf(FDLVL, "<-- pnfs_file_device_find_or_create() "
116  "returning existing device %p\n", *device_out);
117  }
118 
120  return status;
121 }
pnfs_status
Definition: pnfs.h:58
const char * devices
Definition: diskspace.c:793
uint8_t entry
Definition: isohybrid.c:63
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define device_entry(pos)
Definition: pnfs_device.c:40
#define FDLVL
Definition: pnfs_device.c:31
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
Definition: devices.h:37
#define dprintf
Definition: regdump.c:33
smooth NULL
Definition: ftsmooth.c:416
const char * pnfs_error_string(enum pnfs_status status)
Definition: pnfs_debug.c:28
static enum pnfs_status file_device_create(IN const unsigned char *deviceid, IN struct pnfs_file_device_list *devices, OUT pnfs_file_device **device_out)
Definition: pnfs_device.c:43
static struct list_entry * list_search(const struct list_entry *head, const void *value, list_compare_fn compare)
Definition: list.h:102
Definition: list.h:27
struct list_entry entry
Definition: pnfs.h:144
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static int deviceid_compare(const struct list_entry *entry, const void *deviceid)
Definition: pnfs_device.c:74
static SERVICE_STATUS status
Definition: service.c:31

◆ file_device_free()

static void file_device_free ( IN pnfs_file_device device)
static

Definition at line 65 of file pnfs_device.c.

Referenced by pnfs_file_device_list_free(), pnfs_file_device_list_invalidate(), and pnfs_file_device_put().

67 {
68  free(device->servers.arr);
69  free(device->stripes.arr);
70  DeleteCriticalSection(&device->device.lock);
71  free(device);
72 }
#define free
Definition: debug_ros.c:5
Definition: devices.h:37
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

◆ pnfs_data_server_client()

enum pnfs_status pnfs_data_server_client ( IN nfs41_root root,
IN pnfs_data_server server,
IN uint32_t  default_lease,
OUT nfs41_client **  client_out 
)

Definition at line 283 of file pnfs_device.c.

288 {
289  int status;
290  enum pnfs_status pnfsstat;
291 
292  dprintf(FDLVL, "--> pnfs_data_server_client('%s')\n",
293  server->addrs.arr[0].uaddr);
294 
295  /* if we've already created the client, return it */
297  pnfsstat = data_client_status(server, client_out);
299 
300  if (!pnfsstat)
301  goto out;
302 
304 
305  pnfsstat = data_client_status(server, client_out);
306  if (pnfsstat) {
307  status = nfs41_root_mount_addrs(root, &server->addrs, 1, default_lease,
308  &server->client);
309  if (status) {
310  dprintf(FDLVL, "data_client_create('%s') failed with %d\n",
311  server->addrs.arr[0].uaddr, status);
312  } else {
313  *client_out = server->client;
314  pnfsstat = PNFS_SUCCESS;
315 
316  dprintf(FDLVL, "pnfs_data_server_client() returning new client "
317  "%llu\n", server->client->clnt_id);
318  }
319  }
320 
322 out:
323  return pnfsstat;
324 }
pnfs_status
Definition: pnfs.h:58
VOID WINAPI AcquireSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:54
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define FDLVL
Definition: pnfs_device.c:31
#define dprintf
Definition: regdump.c:33
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: namespace.c:335
static FILE * out
Definition: regtests2xml.c:44
VOID WINAPI ReleaseSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:82
static enum pnfs_status data_client_status(IN pnfs_data_server *server, OUT nfs41_client **client_out)
Definition: pnfs_device.c:268
static SERVICE_STATUS status
Definition: service.c:31
VOID WINAPI AcquireSRWLockShared(PSRWLOCK Lock)
Definition: sync.c:61
VOID WINAPI ReleaseSRWLockShared(PSRWLOCK Lock)
Definition: sync.c:89

◆ pnfs_file_device_get()

enum pnfs_status pnfs_file_device_get ( IN nfs41_session session,
IN struct pnfs_file_device_list devices,
IN unsigned char deviceid,
OUT pnfs_file_device **  device_out 
)

Definition at line 192 of file pnfs_device.c.

197 {
199  enum pnfs_status status;
200  enum nfsstat4 nfsstat;
201 
202  dprintf(FDLVL, "--> pnfs_file_device_get()\n");
203 
204  status = file_device_find_or_create(deviceid, devices, &device);
205  if (status)
206  goto out;
207 
208  EnterCriticalSection(&device->device.lock);
209 
210  /* don't give out a device that's been revoked */
211  if (device->device.status & PNFS_DEVICE_REVOKED)
212  status = PNFSERR_NO_DEVICE;
213  else if (device->device.status & PNFS_DEVICE_GRANTED)
214  status = PNFS_SUCCESS;
215  else {
216  nfsstat = pnfs_rpc_getdeviceinfo(session, deviceid, device);
217  if (nfsstat == NFS4_OK) {
219  status = PNFS_SUCCESS;
220 
221  dprintf(FDLVL, "Received device info:\n");
222  dprint_device(FDLVL, device);
223  } else {
224  status = PNFSERR_NO_DEVICE;
225 
226  eprintf("pnfs_rpc_getdeviceinfo() failed with %s\n",
227  nfs_error_string(nfsstat));
228  }
229  }
230 
231  if (status == PNFS_SUCCESS) {
232  device->device.layout_count++;
233  dprintf(FDLVL, "pnfs_file_device_get() -> %u\n",
234  device->device.layout_count);
235  *device_out = device;
236  }
237 
238  LeaveCriticalSection(&device->device.lock);
239 out:
240  dprintf(FDLVL, "<-- pnfs_file_device_get() returning %s\n",
241  pnfs_error_string(status));
242  return status;
243 }
pnfs_status
Definition: pnfs.h:58
static enum pnfs_status file_device_find_or_create(IN const unsigned char *deviceid, IN struct pnfs_file_device_list *devices, OUT pnfs_file_device **device_out)
Definition: pnfs_device.c:82
uint32_t layout_count
Definition: pnfs.h:119
const char * devices
Definition: diskspace.c:793
enum nfsstat4 pnfs_rpc_getdeviceinfo(IN nfs41_session *session, IN unsigned char *deviceid, OUT pnfs_file_device *device)
Definition: nfs41_ops.c:2109
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
CRITICAL_SECTION lock
Definition: pnfs.h:120
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define FDLVL
Definition: pnfs_device.c:31
Definition: devices.h:37
#define dprintf
Definition: regdump.c:33
const char * pnfs_error_string(enum pnfs_status status)
Definition: pnfs_debug.c:28
pnfs_device device
Definition: pnfs.h:140
static FILE * out
Definition: regtests2xml.c:44
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
nfsstat4
Definition: nfs41_const.h:86
void dprint_device(int level, const struct __pnfs_file_device *device)
enum pnfs_device_status status
Definition: pnfs.h:118
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static SERVICE_STATUS status
Definition: service.c:31

◆ pnfs_file_device_list_create()

enum pnfs_status pnfs_file_device_list_create ( OUT struct pnfs_file_device_list **  devices_out)

Definition at line 124 of file pnfs_device.c.

Referenced by pnfs_client_init().

126 {
129 
130  devices = calloc(1, sizeof(struct pnfs_file_device_list));
131  if (devices == NULL) {
132  status = PNFSERR_RESOURCES;
133  goto out;
134  }
135 
136  list_init(&devices->head);
137  InitializeCriticalSection(&devices->lock);
138 
139  *devices_out = devices;
140 out:
141  return status;
142 }
pnfs_status
Definition: pnfs.h:58
struct list_entry head
Definition: pnfs_device.c:36
const char * devices
Definition: diskspace.c:793
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
smooth NULL
Definition: ftsmooth.c:416
static FILE * out
Definition: regtests2xml.c:44
#define calloc
Definition: rosglue.h:14
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
CRITICAL_SECTION lock
Definition: pnfs_device.c:37
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ pnfs_file_device_list_free()

void pnfs_file_device_list_free ( IN struct pnfs_file_device_list devices)

Definition at line 144 of file pnfs_device.c.

Referenced by nfs41_client_free().

146 {
147  struct list_entry *entry, *tmp;
148 
150 
151  list_for_each_tmp(entry, tmp, &devices->head)
153 
156  free(devices);
157 }
rwlock_t lock
Definition: tcpcore.h:1163
static void file_device_free(IN pnfs_file_device *device)
Definition: pnfs_device.c:65
#define free
Definition: debug_ros.c:5
const char * devices
Definition: diskspace.c:793
uint8_t entry
Definition: isohybrid.c:63
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define device_entry(pos)
Definition: pnfs_device.c:40
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
Definition: list.h:27
#define list_for_each_tmp(entry, tmp, head)
Definition: list.h:39
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ pnfs_file_device_list_invalidate()

void pnfs_file_device_list_invalidate ( IN struct pnfs_file_device_list devices)

Definition at line 159 of file pnfs_device.c.

Referenced by file_layout_recall_all(), and file_layout_recall_fsid().

161 {
162  struct list_entry *entry, *tmp;
164 
165  dprintf(FDLVL, "--> pnfs_file_device_list_invalidate()\n");
166 
168 
169  list_for_each_tmp(entry, tmp, &devices->head) {
170  device = device_entry(entry);
171  EnterCriticalSection(&device->device.lock);
172  /* if there are layouts still using the device, flag it
173  * as revoked and clean up on last reference */
174  if (device->device.layout_count) {
175  device->device.status |= PNFS_DEVICE_REVOKED;
176  LeaveCriticalSection(&device->device.lock);
177  } else {
178  LeaveCriticalSection(&device->device.lock);
179  /* no layouts are using it, so it's safe to free */
180  list_remove(entry);
181  file_device_free(device);
182  }
183  }
184 
186 
187  dprintf(FDLVL, "<-- pnfs_file_device_list_invalidate()\n");
188 }
static void file_device_free(IN pnfs_file_device *device)
Definition: pnfs_device.c:65
uint32_t layout_count
Definition: pnfs.h:119
const char * devices
Definition: diskspace.c:793
uint8_t entry
Definition: isohybrid.c:63
CRITICAL_SECTION lock
Definition: pnfs.h:120
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define device_entry(pos)
Definition: pnfs_device.c:40
#define FDLVL
Definition: pnfs_device.c:31
Definition: devices.h:37
#define dprintf
Definition: regdump.c:33
pnfs_device device
Definition: pnfs.h:140
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
Definition: list.h:27
enum pnfs_device_status status
Definition: pnfs.h:118
#define list_for_each_tmp(entry, tmp, head)
Definition: list.h:39
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ pnfs_file_device_notify()

enum pnfs_status pnfs_file_device_notify ( IN struct pnfs_file_device_list devices,
IN const struct notify_deviceid4 change 
)

Definition at line 328 of file pnfs_device.c.

Referenced by handle_cb_notify_deviceid().

331 {
332  struct list_entry *entry;
334 
335  dprintf(FDLVL, "--> pnfs_file_device_notify(%u, %0llX:%0llX)\n",
336  change->type, change->deviceid);
337 
338  if (change->layouttype != PNFS_LAYOUTTYPE_FILE) {
339  status = PNFSERR_NOT_SUPPORTED;
340  goto out;
341  }
342 
344 
345  entry = list_search(&devices->head, change->deviceid, deviceid_compare);
346  if (entry) {
347  dprintf(FDLVL, "found file device %p\n", device_entry(entry));
348 
349  if (change->type == NOTIFY_DEVICEID4_CHANGE) {
350  /* if (change->immediate) ... */
351  dprintf(FDLVL, "CHANGE (%u)\n", change->immediate);
352  } else if (change->type == NOTIFY_DEVICEID4_DELETE) {
353  /* This notification MUST NOT be sent if the client
354  * has a layout that refers to the device ID. */
355  dprintf(FDLVL, "DELETE\n");
356  }
357  status = PNFS_SUCCESS;
358  }
359 
361 out:
362  dprintf(FDLVL, "<-- pnfs_file_device_notify() returning %s\n",
363  pnfs_error_string(status));
364  return status;
365 }
pnfs_status
Definition: pnfs.h:58
const char * devices
Definition: diskspace.c:793
uint8_t entry
Definition: isohybrid.c:63
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define device_entry(pos)
Definition: pnfs_device.c:40
#define FDLVL
Definition: pnfs_device.c:31
#define dprintf
Definition: regdump.c:33
const char * pnfs_error_string(enum pnfs_status status)
Definition: pnfs_debug.c:28
static FILE * out
Definition: regtests2xml.c:44
static struct list_entry * list_search(const struct list_entry *head, const void *value, list_compare_fn compare)
Definition: list.h:102
Definition: list.h:27
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static int deviceid_compare(const struct list_entry *entry, const void *deviceid)
Definition: pnfs_device.c:74
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ pnfs_file_device_put()

void pnfs_file_device_put ( IN pnfs_file_device device)

Definition at line 245 of file pnfs_device.c.

Referenced by file_layout_free().

247 {
248  uint32_t count;
249  EnterCriticalSection(&device->device.lock);
250  count = --device->device.layout_count;
251  dprintf(FDLVL, "pnfs_file_device_put() -> %u\n", count);
252 
253  /* if the device was revoked, remove/free the device on last reference */
254  if (count == 0 && device->device.status & PNFS_DEVICE_REVOKED) {
255  EnterCriticalSection(&device->devices->lock);
256  list_remove(&device->entry);
257  LeaveCriticalSection(&device->devices->lock);
258 
259  LeaveCriticalSection(&device->device.lock);
260 
262  dprintf(FDLVL, "revoked file device freed after last reference\n");
263  } else {
264  LeaveCriticalSection(&device->device.lock);
265  }
266 }
static void file_device_free(IN pnfs_file_device *device)
Definition: pnfs_device.c:65
GLuint GLuint GLsizei count
Definition: gl.h:1545
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define FDLVL
Definition: pnfs_device.c:31
Definition: devices.h:37
#define dprintf
Definition: regdump.c:33
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
UINT32 uint32_t
Definition: types.h:75
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)