Skip to content

Commit 367c8c7

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
lockd: Pass "struct sockaddr *" to new failover-by-IP function
Pass a more generic socket address type to nlmsvc_unlock_all_by_ip() to allow for future support of IPv6. Also provide additional sanity checking in failover_unlock_ip() when constructing the server's IP address. As an added bonus, provide clean kerneldoc comments on related NLM interfaces which were recently added. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
1 parent 560de0e commit 367c8c7

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

fs/lockd/svcsubs.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,16 @@ nlmsvc_free_host_resources(struct nlm_host *host)
373373
}
374374
}
375375

376-
/*
377-
* Remove all locks held for clients
376+
/**
377+
* nlmsvc_invalidate_all - remove all locks held for clients
378+
*
379+
* Release all locks held by NFS clients.
380+
*
378381
*/
379382
void
380383
nlmsvc_invalidate_all(void)
381384
{
382-
/* Release all locks held by NFS clients.
385+
/*
383386
* Previously, the code would call
384387
* nlmsvc_free_host_resources for each client in
385388
* turn, which is about as inefficient as it gets.
@@ -396,6 +399,12 @@ nlmsvc_match_sb(void *datap, struct nlm_file *file)
396399
return sb == file->f_file->f_path.mnt->mnt_sb;
397400
}
398401

402+
/**
403+
* nlmsvc_unlock_all_by_sb - release locks held on this file system
404+
* @sb: super block
405+
*
406+
* Release all locks held by clients accessing this file system.
407+
*/
399408
int
400409
nlmsvc_unlock_all_by_sb(struct super_block *sb)
401410
{
@@ -409,17 +418,22 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb);
409418
static int
410419
nlmsvc_match_ip(void *datap, struct nlm_host *host)
411420
{
412-
__be32 *server_addr = datap;
413-
414-
return host->h_saddr.sin_addr.s_addr == *server_addr;
421+
return nlm_cmp_addr(&host->h_saddr, datap);
415422
}
416423

424+
/**
425+
* nlmsvc_unlock_all_by_ip - release local locks by IP address
426+
* @server_addr: server's IP address as seen by clients
427+
*
428+
* Release all locks held by clients accessing this host
429+
* via the passed in IP address.
430+
*/
417431
int
418-
nlmsvc_unlock_all_by_ip(__be32 server_addr)
432+
nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr)
419433
{
420434
int ret;
421-
ret = nlm_traverse_files(&server_addr, nlmsvc_match_ip, NULL);
422-
return ret ? -EIO : 0;
423435

436+
ret = nlm_traverse_files(server_addr, nlmsvc_match_ip, NULL);
437+
return ret ? -EIO : 0;
424438
}
425439
EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_ip);

fs/nfsd/nfsctl.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,12 @@ static ssize_t write_getfd(struct file *file, char *buf, size_t size)
310310

311311
static ssize_t failover_unlock_ip(struct file *file, char *buf, size_t size)
312312
{
313-
__be32 server_ip;
314-
char *fo_path, c;
313+
struct sockaddr_in sin = {
314+
.sin_family = AF_INET,
315+
};
315316
int b1, b2, b3, b4;
317+
char c;
318+
char *fo_path;
316319

317320
/* sanity check */
318321
if (size == 0)
@@ -326,11 +329,13 @@ static ssize_t failover_unlock_ip(struct file *file, char *buf, size_t size)
326329
return -EINVAL;
327330

328331
/* get ipv4 address */
329-
if (sscanf(fo_path, "%u.%u.%u.%u%c", &b1, &b2, &b3, &b4, &c) != 4)
332+
if (sscanf(fo_path, NIPQUAD_FMT "%c", &b1, &b2, &b3, &b4, &c) != 4)
333+
return -EINVAL;
334+
if (b1 > 255 || b2 > 255 || b3 > 255 || b4 > 255)
330335
return -EINVAL;
331-
server_ip = htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4);
336+
sin.sin_addr.s_addr = htonl((b1 << 24) | (b2 << 16) | (b3 << 8) | b4);
332337

333-
return nlmsvc_unlock_all_by_ip(server_ip);
338+
return nlmsvc_unlock_all_by_ip((struct sockaddr *)&sin);
334339
}
335340

336341
static ssize_t failover_unlock_fs(struct file *file, char *buf, size_t size)

include/linux/lockd/lockd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void nlmsvc_invalidate_all(void);
226226
* Cluster failover support
227227
*/
228228
int nlmsvc_unlock_all_by_sb(struct super_block *sb);
229-
int nlmsvc_unlock_all_by_ip(__be32 server_addr);
229+
int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);
230230

231231
static inline struct inode *nlmsvc_file_inode(struct nlm_file *file)
232232
{

0 commit comments

Comments
 (0)