]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/statd/callback.c
505fdb3c742112d09ea25230ee5588c4ff6e9915
[nfs-utils.git] / utils / statd / callback.c
1 /*
2  * Copyright (C) 1995, 1997-1999 Jeffrey A. Uphoff
3  * Modified by Olaf Kirch, Oct. 1996.
4  * Modified by Lon Hohberger, Oct. 2000.
5  *
6  * NSM for Linux.
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 #include "misc.h"
13 #include "statd.h"
14 #include "notlist.h"
15 #include <arpa/inet.h>
16
17 /* Callback notify list. */
18 /* notify_list *cbnl = NULL; ... never used */
19
20
21 /* 
22  * Services SM_NOTIFY requests.
23  * Any clients that have asked us to monitor that host are put on
24  * the global callback list, which is processed as soon as statd
25  * returns to svc_run.
26  */
27 void *
28 sm_notify_1_svc(struct stat_chge *argp, struct svc_req *rqstp)
29 {
30         notify_list    *lp, *call;
31         static char    *result = NULL;
32         char *ip_addr = xstrdup(inet_ntoa(svc_getcaller(rqstp->rq_xprt)
33                                           ->sin_addr));
34
35         dprintf(N_DEBUG, "Received SM_NOTIFY from %s, state: %d",
36                                 argp->mon_name, argp->state);
37
38         /* quick check - don't bother if we're not monitoring anyone */
39         if (rtnl == NULL) {
40                 note(N_WARNING, "SM_NOTIFY from %s while not monitoring any hosts.",
41                                 argp->mon_name);
42                 return ((void *) &result);
43         }
44
45         /* okir change: statd doesn't remove the remote host from its
46          * internal monitor list when receiving an SM_NOTIFY call from
47          * it. Lockd will want to continue monitoring the remote host
48          * until it issues an SM_UNMON call.
49          */
50         for (lp = rtnl ; lp ; lp = lp->next)
51                 if (NL_STATE(lp) != argp->state &&
52                     (matchhostname(argp->mon_name, lp->dns_name) ||
53                      matchhostname(ip_addr, lp->dns_name))) {
54                         NL_STATE(lp) = argp->state;
55                         call = nlist_clone(lp);
56                         nlist_insert(&notify, call);
57                 }
58
59
60         return ((void *) &result);
61 }