Deleted Added
full compact
autofs.c (274237) autofs.c (279741)
1/*-
2 * Copyright (c) 2014 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 47 unchanged lines hidden (view full) ---

56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 */
62
63#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2014 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 47 unchanged lines hidden (view full) ---

56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 */
62
63#include <sys/cdefs.h>
64 __FBSDID("$FreeBSD: stable/10/sys/fs/autofs/autofs.c 274237 2014-11-07 15:49:04Z trasz $");
64 __FBSDID("$FreeBSD: stable/10/sys/fs/autofs/autofs.c 279741 2015-03-07 19:32:19Z trasz $");
65
66#include <sys/param.h>
67#include <sys/systm.h>
68#include <sys/buf.h>
69#include <sys/conf.h>
70#include <sys/dirent.h>
71#include <sys/ioccom.h>
72#include <sys/kernel.h>

--- 196 unchanged lines hidden (view full) ---

269
270 sx_xlock(&autofs_softc->sc_lock);
271 AUTOFS_WARN("request %d for %s timed out after %d seconds",
272 ar->ar_id, ar->ar_path, autofs_timeout);
273 /*
274 * XXX: EIO perhaps?
275 */
276 ar->ar_error = ETIMEDOUT;
65
66#include <sys/param.h>
67#include <sys/systm.h>
68#include <sys/buf.h>
69#include <sys/conf.h>
70#include <sys/dirent.h>
71#include <sys/ioccom.h>
72#include <sys/kernel.h>

--- 196 unchanged lines hidden (view full) ---

269
270 sx_xlock(&autofs_softc->sc_lock);
271 AUTOFS_WARN("request %d for %s timed out after %d seconds",
272 ar->ar_id, ar->ar_path, autofs_timeout);
273 /*
274 * XXX: EIO perhaps?
275 */
276 ar->ar_error = ETIMEDOUT;
277 ar->ar_wildcards = true;
277 ar->ar_done = true;
278 ar->ar_in_progress = false;
279 cv_broadcast(&autofs_softc->sc_cv);
280 sx_xunlock(&autofs_softc->sc_lock);
281}
282
283bool
284autofs_cached(struct autofs_node *anp, const char *component, int componentlen)
285{
286 int error;
287 struct autofs_mount *amp;
288
289 amp = anp->an_mount;
290
291 AUTOFS_ASSERT_UNLOCKED(amp);
292
293 /*
278 ar->ar_done = true;
279 ar->ar_in_progress = false;
280 cv_broadcast(&autofs_softc->sc_cv);
281 sx_xunlock(&autofs_softc->sc_lock);
282}
283
284bool
285autofs_cached(struct autofs_node *anp, const char *component, int componentlen)
286{
287 int error;
288 struct autofs_mount *amp;
289
290 amp = anp->an_mount;
291
292 AUTOFS_ASSERT_UNLOCKED(amp);
293
294 /*
294 * For top-level nodes we need to request automountd(8)
295 * assistance even if the node is marked as cached,
296 * but the requested subdirectory does not exist. This
297 * is necessary for wildcard indirect map keys to work.
295 * For root node we need to request automountd(8) assistance even
296 * if the node is marked as cached, but the requested top-level
297 * directory does not exist. This is necessary for wildcard indirect
298 * map keys to work. We don't do this if we know that there are
299 * no wildcards.
298 */
300 */
299 if (anp->an_parent == NULL && componentlen != 0) {
301 if (anp->an_parent == NULL && componentlen != 0 && anp->an_wildcards) {
300 AUTOFS_SLOCK(amp);
301 error = autofs_node_find(anp, component, componentlen, NULL);
302 AUTOFS_SUNLOCK(amp);
303 if (error != 0)
304 return (false);
305 }
306
307 return (anp->an_cached);

--- 53 unchanged lines hidden (view full) ---

361 const char *component, int componentlen)
362{
363 sigset_t oldset;
364 struct autofs_mount *amp;
365 struct autofs_node *firstanp;
366 struct autofs_request *ar;
367 char *key, *path;
368 int error = 0, request_error, last;
302 AUTOFS_SLOCK(amp);
303 error = autofs_node_find(anp, component, componentlen, NULL);
304 AUTOFS_SUNLOCK(amp);
305 if (error != 0)
306 return (false);
307 }
308
309 return (anp->an_cached);

--- 53 unchanged lines hidden (view full) ---

363 const char *component, int componentlen)
364{
365 sigset_t oldset;
366 struct autofs_mount *amp;
367 struct autofs_node *firstanp;
368 struct autofs_request *ar;
369 char *key, *path;
370 int error = 0, request_error, last;
371 bool wildcards;
369
370 amp = anp->an_mount;
371
372 sx_assert(&autofs_softc->sc_lock, SA_XLOCKED);
373
374 if (anp->an_parent == NULL) {
375 key = strndup(component, componentlen, M_AUTOFS);
376 } else {

--- 73 unchanged lines hidden (view full) ---

450 }
451
452 request_error = ar->ar_error;
453 if (request_error != 0) {
454 AUTOFS_WARN("request for %s completed with error %d",
455 ar->ar_path, request_error);
456 }
457
372
373 amp = anp->an_mount;
374
375 sx_assert(&autofs_softc->sc_lock, SA_XLOCKED);
376
377 if (anp->an_parent == NULL) {
378 key = strndup(component, componentlen, M_AUTOFS);
379 } else {

--- 73 unchanged lines hidden (view full) ---

453 }
454
455 request_error = ar->ar_error;
456 if (request_error != 0) {
457 AUTOFS_WARN("request for %s completed with error %d",
458 ar->ar_path, request_error);
459 }
460
461 wildcards = ar->ar_wildcards;
462
458 last = refcount_release(&ar->ar_refcount);
459 if (last) {
460 TAILQ_REMOVE(&autofs_softc->sc_requests, ar, ar_next);
461 /*
462 * Unlock the sc_lock, so that autofs_task() can complete.
463 */
464 sx_xunlock(&autofs_softc->sc_lock);
465 taskqueue_cancel_timeout(taskqueue_thread, &ar->ar_task, NULL);

--- 4 unchanged lines hidden (view full) ---

470
471 /*
472 * Note that we do not do negative caching on purpose. This
473 * way the user can retry access at any time, e.g. after fixing
474 * the failure reason, without waiting for cache timer to expire.
475 */
476 if (error == 0 && request_error == 0 && autofs_cache > 0) {
477 anp->an_cached = true;
463 last = refcount_release(&ar->ar_refcount);
464 if (last) {
465 TAILQ_REMOVE(&autofs_softc->sc_requests, ar, ar_next);
466 /*
467 * Unlock the sc_lock, so that autofs_task() can complete.
468 */
469 sx_xunlock(&autofs_softc->sc_lock);
470 taskqueue_cancel_timeout(taskqueue_thread, &ar->ar_task, NULL);

--- 4 unchanged lines hidden (view full) ---

475
476 /*
477 * Note that we do not do negative caching on purpose. This
478 * way the user can retry access at any time, e.g. after fixing
479 * the failure reason, without waiting for cache timer to expire.
480 */
481 if (error == 0 && request_error == 0 && autofs_cache > 0) {
482 anp->an_cached = true;
483 anp->an_wildcards = wildcards;
478 callout_reset(&anp->an_callout, autofs_cache * hz,
479 autofs_cache_callout, anp);
480 }
481
482 free(key, M_AUTOFS);
483 free(path, M_AUTOFS);
484
485 if (error != 0)

--- 86 unchanged lines hidden (view full) ---

572 PROC_LOCK(curproc);
573 autofs_softc->sc_dev_sid = curproc->p_session->s_sid;
574 PROC_UNLOCK(curproc);
575
576 return (0);
577}
578
579static int
484 callout_reset(&anp->an_callout, autofs_cache * hz,
485 autofs_cache_callout, anp);
486 }
487
488 free(key, M_AUTOFS);
489 free(path, M_AUTOFS);
490
491 if (error != 0)

--- 86 unchanged lines hidden (view full) ---

578 PROC_LOCK(curproc);
579 autofs_softc->sc_dev_sid = curproc->p_session->s_sid;
580 PROC_UNLOCK(curproc);
581
582 return (0);
583}
584
585static int
586autofs_ioctl_done_101(struct autofs_daemon_done_101 *add)
587{
588 struct autofs_request *ar;
589
590 sx_xlock(&autofs_softc->sc_lock);
591 TAILQ_FOREACH(ar, &autofs_softc->sc_requests, ar_next) {
592 if (ar->ar_id == add->add_id)
593 break;
594 }
595
596 if (ar == NULL) {
597 sx_xunlock(&autofs_softc->sc_lock);
598 AUTOFS_DEBUG("id %d not found", add->add_id);
599 return (ESRCH);
600 }
601
602 ar->ar_error = add->add_error;
603 ar->ar_wildcards = true;
604 ar->ar_done = true;
605 ar->ar_in_progress = false;
606 cv_broadcast(&autofs_softc->sc_cv);
607
608 sx_xunlock(&autofs_softc->sc_lock);
609
610 return (0);
611}
612
613static int
580autofs_ioctl_done(struct autofs_daemon_done *add)
581{
582 struct autofs_request *ar;
583
584 sx_xlock(&autofs_softc->sc_lock);
585 TAILQ_FOREACH(ar, &autofs_softc->sc_requests, ar_next) {
586 if (ar->ar_id == add->add_id)
587 break;
588 }
589
590 if (ar == NULL) {
591 sx_xunlock(&autofs_softc->sc_lock);
592 AUTOFS_DEBUG("id %d not found", add->add_id);
593 return (ESRCH);
594 }
595
596 ar->ar_error = add->add_error;
614autofs_ioctl_done(struct autofs_daemon_done *add)
615{
616 struct autofs_request *ar;
617
618 sx_xlock(&autofs_softc->sc_lock);
619 TAILQ_FOREACH(ar, &autofs_softc->sc_requests, ar_next) {
620 if (ar->ar_id == add->add_id)
621 break;
622 }
623
624 if (ar == NULL) {
625 sx_xunlock(&autofs_softc->sc_lock);
626 AUTOFS_DEBUG("id %d not found", add->add_id);
627 return (ESRCH);
628 }
629
630 ar->ar_error = add->add_error;
631 ar->ar_wildcards = add->add_wildcards;
597 ar->ar_done = true;
598 ar->ar_in_progress = false;
599 cv_broadcast(&autofs_softc->sc_cv);
600
601 sx_xunlock(&autofs_softc->sc_lock);
602
603 return (0);
604}

--- 40 unchanged lines hidden (view full) ---

645{
646
647 KASSERT(autofs_softc->sc_dev_opened, ("not opened?"));
648
649 switch (cmd) {
650 case AUTOFSREQUEST:
651 return (autofs_ioctl_request(
652 (struct autofs_daemon_request *)arg));
632 ar->ar_done = true;
633 ar->ar_in_progress = false;
634 cv_broadcast(&autofs_softc->sc_cv);
635
636 sx_xunlock(&autofs_softc->sc_lock);
637
638 return (0);
639}

--- 40 unchanged lines hidden (view full) ---

680{
681
682 KASSERT(autofs_softc->sc_dev_opened, ("not opened?"));
683
684 switch (cmd) {
685 case AUTOFSREQUEST:
686 return (autofs_ioctl_request(
687 (struct autofs_daemon_request *)arg));
688 case AUTOFSDONE101:
689 return (autofs_ioctl_done_101(
690 (struct autofs_daemon_done_101 *)arg));
653 case AUTOFSDONE:
654 return (autofs_ioctl_done(
655 (struct autofs_daemon_done *)arg));
656 default:
657 AUTOFS_DEBUG("invalid cmd %lx", cmd);
658 return (EINVAL);
659 }
660}
691 case AUTOFSDONE:
692 return (autofs_ioctl_done(
693 (struct autofs_daemon_done *)arg));
694 default:
695 AUTOFS_DEBUG("invalid cmd %lx", cmd);
696 return (EINVAL);
697 }
698}