Debian Codegraph @

include/state.h

raw
1 /* ----------------------------------------------------------------------- *
2 *
3 * state.h - state queue functions.
4 *
5 * Copyright 2006 Ian Kent <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
10 * USA; either version 2 of the License, or (at your option) any later
11 * version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * ----------------------------------------------------------------------- */
19
20 #ifndef STATE_H
21 #define STATE_H
22
23 #include <string.h>
24 #include <stdlib.h>
25 #include <signal.h>
26 #include "automount.h"
27
28 /*
29 * State machine for daemon
30 *
31 * READY - reads from pipe; performs mount/umount operations
32 * PRUNE - generates prune events in subprocess; reads from pipe
33 * READMAP - read read map for maps taht use cache
34 * EXPIRE - generates expire events in subprocess; reads from pipe
35 * SHUTDOWN_PENDING - as prune, but goes to SHUTDOWN when done
36 * SHUTDOWN - unmount autofs, exit
37 *
38 */
39 enum states {
40 ST_ANY = -2,
41 ST_INVAL,
42 ST_INIT,
43 ST_READY,
44 ST_EXPIRE,
45 ST_PRUNE,
46 ST_READMAP,
47 ST_SHUTDOWN_PENDING,
48 ST_SHUTDOWN_FORCE,
49 ST_SHUTDOWN
50 };
51
52 struct expire_args {
53 pthread_mutex_t mutex;
54 pthread_cond_t cond;
55 unsigned int signaled;
56 struct autofs_point *ap; /* autofs mount we are working on */
57 enum states state; /* State prune or expire */
58 unsigned int how; /* Normal, immediate, forced expire ? */
59 int status; /* Return status */
60 };
61
62 #define expire_args_mutex_lock(ea) \
63 do { \
64 int _ea_lock = pthread_mutex_lock(&ea->mutex); \
65 if (_ea_lock) \
66 fatal(_ea_lock); \
67 } while (0)
68
69 #define expire_args_mutex_unlock(ea) \
70 do { \
71 int _ea_unlock = pthread_mutex_unlock(&ea->mutex); \
72 if (_ea_unlock) \
73 fatal(_ea_unlock); \
74 } while (0)
75
76 struct readmap_args {
77 pthread_mutex_t mutex;
78 pthread_cond_t cond;
79 unsigned int signaled;
80 struct autofs_point *ap; /* autofs mount we are working on */
81 time_t now; /* Time when map is read */
82 };
83
84 void st_mutex_lock(void);
85 void st_mutex_unlock(void);
86
87 void expire_cleanup(void *);
88 void expire_proc_cleanup(void *);
89
90 int st_add_task(struct autofs_point *, enum states);
91 int __st_add_task(struct autofs_point *, enum states);
92 void st_remove_tasks(struct autofs_point *);
93 int st_wait_task(struct autofs_point *, enum states, unsigned int);
94 int st_wait_state(struct autofs_point *ap, enum states state);
95 int st_start_handler(void);
96
97 #endif