| 1 |
/* |
| 2 |
* automount.h |
| 3 |
* |
| 4 |
* Header file for automounter modules |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef AUTOMOUNT_H |
| 9 |
#define AUTOMOUNT_H |
| 10 |
|
| 11 |
#include <stdio.h> |
| 12 |
#include <paths.h> |
| 13 |
#include <limits.h> |
| 14 |
#include <time.h> |
| 15 |
#include <syslog.h> |
| 16 |
#include <sys/types.h> |
| 17 |
#include <pthread.h> |
| 18 |
#include <sched.h> |
| 19 |
#include <errno.h> |
| 20 |
#include <unistd.h> |
| 21 |
#include <fcntl.h> |
| 22 |
#include <mntent.h> |
| 23 |
#include "config.h" |
| 24 |
#include "list.h" |
| 25 |
#include "hash.h" |
| 26 |
|
| 27 |
#include <linux/auto_fs4.h> |
| 28 |
|
| 29 |
#include "defaults.h" |
| 30 |
#include "state.h" |
| 31 |
#include "master.h" |
| 32 |
#include "macros.h" |
| 33 |
#include "log.h" |
| 34 |
#include "mounts.h" |
| 35 |
#include "rpc_subs.h" |
| 36 |
#include "parse_subs.h" |
| 37 |
#include "dev-ioctl-lib.h" |
| 38 |
#include "parse_amd.h" |
| 39 |
|
| 40 |
#ifdef WITH_DMALLOC |
| 41 |
#include <dmalloc.h> |
| 42 |
#endif |
| 43 |
|
| 44 |
#define ENABLE_CORES 1 |
| 45 |
|
| 46 |
#ifndef __GLIBC__ |
| 47 |
# define strerror_r(N,B,S) autofs_strerror_r(N,B,S) |
| 48 |
char *autofs_strerror_r(int errnum, char *buf, size_t buflen); /* GNU */ |
| 49 |
#endif |
| 50 |
|
| 51 |
/* We MUST have the paths to mount(8) and umount(8) */ |
| 52 |
#ifndef HAVE_MOUNT |
| 53 |
#error Failed to locate mount(8)! |
| 54 |
#endif |
| 55 |
|
| 56 |
#ifndef HAVE_UMOUNT |
| 57 |
#error Failed to locate umount(8)! |
| 58 |
#endif |
| 59 |
|
| 60 |
#ifndef HAVE_LINUX_PROCFS |
| 61 |
#error Failed to verify existence of procfs filesystem! |
| 62 |
#endif |
| 63 |
|
| 64 |
/* The -s (sloppy) option to mount is good, if we have it... */ |
| 65 |
|
| 66 |
#ifdef HAVE_SLOPPY_MOUNT |
| 67 |
#define SLOPPYOPT "-s", /* For use in spawnl() lists */ |
| 68 |
#define SLOPPY "-s " /* For use in strings */ |
| 69 |
#else |
| 70 |
#define SLOPPYOPT |
| 71 |
#define SLOPPY |
| 72 |
#endif |
| 73 |
|
| 74 |
#define DAEMON_FLAGS_FOREGROUND 0x0001 |
| 75 |
#define DAEMON_FLAGS_SYSTEMD_SERVICE 0x0002 |
| 76 |
#define DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS 0x0004 |
| 77 |
#define DAEMON_FLAGS_GHOST 0x0008 |
| 78 |
#define DAEMON_FLAGS_CHECK_DAEMON 0x0010 |
| 79 |
#define DAEMON_FLAGS_DUMP_MAPS 0x0020 |
| 80 |
|
| 81 |
#define AUTOFS_SUPER_MAGIC 0x00000187L |
| 82 |
#define SMB_SUPER_MAGIC 0x0000517BL |
| 83 |
#define CIFS_MAGIC_NUMBER 0xFF534D42L |
| 84 |
#define NCP_SUPER_MAGIC 0x0000564CL |
| 85 |
#define NFS_SUPER_MAGIC 0x00006969L |
| 86 |
|
| 87 |
#define ATTEMPT_ID_SIZE 24 |
| 88 |
|
| 89 |
/* This sould be enough for at least 20 host aliases */ |
| 90 |
#define HOST_ENT_BUF_SIZE 2048 |
| 91 |
|
| 92 |
#define CHECK_RATIO 4 /* exp_runfreq = exp_timeout/CHECK_RATIO */ |
| 93 |
#define AUTOFS_LOCK "/var/lock/autofs" /* To serialize access to mount */ |
| 94 |
#define MOUNTED_LOCK _PATH_MOUNTED "~" /* mounts' lock file */ |
| 95 |
#define MTAB_NOTUPDATED 0x1000 /* mtab succeded but not updated */ |
| 96 |
#define NOT_MOUNTED 0x0100 /* path notmounted */ |
| 97 |
#define MNT_FORCE_FAIL -1 |
| 98 |
#define _PROC_MOUNTS "/proc/mounts" |
| 99 |
#define _PROC_SELF_MOUNTS "/proc/self/mounts" |
| 100 |
|
| 101 |
/* Constants for lookup modules */ |
| 102 |
|
| 103 |
#define LKP_FAIL 0x0001 |
| 104 |
|
| 105 |
#define LKP_INDIRECT 0x0002 |
| 106 |
#define LKP_DIRECT 0x0004 |
| 107 |
#define LKP_MULTI 0x0008 |
| 108 |
#define LKP_NOMATCH 0x0010 |
| 109 |
#define LKP_MATCH 0x0020 |
| 110 |
#define LKP_NEXT 0x0040 |
| 111 |
#define LKP_MOUNT 0x0080 |
| 112 |
#define LKP_WILD 0x0100 |
| 113 |
#define LKP_LOOKUP 0x0200 |
| 114 |
#define LKP_GHOST 0x0400 |
| 115 |
#define LKP_REREAD 0x0800 |
| 116 |
#define LKP_NORMAL 0x1000 |
| 117 |
#define LKP_DISTINCT 0x2000 |
| 118 |
#define LKP_ERR_MOUNT 0x4000 |
| 119 |
#define LKP_NOTSUP 0x8000 |
| 120 |
|
| 121 |
#define MAX_ERR_BUF 128 |
| 122 |
|
| 123 |
#ifdef DEBUG |
| 124 |
#define DB(x) do { x; } while(0) |
| 125 |
#else |
| 126 |
#define DB(x) do { } while(0) |
| 127 |
#endif |
| 128 |
|
| 129 |
#define min(a, b) (a <= b ? a : b) |
| 130 |
|
| 131 |
/* Forward declaraion */ |
| 132 |
struct autofs_point; |
| 133 |
|
| 134 |
/* mapent cache definition */ |
| 135 |
|
| 136 |
#define CHE_FAIL 0x0000 |
| 137 |
#define CHE_OK 0x0001 |
| 138 |
#define CHE_UPDATED 0x0002 |
| 139 |
#define CHE_RMPATH 0x0004 |
| 140 |
#define CHE_MISSING 0x0008 |
| 141 |
#define CHE_COMPLETED 0x0010 |
| 142 |
#define CHE_DUPLICATE 0x0020 |
| 143 |
#define CHE_UNAVAIL 0x0040 |
| 144 |
|
| 145 |
#define NULL_MAP_HASHSIZE 64 |
| 146 |
#define NEGATIVE_TIMEOUT 10 |
| 147 |
#define POSITIVE_TIMEOUT 120 |
| 148 |
#define UMOUNT_RETRIES 16 |
| 149 |
#define EXPIRE_RETRIES 1 |
| 150 |
|
| 151 |
struct mapent_cache { |
| 152 |
pthread_rwlock_t rwlock; |
| 153 |
unsigned int size; |
| 154 |
pthread_mutex_t ino_index_mutex; |
| 155 |
struct list_head *ino_index; |
| 156 |
struct autofs_point *ap; |
| 157 |
struct map_source *map; |
| 158 |
struct mapent **hash; |
| 159 |
}; |
| 160 |
|
| 161 |
struct stack { |
| 162 |
char *mapent; |
| 163 |
time_t age; |
| 164 |
struct stack *next; |
| 165 |
}; |
| 166 |
|
| 167 |
struct mapent { |
| 168 |
struct mapent *next; |
| 169 |
struct list_head ino_index; |
| 170 |
struct mapent_cache *mc; |
| 171 |
struct map_source *source; |
| 172 |
/* Need to know owner if we're a multi-mount */ |
| 173 |
struct tree_node *mm_root; |
| 174 |
/* Parent nesting point within multi-mount */ |
| 175 |
struct tree_node *mm_parent; |
| 176 |
struct tree_node node; |
| 177 |
struct list_head work; |
| 178 |
char *key; |
| 179 |
size_t len; |
| 180 |
char *mapent; |
| 181 |
struct stack *stack; |
| 182 |
time_t age; |
| 183 |
/* Time of last mount fail */ |
| 184 |
time_t status; |
| 185 |
/* For direct mounts per entry context is kept here */ |
| 186 |
int flags; |
| 187 |
/* File descriptor for ioctls */ |
| 188 |
int ioctlfd; |
| 189 |
dev_t dev; |
| 190 |
ino_t ino; |
| 191 |
}; |
| 192 |
|
| 193 |
#define IS_MM(me) (me->mm_root) |
| 194 |
#define IS_MM_ROOT(me) (me->mm_root == &me->node) |
| 195 |
#define MM_ROOT(me) (MAPENT(me->mm_root)) |
| 196 |
#define MM_PARENT(me) (MAPENT(me->mm_parent)) |
| 197 |
|
| 198 |
void cache_lock_cleanup(void *arg); |
| 199 |
void cache_readlock(struct mapent_cache *mc); |
| 200 |
void cache_writelock(struct mapent_cache *mc); |
| 201 |
int cache_try_writelock(struct mapent_cache *mc); |
| 202 |
void cache_unlock(struct mapent_cache *mc); |
| 203 |
int cache_push_mapent(struct mapent *me, char *mapent); |
| 204 |
int cache_pop_mapent(struct mapent *me); |
| 205 |
struct mapent_cache *cache_init(struct autofs_point *ap, struct map_source *map); |
| 206 |
struct mapent_cache *cache_init_null_cache(struct master *master); |
| 207 |
int cache_set_ino_index(struct mapent_cache *mc, struct mapent *me); |
| 208 |
struct mapent *cache_lookup_ino(struct mapent_cache *mc, dev_t dev, ino_t ino); |
| 209 |
struct mapent *cache_lookup_first(struct mapent_cache *mc); |
| 210 |
struct mapent *cache_lookup_next(struct mapent_cache *mc, struct mapent *me); |
| 211 |
struct mapent *cache_lookup_key_next(struct mapent *me); |
| 212 |
struct mapent *cache_lookup(struct mapent_cache *mc, const char *key); |
| 213 |
struct mapent *cache_lookup_distinct(struct mapent_cache *mc, const char *key); |
| 214 |
struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix); |
| 215 |
struct mapent *cache_partial_match_wild(struct mapent_cache *mc, const char *prefix); |
| 216 |
int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age); |
| 217 |
int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age); |
| 218 |
int cache_lookup_negative(struct mapent *me, const char *key); |
| 219 |
void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout); |
| 220 |
struct mapent *cache_get_offset_parent(struct mapent_cache *mc, const char *key); |
| 221 |
int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age); |
| 222 |
int cache_delete(struct mapent_cache *mc, const char *key); |
| 223 |
void cache_release(struct map_source *map); |
| 224 |
void cache_clean_null_cache(struct mapent_cache *mc); |
| 225 |
void cache_release_null_cache(struct master *master); |
| 226 |
struct mapent *cache_enumerate(struct mapent_cache *mc, struct mapent *me); |
| 227 |
|
| 228 |
/* Utility functions */ |
| 229 |
|
| 230 |
char **add_argv(int argc, char **argv, char *str); |
| 231 |
char **append_argv(int argc1, char **argv1, int argc2, char **argv2); |
| 232 |
const char **copy_argv(int argc, const char **argv); |
| 233 |
int compare_argv(int argc1, const char **argv1, int argc2, const char **argv2); |
| 234 |
int free_argv(int argc, const char **argv); |
| 235 |
|
| 236 |
struct pending_args; |
| 237 |
void set_thread_mount_request_log_id(struct pending_args *mt); |
| 238 |
|
| 239 |
void dump_core(void); |
| 240 |
int aquire_lock(void); |
| 241 |
void release_lock(void); |
| 242 |
int spawnl(unsigned logopt, const char *prog, ...); |
| 243 |
int spawnv(unsigned logopt, const char *prog, const char *const *argv); |
| 244 |
int spawn_mount(unsigned logopt, ...); |
| 245 |
int spawn_bind_mount(unsigned logopt, ...); |
| 246 |
int spawn_umount(unsigned logopt, ...); |
| 247 |
void open_mutex_lock(void); |
| 248 |
void open_mutex_unlock(void); |
| 249 |
int open_fd(const char *, int); |
| 250 |
int open_fd_mode(const char *, int, int); |
| 251 |
int open_pipe(int[2]); |
| 252 |
int open_sock(int, int, int); |
| 253 |
FILE *open_fopen_r(const char *); |
| 254 |
FILE *open_setmntent_r(const char *); |
| 255 |
void reset_signals(void); |
| 256 |
int do_mount(struct autofs_point *ap, const char *root, const char *name, |
| 257 |
int name_len, const char *what, const char *fstype, |
| 258 |
const char *options); |
| 259 |
extern unsigned int mp_mode; |
| 260 |
int mkdir_path(const char *path, mode_t mode); |
| 261 |
int rmdir_path(struct autofs_point *ap, const char *path, dev_t dev); |
| 262 |
|
| 263 |
/* Prototype for module functions */ |
| 264 |
|
| 265 |
/* lookup module */ |
| 266 |
|
| 267 |
#define AUTOFS_LOOKUP_VERSION 5 |
| 268 |
|
| 269 |
#define KEY_MAX_LEN NAME_MAX |
| 270 |
#define MAPENT_MAX_LEN 16384 |
| 271 |
#define PARSE_MAX_BUF KEY_MAX_LEN + MAPENT_MAX_LEN + 2 |
| 272 |
|
| 273 |
int lookup_nss_read_master(struct master *master, time_t age); |
| 274 |
int lookup_nss_read_map(struct autofs_point *ap, struct map_source *source, time_t age); |
| 275 |
int lookup_enumerate(struct autofs_point *ap, |
| 276 |
int (*fn)(struct autofs_point *,struct mapent *, int), time_t now); |
| 277 |
int lookup_ghost(struct autofs_point *ap); |
| 278 |
int lookup_nss_mount(struct autofs_point *ap, struct map_source *source, const char *name, int name_len); |
| 279 |
void lookup_close_lookup(struct autofs_point *ap); |
| 280 |
void lookup_prune_one_cache(struct autofs_point *ap, struct mapent_cache *mc, time_t age); |
| 281 |
int lookup_prune_cache(struct autofs_point *ap, time_t age); |
| 282 |
struct mapent *lookup_source_valid_mapent(struct autofs_point *ap, const char *key, unsigned int type); |
| 283 |
struct mapent *lookup_source_mapent(struct autofs_point *ap, const char *key, unsigned int type); |
| 284 |
int lookup_source_close_ioctlfd(struct autofs_point *ap, const char *key); |
| 285 |
|
| 286 |
#ifdef MODULE_LOOKUP |
| 287 |
int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context); |
| 288 |
int lookup_reinit(const char *mapfmt, int argc, const char *const *argv, void **context); |
| 289 |
int lookup_read_master(struct master *master, time_t age, void *context); |
| 290 |
int lookup_read_map(struct autofs_point *ap, struct map_source *map, time_t age, void *context); |
| 291 |
int lookup_mount(struct autofs_point *, struct map_source *map, const char *name, int name_len, void *context); |
| 292 |
int lookup_done(void *); |
| 293 |
#endif |
| 294 |
typedef int (*lookup_init_t) (const char *, int, const char *const *, void **); |
| 295 |
typedef int (*lookup_reinit_t) (const char *, int, const char *const *, void **); |
| 296 |
typedef int (*lookup_read_master_t) (struct master *master, time_t, void *); |
| 297 |
typedef int (*lookup_read_map_t) (struct autofs_point *, struct map_source *, time_t, void *); |
| 298 |
typedef int (*lookup_mount_t) (struct autofs_point *, struct map_source *, const char *, int, void *); |
| 299 |
typedef int (*lookup_done_t) (void *); |
| 300 |
|
| 301 |
struct lookup_mod { |
| 302 |
lookup_init_t lookup_init; |
| 303 |
lookup_reinit_t lookup_reinit; |
| 304 |
lookup_read_master_t lookup_read_master; |
| 305 |
lookup_read_map_t lookup_read_map; |
| 306 |
lookup_mount_t lookup_mount; |
| 307 |
lookup_done_t lookup_done; |
| 308 |
char *type; |
| 309 |
void *dlhandle; |
| 310 |
void *context; |
| 311 |
}; |
| 312 |
|
| 313 |
int open_lookup(const char *name, const char *err_prefix, const char *mapfmt, |
| 314 |
int argc, const char *const *argv, struct lookup_mod **lookup); |
| 315 |
int reinit_lookup(struct lookup_mod *mod, const char *name, |
| 316 |
const char *err_prefix, const char *mapfmt, |
| 317 |
int argc, const char *const *argv); |
| 318 |
int close_lookup(struct lookup_mod *); |
| 319 |
|
| 320 |
/* parse module */ |
| 321 |
|
| 322 |
#define AUTOFS_PARSE_VERSION 5 |
| 323 |
|
| 324 |
#ifdef MODULE_PARSE |
| 325 |
int parse_init(int argc, const char *const *argv, void **context); |
| 326 |
int parse_reinit(int argc, const char *const *argv, void **context); |
| 327 |
int parse_mount(struct autofs_point *ap, struct map_source *map, |
| 328 |
const char *name, int name_len, const char *mapent, |
| 329 |
void *context); |
| 330 |
int parse_done(void *); |
| 331 |
#endif |
| 332 |
typedef int (*parse_init_t) (int, const char *const *, void **); |
| 333 |
typedef int (*parse_reinit_t) (int, const char *const *, void **); |
| 334 |
typedef int (*parse_mount_t) (struct autofs_point *, struct map_source *, |
| 335 |
const char *, int, const char *, void *); |
| 336 |
typedef int (*parse_done_t) (void *); |
| 337 |
|
| 338 |
struct parse_mod { |
| 339 |
parse_init_t parse_init; |
| 340 |
parse_reinit_t parse_reinit; |
| 341 |
parse_mount_t parse_mount; |
| 342 |
parse_done_t parse_done; |
| 343 |
void *dlhandle; |
| 344 |
void *context; |
| 345 |
}; |
| 346 |
|
| 347 |
struct parse_mod *open_parse(const char *name, const char *err_prefix, |
| 348 |
int argc, const char *const *argv); |
| 349 |
int reinit_parse(struct parse_mod *, const char *name, |
| 350 |
const char *err_prefix, int argc, const char *const *argv); |
| 351 |
int close_parse(struct parse_mod *); |
| 352 |
|
| 353 |
/* mount module */ |
| 354 |
|
| 355 |
#define AUTOFS_MOUNT_VERSION 4 |
| 356 |
|
| 357 |
#ifdef MODULE_MOUNT |
| 358 |
int mount_init(void **context); |
| 359 |
int mount_reinit(void **context); |
| 360 |
int mount_mount(struct autofs_point *ap, const char *root, const char *name, int name_len, |
| 361 |
const char *what, const char *fstype, const char *options, void *context); |
| 362 |
int mount_done(void *context); |
| 363 |
#endif |
| 364 |
typedef int (*mount_init_t) (void **); |
| 365 |
typedef int (*mount_reinit_t) (void **); |
| 366 |
typedef int (*mount_mount_t) (struct autofs_point *, const char *, const char *, int, |
| 367 |
const char *, const char *, const char *, void *); |
| 368 |
typedef int (*mount_done_t) (void *); |
| 369 |
|
| 370 |
struct mount_mod { |
| 371 |
mount_init_t mount_init; |
| 372 |
mount_reinit_t mount_reinit; |
| 373 |
mount_mount_t mount_mount; |
| 374 |
mount_done_t mount_done; |
| 375 |
void *dlhandle; |
| 376 |
void *context; |
| 377 |
}; |
| 378 |
|
| 379 |
struct mount_mod *open_mount(const char *name, const char *err_prefix); |
| 380 |
int reinit_mount(struct mount_mod *mod, const char *name, const char *err_prefix); |
| 381 |
int close_mount(struct mount_mod *); |
| 382 |
|
| 383 |
/* buffer management */ |
| 384 |
|
| 385 |
size_t _strlen(const char *str, size_t max); |
| 386 |
int cat_path(char *buf, size_t len, const char *dir, const char *base); |
| 387 |
int ncat_path(char *buf, size_t len, |
| 388 |
const char *dir, const char *base, size_t blen); |
| 389 |
int _strncmp(const char *s1, const char *s2, size_t n); |
| 390 |
|
| 391 |
/* Core automount definitions */ |
| 392 |
|
| 393 |
#ifndef MNT_DETACH |
| 394 |
#define MNT_DETACH 0x00000002 /* Just detach from the tree */ |
| 395 |
#endif |
| 396 |
|
| 397 |
struct startup_cond { |
| 398 |
pthread_mutex_t mutex; |
| 399 |
pthread_cond_t cond; |
| 400 |
struct autofs_point *ap; |
| 401 |
unsigned int done; |
| 402 |
unsigned int status; |
| 403 |
}; |
| 404 |
|
| 405 |
int handle_mounts_startup_cond_init(struct startup_cond *suc); |
| 406 |
void handle_mounts_startup_cond_destroy(void *arg); |
| 407 |
|
| 408 |
struct master_readmap_cond { |
| 409 |
pthread_mutex_t mutex; |
| 410 |
pthread_cond_t cond; |
| 411 |
pthread_t thid; /* map reader thread id */ |
| 412 |
struct master *master; |
| 413 |
time_t age; /* Last time read */ |
| 414 |
enum states state; /* Next state */ |
| 415 |
unsigned int signaled; /* Condition has been signaled */ |
| 416 |
unsigned int busy; /* Map read in progress. */ |
| 417 |
}; |
| 418 |
|
| 419 |
struct pending_args { |
| 420 |
pthread_mutex_t mutex; |
| 421 |
pthread_cond_t cond; |
| 422 |
unsigned int signaled; /* Condition has been signaled */ |
| 423 |
struct autofs_point *ap; /* autofs mount we are working on */ |
| 424 |
int status; /* Return status */ |
| 425 |
int type; /* Type of packet */ |
| 426 |
int ioctlfd; /* Mount ioctl fd */ |
| 427 |
struct mapent_cache *mc; /* Cache Containing entry */ |
| 428 |
char name[PATH_MAX]; /* Name field of the request */ |
| 429 |
dev_t dev; /* device number of mount */ |
| 430 |
unsigned int len; /* Name field len */ |
| 431 |
uid_t uid; /* uid of requester */ |
| 432 |
gid_t gid; /* gid of requester */ |
| 433 |
pid_t pid; /* pid of requestor */ |
| 434 |
unsigned long wait_queue_token; /* Associated kernel wait token */ |
| 435 |
}; |
| 436 |
|
| 437 |
#ifdef INCLUDE_PENDING_FUNCTIONS |
| 438 |
static void pending_cond_init(void *arg) |
| 439 |
{ |
| 440 |
struct pending_args *mt = (struct pending_args *) arg; |
| 441 |
pthread_condattr_t condattrs; |
| 442 |
int status; |
| 443 |
|
| 444 |
status = pthread_condattr_init(&condattrs); |
| 445 |
if (status) |
| 446 |
fatal(status); |
| 447 |
|
| 448 |
status = pthread_condattr_setclock(&condattrs, CLOCK_MONOTONIC); |
| 449 |
if (status) |
| 450 |
fatal(status); |
| 451 |
|
| 452 |
status = pthread_cond_init(&mt->cond, &condattrs); |
| 453 |
if (status) |
| 454 |
fatal(status); |
| 455 |
|
| 456 |
pthread_condattr_destroy(&condattrs); |
| 457 |
} |
| 458 |
|
| 459 |
static void pending_cond_destroy(void *arg) |
| 460 |
{ |
| 461 |
struct pending_args *mt = (struct pending_args *) arg; |
| 462 |
int status; |
| 463 |
status = pthread_cond_destroy(&mt->cond); |
| 464 |
if (status) |
| 465 |
fatal(status); |
| 466 |
} |
| 467 |
|
| 468 |
static void pending_mutex_destroy(void *arg) |
| 469 |
{ |
| 470 |
struct pending_args *mt = (struct pending_args *) arg; |
| 471 |
int status = pthread_mutex_destroy(&mt->mutex); |
| 472 |
if (status) |
| 473 |
fatal(status); |
| 474 |
} |
| 475 |
|
| 476 |
static void free_pending_args(void *arg) |
| 477 |
{ |
| 478 |
struct pending_args *mt = (struct pending_args *) arg; |
| 479 |
free(mt); |
| 480 |
} |
| 481 |
|
| 482 |
static void pending_mutex_lock(void *arg) |
| 483 |
{ |
| 484 |
struct pending_args *mt = (struct pending_args *) arg; |
| 485 |
int status = pthread_mutex_lock(&mt->mutex); |
| 486 |
if (status) |
| 487 |
fatal(status); |
| 488 |
} |
| 489 |
|
| 490 |
static void pending_mutex_unlock(void *arg) |
| 491 |
{ |
| 492 |
struct pending_args *mt = (struct pending_args *) arg; |
| 493 |
int status = pthread_mutex_unlock(&mt->mutex); |
| 494 |
if (status) |
| 495 |
fatal(status); |
| 496 |
} |
| 497 |
#endif |
| 498 |
|
| 499 |
struct thread_stdenv_vars { |
| 500 |
uid_t uid; |
| 501 |
gid_t gid; |
| 502 |
char *user; |
| 503 |
char *group; |
| 504 |
char *home; |
| 505 |
}; |
| 506 |
|
| 507 |
extern pthread_key_t key_thread_stdenv_vars; |
| 508 |
|
| 509 |
extern pthread_key_t key_thread_attempt_id; |
| 510 |
|
| 511 |
struct kernel_mod_version { |
| 512 |
unsigned int major; |
| 513 |
unsigned int minor; |
| 514 |
}; |
| 515 |
|
| 516 |
/* Enable/disable ghosted directories */ |
| 517 |
#define MOUNT_FLAG_GHOST 0x0001 |
| 518 |
|
| 519 |
/* Directory created for this mount? */ |
| 520 |
#define MOUNT_FLAG_DIR_CREATED 0x0002 |
| 521 |
|
| 522 |
/* Use random policy when selecting a host from which to mount */ |
| 523 |
#define MOUNT_FLAG_RANDOM_SELECT 0x0004 |
| 524 |
|
| 525 |
/* Mount being re-mounted */ |
| 526 |
#define MOUNT_FLAG_REMOUNT 0x0008 |
| 527 |
|
| 528 |
/* Use server weight only for selection */ |
| 529 |
#define MOUNT_FLAG_USE_WEIGHT_ONLY 0x0010 |
| 530 |
|
| 531 |
/* Don't use bind mounts even when system supports them */ |
| 532 |
#define MOUNT_FLAG_NOBIND 0x0020 |
| 533 |
|
| 534 |
/* Use symlinks instead of bind mounting local mounts */ |
| 535 |
#define MOUNT_FLAG_SYMLINK 0x0040 |
| 536 |
|
| 537 |
/* Read amd map even if it's not to be ghosted (browsable) */ |
| 538 |
#define MOUNT_FLAG_AMD_CACHE_ALL 0x0080 |
| 539 |
|
| 540 |
/* Set mount propagation for bind mounts */ |
| 541 |
#define MOUNT_FLAG_SHARED 0x0100 |
| 542 |
#define MOUNT_FLAG_SLAVE 0x0200 |
| 543 |
#define MOUNT_FLAG_PRIVATE 0x0400 |
| 544 |
|
| 545 |
/* Use strict expire semantics if requested and kernel supports it */ |
| 546 |
#define MOUNT_FLAG_STRICTEXPIRE 0x0800 |
| 547 |
|
| 548 |
/* Indicator for applications to ignore the mount entry */ |
| 549 |
#define MOUNT_FLAG_IGNORE 0x1000 |
| 550 |
|
| 551 |
struct autofs_point { |
| 552 |
pthread_t thid; |
| 553 |
char *path; /* Mount point name */ |
| 554 |
size_t len; /* Length of mount point name */ |
| 555 |
mode_t mode; /* Mount point mode */ |
| 556 |
char *pref; /* amd prefix */ |
| 557 |
int pipefd; /* File descriptor for pipe */ |
| 558 |
int kpipefd; /* Kernel end descriptor for pipe */ |
| 559 |
int ioctlfd; /* File descriptor for ioctls */ |
| 560 |
dev_t dev; /* "Device" number assigned by kernel */ |
| 561 |
struct master_mapent *entry; /* Master map entry for this mount */ |
| 562 |
unsigned int type; /* Type of map direct or indirect */ |
| 563 |
time_t exp_timeout; /* Indirect mount expire timeout */ |
| 564 |
time_t exp_runfreq; /* Frequency for polling for timeouts */ |
| 565 |
time_t negative_timeout; /* timeout in secs for failed mounts */ |
| 566 |
time_t positive_timeout; /* timeout in secs for using cache for map entries */ |
| 567 |
unsigned int flags; /* autofs mount flags */ |
| 568 |
unsigned int logopt; /* Per map logging */ |
| 569 |
pthread_t exp_thread; /* Thread that is expiring */ |
| 570 |
pthread_t readmap_thread; /* Thread that is reading maps */ |
| 571 |
enum states state; /* Current state */ |
| 572 |
struct autofs_point *parent; /* Owner of mounts list for submount */ |
| 573 |
struct list_head mounts; /* List of autofs mounts at current level */ |
| 574 |
unsigned int submount; /* Is this a submount */ |
| 575 |
struct list_head submounts; /* List of child submounts */ |
| 576 |
struct list_head amdmounts; /* List of non submount amd mounts */ |
| 577 |
unsigned int shutdown; /* Shutdown notification */ |
| 578 |
}; |
| 579 |
|
| 580 |
#define UNLINK_AND_CONT 0x01 |
| 581 |
#define UNLINK_AND_EXIT 0x02 |
| 582 |
|
| 583 |
/* Foreably unlink existing mounts at startup. */ |
| 584 |
extern int do_force_unlink; |
| 585 |
|
| 586 |
/* Standard functions used by daemon or modules */ |
| 587 |
|
| 588 |
#define MOUNT_OFFSET_OK 0 |
| 589 |
#define MOUNT_OFFSET_FAIL -1 |
| 590 |
#define MOUNT_OFFSET_IGNORE -2 |
| 591 |
|
| 592 |
void *handle_mounts(void *arg); |
| 593 |
int umount_multi(struct autofs_point *ap, const char *path, int incl); |
| 594 |
int do_expire(struct autofs_point *ap, const char *name, int namelen); |
| 595 |
void *expire_proc_indirect(void *); |
| 596 |
void *expire_proc_direct(void *); |
| 597 |
int expire_offsets_direct(struct autofs_point *ap, struct mapent *me, int now); |
| 598 |
int mount_autofs_indirect(struct autofs_point *ap); |
| 599 |
int do_mount_autofs_direct(struct autofs_point *ap, struct mapent *me, time_t timeout); |
| 600 |
int mount_autofs_direct(struct autofs_point *ap); |
| 601 |
int mount_autofs_offset(struct autofs_point *ap, struct mapent *me); |
| 602 |
void submount_signal_parent(struct autofs_point *ap, unsigned int success); |
| 603 |
void close_mount_fds(struct autofs_point *ap); |
| 604 |
int umount_autofs_indirect(struct autofs_point *ap); |
| 605 |
int do_umount_autofs_direct(struct autofs_point *ap, struct mapent *me); |
| 606 |
int umount_autofs_direct(struct autofs_point *ap); |
| 607 |
int umount_autofs_offset(struct autofs_point *ap, struct mapent *me); |
| 608 |
int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_indirect_t *pkt); |
| 609 |
int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_direct_t *pkt); |
| 610 |
int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missing_indirect_t *pkt); |
| 611 |
int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_direct_t *pkt); |
| 612 |
void rm_unwanted(struct autofs_point *ap, const char *path, int incl); |
| 613 |
int count_mounts(struct autofs_point *ap, const char *path, dev_t dev); |
| 614 |
|
| 615 |
#define mounts_mutex_lock(ap) \ |
| 616 |
do { \ |
| 617 |
int _m_lock = pthread_mutex_lock(&ap->mounts_mutex); \ |
| 618 |
if (_m_lock) \ |
| 619 |
fatal(_m_lock); \ |
| 620 |
} while (0) |
| 621 |
|
| 622 |
#define mounts_mutex_unlock(ap) \ |
| 623 |
do { \ |
| 624 |
int _m_unlock = pthread_mutex_unlock(&ap->mounts_mutex); \ |
| 625 |
if (_m_unlock) \ |
| 626 |
fatal(_m_unlock); \ |
| 627 |
} while(0) |
| 628 |
|
| 629 |
static inline time_t monotonic_time(time_t *t) |
| 630 |
{ |
| 631 |
struct timespec ts; |
| 632 |
|
| 633 |
clock_gettime(CLOCK_MONOTONIC, &ts); |
| 634 |
if (t) |
| 635 |
*t = (time_t) ts.tv_sec; |
| 636 |
return (time_t) ts.tv_sec; |
| 637 |
} |
| 638 |
|
| 639 |
/* Expire alarm handling routines */ |
| 640 |
int alarm_start_handler(void); |
| 641 |
int alarm_add(struct autofs_point *ap, time_t seconds); |
| 642 |
int conditional_alarm_add(struct autofs_point *ap, time_t seconds); |
| 643 |
void alarm_delete(struct autofs_point *ap); |
| 644 |
|
| 645 |
#endif |
| 646 |
|