334
ioctl(ioctlfd, AUTOFS_IOC_SETTIMEOUT, &tout);
307
ops->timeout(ap->logopt, ioctlfd, &tout);
336
309
if (save_ioctlfd == -1)
341
if (!unlink_mount_tree(ap, &list)) {
343
"already mounted as other than autofs "
344
"or failed to unlink entry in tree");
349
if (me->ioctlfd != -1) {
350
error(ap->logopt, "active direct mount %s", me->key);
310
ops->close(ap->logopt, ioctlfd);
316
if (!unlink_mount_tree(ap, &list)) {
318
"already mounted as other than autofs "
319
"or failed to unlink entry in tree");
326
int do_mount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me)
328
const char *str_direct = mount_type_str(t_direct);
329
struct ioctl_ops *ops = get_ioctl_ops();
330
struct mnt_params *mp;
331
time_t timeout = ap->exp_timeout;
333
int status, ret, ioctlfd;
334
const char *map_name;
336
/* Calculate the timeouts */
337
ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
340
ap->flags |= MOUNT_FLAG_REMOUNT;
341
ret = try_remount(ap, me, t_direct);
342
ap->flags &= ~MOUNT_FLAG_REMOUNT;
349
* A return of 0 indicates we're re-reading the map.
350
* A return of 1 indicates we successfully unlinked
351
* the mount tree if there was one. A return of -1
352
* inducates we failed to unlink the mount tree so
353
* we have to return a failure.
355
ret = unlink_active_mounts(ap, mnts, me);
356
if (ret == -1 || ret == 0)
359
if (me->ioctlfd != -1) {
360
error(ap->logopt, "active direct mount %s", me->key);
354
365
status = pthread_once(&key_mnt_params_once, key_mnt_params_init);
405
/* Root directory for ioctl()'s */
406
ioctlfd = open(me->key, O_RDONLY);
408
crit(ap->logopt, "failed to create ioctl fd for %s", me->key);
412
if ((cl_flags = fcntl(ioctlfd, F_GETFD, 0)) != -1) {
413
cl_flags |= FD_CLOEXEC;
414
fcntl(ioctlfd, F_SETFD, cl_flags);
417
/* Calculate the timeouts */
418
ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
420
ioctl(ioctlfd, AUTOFS_IOC_SETTIMEOUT, &timeout);
424
"mounted direct mount on %s "
425
"with timeout %u, freq %u seconds", me->key,
426
(unsigned int) ap->exp_timeout,
427
(unsigned int) ap->exp_runfreq);
430
"mounted direct mount on %s with timeouts disabled",
433
ret = fstat(ioctlfd, &st);
416
ret = stat(me->key, &st);
435
418
error(ap->logopt,
436
419
"failed to stat direct mount trigger %s", me->key);
423
ops->open(ap->logopt, &ioctlfd, st.st_dev, me->key);
425
crit(ap->logopt, "failed to create ioctl fd for %s", me->key);
429
ops->timeout(ap->logopt, ioctlfd, &timeout);
430
notify_mount_result(ap, me->key, str_direct);
439
431
cache_set_ino_index(me->mc, me->key, st.st_dev, st.st_ino);
432
ops->close(ap->logopt, ioctlfd);
443
434
debug(ap->logopt, "mounted trigger %s", me->key);
450
439
/* TODO: maybe force umount (-l) */
442
if (me->flags & MOUNT_FLAG_DIR_CREATED)
559
ioctlfd = open(me->key, O_RDONLY);
561
if ((cl_flags = fcntl(ioctlfd, F_GETFD, 0)) != -1) {
562
cl_flags |= FD_CLOEXEC;
563
fcntl(ioctlfd, F_SETFD, cl_flags);
542
ops->open(ap->logopt, &ioctlfd, me->dev, me->key);
568
545
if (ioctlfd >= 0) {
546
unsigned int status = 1;
571
rv = ioctl(ioctlfd, AUTOFS_IOC_ASKUMOUNT, &status);
548
rv = ops->askumount(ap->logopt, ioctlfd, &status);
573
550
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
574
551
logerr("ioctl failed: %s", estr);
576
553
} else if (!status) {
577
554
if (ap->state != ST_SHUTDOWN_FORCE) {
579
"ask umount returned busy for %s",
557
"ask umount returned busy for %s",
583
561
me->ioctlfd = -1;
584
ioctl(ioctlfd, AUTOFS_IOC_CATATONIC, 0);
562
ops->catatonic(ap->logopt, ioctlfd);
563
ops->close(ap->logopt, ioctlfd);
586
564
goto force_umount;
589
567
me->ioctlfd = -1;
590
ioctl(ioctlfd, AUTOFS_IOC_CATATONIC, 0);
568
ops->catatonic(ap->logopt, ioctlfd);
569
ops->close(ap->logopt, ioctlfd);
654
int mount_autofs_offset(struct autofs_point *ap, struct mapent *me)
632
int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, const char *root, const char *offset)
634
const char *str_offset = mount_type_str(t_offset);
635
struct ioctl_ops *ops = get_ioctl_ops();
656
636
char buf[MAX_ERR_BUF];
657
637
struct mnt_params *mp;
658
638
time_t timeout = ap->exp_timeout;
660
int ioctlfd, cl_flags, status, ret;
640
int ioctlfd, status, ret;
661
641
const char *type, *map_name = NULL;
663
if (is_mounted(_PROC_MOUNTS, me->key, MNTS_AUTOFS)) {
664
if (ap->state != ST_READMAP)
666
"trigger %s already mounted", me->key);
670
if (me->ioctlfd != -1) {
671
error(ap->logopt, "active offset mount %s", me->key);
642
char mountpoint[PATH_MAX];
644
if (ops->version && ap->flags & MOUNT_FLAG_REMOUNT) {
645
ret = try_remount(ap, me, t_offset);
647
return MOUNT_OFFSET_OK;
648
return MOUNT_OFFSET_FAIL;
651
if (is_mounted(_PROC_MOUNTS, me->key, MNTS_AUTOFS)) {
652
if (ap->state != ST_READMAP)
654
"trigger %s already mounted", me->key);
655
return MOUNT_OFFSET_OK;
658
if (me->ioctlfd != -1) {
659
error(ap->logopt, "active offset mount %s", me->key);
660
return MOUNT_OFFSET_FAIL;
675
664
status = pthread_once(&key_mnt_params_once, key_mnt_params_init);
697
686
if (!mp->options) {
698
mp->options = make_options_string(ap->path, ap->kpipefd, "offset");
687
mp->options = make_options_string(ap->path, ap->kpipefd, str_offset);
699
688
if (!mp->options)
689
return MOUNT_OFFSET_OK;
692
strcpy(mountpoint, root);
693
strcat(mountpoint, offset);
703
695
/* In case the directory doesn't exist, try to mkdir it */
704
if (mkdir_path(me->key, 0555) < 0) {
696
if (mkdir_path(mountpoint, 0555) < 0) {
705
697
if (errno == EEXIST) {
699
* If the mount point directory is a real mount
700
* and it isn't the root offset then it must be
701
* a mount that has been automatically mounted by
702
* the kernel NFS client.
704
if (me->multi != me &&
705
is_mounted(_PROC_MOUNTS, mountpoint, MNTS_REAL))
706
return MOUNT_OFFSET_IGNORE;
707
709
* If we recieve an error, and it's EEXIST
708
710
* we know the directory was not created.
712
me->flags &= ~MOUNT_FLAG_DIR_CREATED;
711
713
} else if (errno == EACCES) {
713
715
* We require the mount point directory to exist when
749
751
map_name = me->mc->map->argv[0];
751
ret = mount(map_name, me->key, "autofs", MS_MGC_VAL, mp->options);
753
ret = mount(map_name, mountpoint, "autofs", MS_MGC_VAL, mp->options);
753
crit(ap->logopt, "failed to mount autofs path %s", me->key);
759
"failed to mount autofs offset trigger %s", me->key);
756
"failed to mount offset trigger %s at %s",
757
me->key, mountpoint);
763
/* Root directory for ioctl()'s */
764
ioctlfd = open(me->key, O_RDONLY);
766
crit(ap->logopt, "failed to create ioctl fd for %s", me->key);
770
if ((cl_flags = fcntl(ioctlfd, F_GETFD, 0)) != -1) {
771
cl_flags |= FD_CLOEXEC;
772
fcntl(ioctlfd, F_SETFD, cl_flags);
775
ioctl(ioctlfd, AUTOFS_IOC_SETTIMEOUT, &timeout);
777
ret = fstat(ioctlfd, &st);
761
ret = stat(mountpoint, &st);
779
763
error(ap->logopt,
780
"failed to stat direct mount trigger %s", me->key);
764
"failed to stat direct mount trigger %s", mountpoint);
768
ops->open(ap->logopt, &ioctlfd, st.st_dev, mountpoint);
770
crit(ap->logopt, "failed to create ioctl fd for %s", mountpoint);
774
ops->timeout(ap->logopt, ioctlfd, &timeout);
775
notify_mount_result(ap, mountpoint, str_offset);
784
776
cache_set_ino_index(me->mc, me->key, st.st_dev, st.st_ino);
788
debug(ap->logopt, "mounted trigger %s", me->key);
777
ops->close(ap->logopt, ioctlfd);
779
debug(ap->logopt, "mounted trigger %s at %s", me->key, mountpoint);
781
return MOUNT_OFFSET_OK;
797
if (stat(me->key, &st) == 0 && me->dir_created)
798
rmdir_path(ap, me->key, st.st_dev);
803
static int expire_direct(int ioctlfd, const char *path, unsigned int when, unsigned int logopt)
805
char buf[MAX_ERR_BUF];
809
if (fstat(ioctlfd, &st) == -1) {
810
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
811
error(logopt, "fstat failed: %s", estr);
815
retries = (count_mounts(logopt, path, st.st_dev) + 1) * EXPIRE_RETRIES;
818
struct timespec tm = {0, 100000000};
820
/* Ggenerate expire message for the mount. */
821
ret = ioctl(ioctlfd, AUTOFS_IOC_EXPIRE_DIRECT, &when);
823
/* Mount has gone away */
824
if (errno == EBADF || errno == EINVAL)
827
/* Other than need to wait for the kernel ? */
832
nanosleep(&tm, NULL);
835
if (!ioctl(ioctlfd, AUTOFS_IOC_ASKUMOUNT, &ret)) {
786
if (stat(mountpoint, &st) == 0 && me->flags & MOUNT_FLAG_DIR_CREATED)
787
rmdir_path(ap, mountpoint, st.st_dev);
789
return MOUNT_OFFSET_FAIL;
843
792
void *expire_proc_direct(void *arg)
794
struct ioctl_ops *ops = get_ioctl_ops();
845
795
struct mnt_list *mnts = NULL, *next;
846
796
struct list_head list, *p;
847
797
struct expire_args *ea;
1038
992
static void *do_expire_direct(void *arg)
1040
struct pending_args *mt;
994
struct ioctl_ops *ops = get_ioctl_ops();
995
struct pending_args *args, mt;
1041
996
struct autofs_point *ap;
1043
998
int status, state;
1045
mt = (struct pending_args *) arg;
1000
args = (struct pending_args *) arg;
1047
1002
status = pthread_mutex_lock(&ea_mutex);
1054
status = pthread_cond_signal(&mt->cond);
1006
memcpy(&mt, args, sizeof(struct pending_args));
1011
status = pthread_cond_signal(&args->cond);
1058
1015
expire_mutex_unlock(NULL);
1060
pthread_cleanup_push(free_pending_args, mt);
1061
pthread_cleanup_push(pending_cond_destroy, mt);
1062
pthread_cleanup_push(expire_send_fail, mt);
1017
pthread_cleanup_push(expire_send_fail, &mt);
1064
len = _strlen(mt->name, KEY_MAX_LEN);
1019
len = _strlen(mt.name, KEY_MAX_LEN);
1066
warn(ap->logopt, "direct key path too long %s", mt->name);
1021
warn(ap->logopt, "direct key path too long %s", mt.name);
1067
1022
/* TODO: force umount ?? */
1068
1023
pthread_exit(NULL);
1071
status = do_expire(ap, mt->name, len);
1026
status = do_expire(ap, mt.name, len);
1072
1027
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
1074
send_fail(ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1029
ops->send_fail(ap->logopt,
1030
mt.ioctlfd, mt.wait_queue_token, -ENOENT);
1076
1032
struct mapent *me;
1077
cache_readlock(mt->mc);
1078
me = cache_lookup_distinct(mt->mc, mt->name);
1033
cache_writelock(mt.mc);
1034
me = cache_lookup_distinct(mt.mc, mt.name);
1079
1035
me->ioctlfd = -1;
1080
cache_unlock(mt->mc);
1081
send_ready(ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1036
cache_unlock(mt.mc);
1037
ops->send_ready(ap->logopt, mt.ioctlfd, mt.wait_queue_token);
1038
ops->close(ap->logopt, mt.ioctlfd);
1084
1040
pthread_setcancelstate(state, NULL);
1086
1042
pthread_cleanup_pop(0);
1087
pthread_cleanup_pop(1);
1088
pthread_cleanup_pop(1);
1093
1047
int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_direct_t *pkt)
1049
struct ioctl_ops *ops = get_ioctl_ops();
1095
1050
struct map_source *map;
1096
1051
struct mapent_cache *mc = NULL;
1097
1052
struct mapent *me = NULL;
1098
1053
struct pending_args *mt;
1099
1054
char buf[MAX_ERR_BUF];
1100
1055
pthread_t thid;
1056
struct timespec wait;
1101
1058
int status, state;
1103
1060
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
1133
1089
crit(ap->logopt, "can't find map entry for (%lu,%lu)",
1134
1090
(unsigned long) pkt->dev, (unsigned long) pkt->ino);
1091
master_source_unlock(ap->entry);
1092
master_mutex_unlock();
1135
1093
pthread_setcancelstate(state, NULL);
1097
/* Can't expire it if it isn't mounted */
1098
if (me->ioctlfd == -1) {
1100
ops->open(ap->logopt, &ioctlfd, me->dev, me->key);
1101
if (ioctlfd == -1) {
1102
crit(ap->logopt, "can't open ioctlfd for %s",
1104
pthread_setcancelstate(state, NULL);
1107
ops->send_ready(ap->logopt, ioctlfd, pkt->wait_queue_token);
1108
ops->close(ap->logopt, ioctlfd);
1110
master_source_unlock(ap->entry);
1111
pthread_setcancelstate(state, NULL);
1140
1115
mt = malloc(sizeof(struct pending_args));
1142
1117
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
1143
1118
error(ap->logopt, "malloc: %s", estr);
1144
send_fail(ap->logopt, me->ioctlfd, pkt->wait_queue_token);
1119
ops->send_fail(ap->logopt,
1120
me->ioctlfd, pkt->wait_queue_token, -ENOMEM);
1145
1121
cache_unlock(mc);
1122
master_source_unlock(ap->entry);
1146
1123
pthread_setcancelstate(state, NULL);
1182
1161
cache_unlock(mc);
1162
master_source_unlock(ap->entry);
1164
pthread_cleanup_push(free_pending_args, mt);
1165
pthread_cleanup_push(pending_cond_destroy, mt);
1184
1166
pthread_cleanup_push(expire_mutex_unlock, NULL);
1185
1167
pthread_setcancelstate(state, NULL);
1187
1169
mt->signaled = 0;
1188
1170
while (!mt->signaled) {
1171
gettimeofday(&now, NULL);
1172
wait.tv_sec = now.tv_sec + 2;
1173
wait.tv_nsec = now.tv_usec * 1000;
1189
1174
status = pthread_cond_wait(&mt->cond, &ea_mutex);
1175
if (status && status != ETIMEDOUT)
1194
1179
pthread_cleanup_pop(1);
1180
pthread_cleanup_pop(1);
1181
pthread_cleanup_pop(1);
1199
1186
static void mount_send_fail(void *arg)
1188
struct ioctl_ops *ops = get_ioctl_ops();
1201
1189
struct pending_args *mt = arg;
1202
send_fail(mt->ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1190
struct autofs_point *ap = mt->ap;
1191
ops->send_fail(ap->logopt, mt->ioctlfd, mt->wait_queue_token, -ENOENT);
1192
ops->close(ap->logopt, mt->ioctlfd);
1195
static void pending_mutex_destroy(void *arg)
1197
struct pending_args *mt = (struct pending_args *) arg;
1198
int status = pthread_mutex_destroy(&mt->mutex);
1206
1203
static void mount_mutex_unlock(void *arg)
1208
int status = pthread_mutex_unlock(&ma_mutex);
1205
struct pending_args *mt = (struct pending_args *) arg;
1206
int status = pthread_mutex_unlock(&mt->mutex);
1213
1211
static void *do_mount_direct(void *arg)
1215
struct pending_args *mt;
1213
struct ioctl_ops *ops = get_ioctl_ops();
1214
struct pending_args *args, mt;
1216
1215
struct autofs_point *ap;
1218
struct passwd *ppw = &pw;
1219
struct passwd **pppw = &ppw;
1222
struct group **ppgr;
1223
char *pw_tmp, *gr_tmp;
1224
struct thread_stdenv_vars *tsv;
1226
1216
struct stat st;
1227
1217
int status, state;
1229
mt = (struct pending_args *) arg;
1231
status = pthread_mutex_lock(&ma_mutex);
1238
status = pthread_cond_signal(&mt->cond);
1242
mount_mutex_unlock(NULL);
1244
pthread_cleanup_push(free_pending_args, mt);
1245
pthread_cleanup_push(pending_cond_destroy, mt);
1246
pthread_cleanup_push(mount_send_fail, mt);
1219
args = (struct pending_args *) arg;
1221
status = pthread_mutex_lock(&args->mutex);
1225
memcpy(&mt, args, sizeof(struct pending_args));
1230
status = pthread_cond_signal(&args->cond);
1234
mount_mutex_unlock(args);
1236
pthread_cleanup_push(mount_send_fail, &mt);
1248
1238
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
1250
status = fstat(mt->ioctlfd, &st);
1240
status = fstat(mt.ioctlfd, &st);
1251
1241
if (status == -1) {
1252
1242
error(ap->logopt,
1253
"can't stat direct mount trigger %s", mt->name);
1243
"can't stat direct mount trigger %s", mt.name);
1244
ops->send_fail(ap->logopt,
1245
mt.ioctlfd, mt.wait_queue_token, -ENOENT);
1246
ops->close(ap->logopt, mt.ioctlfd);
1254
1247
pthread_setcancelstate(state, NULL);
1255
1248
pthread_exit(NULL);
1258
status = stat(mt->name, &st);
1259
if (!S_ISDIR(st.st_mode) || st.st_dev != mt->dev) {
1251
status = stat(mt.name, &st);
1252
if (!S_ISDIR(st.st_mode) || st.st_dev != mt.dev) {
1260
1253
error(ap->logopt,
1261
1254
"direct trigger not valid or already mounted %s",
1256
ops->send_ready(ap->logopt, mt.ioctlfd, mt.wait_queue_token);
1257
ops->close(ap->logopt, mt.ioctlfd);
1263
1258
pthread_setcancelstate(state, NULL);
1264
1259
pthread_exit(NULL);
1267
1262
pthread_setcancelstate(state, NULL);
1269
info(ap->logopt, "attempting to mount entry %s", mt->name);
1272
* Setup thread specific data values for macro
1273
* substution in map entries during the mount.
1274
* Best effort only as it must go ahead.
1277
tsv = malloc(sizeof(struct thread_stdenv_vars));
1284
/* Try to get passwd info */
1286
tmplen = sysconf(_SC_GETPW_R_SIZE_MAX);
1288
error(ap->logopt, "failed to get buffer size for getpwuid_r");
1293
pw_tmp = malloc(tmplen + 1);
1295
error(ap->logopt, "failed to malloc buffer for getpwuid_r");
1300
status = getpwuid_r(mt->uid, ppw, pw_tmp, tmplen, pppw);
1301
if (status || !ppw) {
1302
error(ap->logopt, "failed to get passwd info from getpwuid_r");
1308
tsv->user = strdup(pw.pw_name);
1310
error(ap->logopt, "failed to malloc buffer for user");
1316
tsv->home = strdup(pw.pw_dir);
1318
error(ap->logopt, "failed to malloc buffer for home");
1327
/* Try to get group info */
1329
grplen = sysconf(_SC_GETGR_R_SIZE_MAX);
1331
error(ap->logopt, "failed to get buffer size for getgrgid_r");
1341
char *tmp = realloc(gr_tmp, tmplen + 1);
1343
error(ap->logopt, "failed to malloc buffer for getgrgid_r");
1354
status = getgrgid_r(mt->gid, pgr, gr_tmp, tmplen, ppgr);
1355
if (status != ERANGE)
1360
if (status || !pgr) {
1361
error(ap->logopt, "failed to get group info from getgrgid_r");
1369
tsv->group = strdup(gr.gr_name);
1371
error(ap->logopt, "failed to malloc buffer for group");
1381
status = pthread_setspecific(key_thread_stdenv_vars, tsv);
1383
error(ap->logopt, "failed to set stdenv thread var");
1391
status = lookup_nss_mount(ap, NULL, mt->name, strlen(mt->name));
1264
info(ap->logopt, "attempting to mount entry %s", mt.name);
1266
set_tsd_user_vars(ap->logopt, mt.uid, mt.gid);
1268
status = lookup_nss_mount(ap, NULL, mt.name, mt.len);
1393
1270
* Direct mounts are always a single mount. If it fails there's
1394
1271
* nothing to undo so just complain
1396
1273
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
1398
1275
struct mapent *me;
1399
int real_mount, set_fd;
1400
cache_readlock(mt->mc);
1401
me = cache_lookup_distinct(mt->mc, mt->name);
1402
real_mount = is_mounted(_PATH_MOUNTED, me->key, MNTS_REAL);
1403
set_fd = (real_mount || me->multi == me);
1404
cache_unlock(mt->mc);
1406
me->ioctlfd = mt->ioctlfd;
1407
send_ready(ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1409
send_ready(ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1277
unsigned int close_fd = 0;
1279
if (statfs(mt.name, &fs) == -1 ||
1280
(fs.f_type == AUTOFS_SUPER_MAGIC &&
1281
!master_find_submount(ap, mt.name)))
1283
cache_writelock(mt.mc);
1284
if ((me = cache_lookup_distinct(mt.mc, mt.name))) {
1286
* Careful here, we need to leave the file handle open
1287
* for direct mount multi-mounts with no real mount at
1288
* their base so they will be expired.
1290
if (close_fd && me == me->multi)
1293
me->ioctlfd = mt.ioctlfd;
1412
info(ap->logopt, "mounted %s", mt->name);
1295
ops->send_ready(ap->logopt, mt.ioctlfd, mt.wait_queue_token);
1296
cache_unlock(mt.mc);
1298
ops->close(ap->logopt, mt.ioctlfd);
1299
info(ap->logopt, "mounted %s", mt.name);
1414
send_fail(mt->ap->logopt, mt->ioctlfd, mt->wait_queue_token);
1416
info(ap->logopt, "failed to mount %s", mt->name);
1301
/* TODO: get mount return status from lookup_nss_mount */
1302
ops->send_fail(ap->logopt,
1303
mt.ioctlfd, mt.wait_queue_token, -ENOENT);
1304
ops->close(ap->logopt, mt.ioctlfd);
1305
info(ap->logopt, "failed to mount %s", mt.name);
1418
1307
pthread_setcancelstate(state, NULL);
1420
1309
pthread_cleanup_pop(0);
1421
pthread_cleanup_pop(1);
1422
pthread_cleanup_pop(1);
1427
1314
int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_direct_t *pkt)
1316
struct ioctl_ops *ops = get_ioctl_ops();
1429
1317
struct map_source *map;
1430
1318
struct mapent_cache *mc = NULL;
1431
1319
struct mapent *me = NULL;
1475
1375
ioctlfd = me->ioctlfd;
1476
1376
me->ioctlfd = -1;
1478
ioctlfd = open(me->key, O_RDONLY);
1378
ops->open(ap->logopt, &ioctlfd, me->dev, me->key);
1480
1380
if (ioctlfd == -1) {
1481
1381
cache_unlock(mc);
1382
master_source_unlock(ap->entry);
1383
master_mutex_unlock();
1482
1384
pthread_setcancelstate(state, NULL);
1483
1385
crit(ap->logopt, "failed to create ioctl fd for %s", me->key);
1484
1386
/* TODO: how do we clear wait q in kernel ?? */
1488
if ((cl_flags = fcntl(ioctlfd, F_GETFD, 0)) != -1) {
1489
cl_flags |= FD_CLOEXEC;
1490
fcntl(ioctlfd, F_SETFD, cl_flags);
1493
1390
debug(ap->logopt, "token %ld, name %s, request pid %u",
1494
1391
(unsigned long) pkt->wait_queue_token, me->key, pkt->pid);
1496
1393
/* Ignore packet if we're trying to shut down */
1498
ap->state == ST_SHUTDOWN_FORCE ||
1499
ap->state == ST_SHUTDOWN) {
1500
send_fail(ap->logopt, ioctlfd, pkt->wait_queue_token);
1394
if (ap->shutdown || ap->state == ST_SHUTDOWN_FORCE) {
1395
ops->send_fail(ap->logopt,
1396
ioctlfd, pkt->wait_queue_token, -ENOENT);
1397
ops->close(ap->logopt, ioctlfd);
1399
master_source_unlock(ap->entry);
1400
master_mutex_unlock();
1401
pthread_setcancelstate(state, NULL);
1405
len = strlen(me->key);
1406
if (len >= PATH_MAX) {
1407
error(ap->logopt, "direct mount path too long %s", me->key);
1408
ops->send_fail(ap->logopt,
1409
ioctlfd, pkt->wait_queue_token, -ENAMETOOLONG);
1410
ops->close(ap->logopt, ioctlfd);
1412
master_source_unlock(ap->entry);
1413
master_mutex_unlock();
1503
1414
pthread_setcancelstate(state, NULL);
1537
1456
status = pthread_create(&thid, &thread_attr, do_mount_direct, mt);
1539
1458
error(ap->logopt, "missing mount thread create failed");
1540
send_fail(ap->logopt, ioctlfd, pkt->wait_queue_token);
1459
ops->send_fail(ap->logopt,
1460
ioctlfd, pkt->wait_queue_token, -status);
1461
ops->close(ap->logopt, ioctlfd);
1542
1462
cache_unlock(mc);
1543
mount_mutex_unlock(NULL);
1463
master_source_unlock(ap->entry);
1464
master_mutex_unlock();
1465
mount_mutex_unlock(mt);
1544
1466
pending_cond_destroy(mt);
1467
pending_mutex_destroy(mt);
1545
1468
free_pending_args(mt);
1546
1469
pthread_setcancelstate(state, NULL);
1550
1473
cache_unlock(mc);
1551
pthread_cleanup_push(mount_mutex_unlock, NULL);
1474
master_source_unlock(ap->entry);
1476
master_mutex_unlock();
1478
pthread_cleanup_push(free_pending_args, mt);
1479
pthread_cleanup_push(pending_mutex_destroy, mt);
1480
pthread_cleanup_push(pending_cond_destroy, mt);
1481
pthread_cleanup_push(mount_mutex_unlock, mt);
1552
1482
pthread_setcancelstate(state, NULL);
1554
1484
mt->signaled = 0;
1555
1485
while (!mt->signaled) {
1556
status = pthread_cond_wait(&mt->cond, &ma_mutex);
1486
gettimeofday(&now, NULL);
1487
wait.tv_sec = now.tv_sec + 2;
1488
wait.tv_nsec = now.tv_usec * 1000;
1489
status = pthread_cond_timedwait(&mt->cond, &mt->mutex, &wait);
1490
if (status && status != ETIMEDOUT)
1561
1494
pthread_cleanup_pop(1);
1495
pthread_cleanup_pop(1);
1496
pthread_cleanup_pop(1);
1497
pthread_cleanup_pop(1);