From ae6eb4aae7e6d2b82f0cdfbb57a62b53f0c2ac34 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Apr 16 2021 22:13:47 +0000 Subject: Apply patch autofs-5.1.4-use_hostname_for_mounts-shouldnt-prevent-selection-among-replicas.patch patch_name: autofs-5.1.4-use_hostname_for_mounts-shouldnt-prevent-selection-among-replicas.patch present_in_specfile: true --- diff --git a/CHANGELOG b/CHANGELOG index 2d5d5b1..104fca9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ xx/xx/2018 autofs-5.1.5 - fix error return in do_nfs_mount(). - add error handling for ext_mount_add(). - account for recent libnsl changes. +- use_hostname_for_mounts shouldn't prevent selection among replicas. 19/12/2017 autofs-5.1.4 - fix spec file url. diff --git a/include/replicated.h b/include/replicated.h index 69ab780..0f482d2 100644 --- a/include/replicated.h +++ b/include/replicated.h @@ -57,6 +57,7 @@ struct host { char *name; + int ent_num; struct sockaddr *addr; size_t addr_len; unsigned int rr; @@ -70,7 +71,7 @@ struct host { }; void seed_random(void); -struct host *new_host(const char *, struct sockaddr *, size_t, +struct host *new_host(const char *, int, struct sockaddr *, size_t, unsigned int, unsigned int, unsigned int); void free_host_list(struct host **); int parse_location(unsigned, struct host **, const char *, unsigned int); diff --git a/modules/mount_nfs.c b/modules/mount_nfs.c index 7716654..4cf0cd2 100644 --- a/modules/mount_nfs.c +++ b/modules/mount_nfs.c @@ -236,7 +236,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int (vers & NFS4_VERS_MASK) != 0 && !(vers & UDP6_REQUESTED)) { unsigned int v4_probe_ok = 0; - struct host *tmp = new_host(hosts->name, + struct host *tmp = new_host(hosts->name, 0, hosts->addr, hosts->addr_len, hosts->proximity, hosts->weight, hosts->options); diff --git a/modules/replicated.c b/modules/replicated.c index 3ac4c70..f7b8323 100644 --- a/modules/replicated.c +++ b/modules/replicated.c @@ -83,7 +83,7 @@ void seed_random(void) return; } -struct host *new_host(const char *name, +struct host *new_host(const char *name, int ent_num, struct sockaddr *addr, size_t addr_len, unsigned int proximity, unsigned int weight, unsigned int options) @@ -116,6 +116,7 @@ struct host *new_host(const char *name, memset(new, 0, sizeof(struct host)); new->name = tmp1; + new->ent_num = ent_num; new->addr_len = addr_len; new->addr = tmp2; new->proximity = proximity; @@ -714,7 +715,7 @@ done: int prune_host_list(unsigned logopt, struct host **list, unsigned int vers, int port) { - struct host *this, *last, *first; + struct host *this, *last, *first, *prev; struct host *new = NULL; unsigned int proximity, selected_version = 0; unsigned int v2_tcp_count, v3_tcp_count, v4_tcp_count; @@ -726,12 +727,6 @@ int prune_host_list(unsigned logopt, struct host **list, if (!*list) return 0; - /* If we're using the host name then there's no point probing - * avialability and respose time. - */ - if (defaults_use_hostname_for_mounts()) - return 1; - /* Use closest hosts to choose NFS version */ first = *list; @@ -877,11 +872,18 @@ int prune_host_list(unsigned logopt, struct host **list, first = last; this = first; + prev = NULL; while (this) { struct host *next = this->next; if (!this->name) { remove_host(list, this); add_host(&new, this); + } else if (defaults_use_hostname_for_mounts() && prev && + prev->ent_num == this->ent_num) { + /* When we use the hostname to mount, there is no + * point in probing every address it has, just one is + * enough. Skip the rest. + */ } else { status = get_supported_ver_and_cost(logopt, this, selected_version, port); @@ -889,6 +891,7 @@ int prune_host_list(unsigned logopt, struct host **list, this->version = selected_version; remove_host(list, this); add_host(&new, this); + prev = this; } } this = next; @@ -901,7 +904,7 @@ int prune_host_list(unsigned logopt, struct host **list, } static int add_new_host(struct host **list, - const char *host, unsigned int weight, + const char *host, int ent_num, unsigned int weight, struct addrinfo *host_addr, unsigned int rr, unsigned int options) { @@ -940,7 +943,7 @@ static int add_new_host(struct host **list, else return 0; - new = new_host(host, host_addr->ai_addr, addr_len, prx, weight, options); + new = new_host(host, ent_num, host_addr->ai_addr, addr_len, prx, weight, options); if (!new) return 0; @@ -953,7 +956,7 @@ static int add_new_host(struct host **list, return 1; } -static int add_host_addrs(struct host **list, const char *host, +static int add_host_addrs(struct host **list, const char *host, int ent_num, unsigned int weight, unsigned int options) { struct addrinfo hints, *ni, *this; @@ -988,7 +991,7 @@ static int add_host_addrs(struct host **list, const char *host, this = ni; while (this) { - ret = add_new_host(list, host, weight, this, 0, options); + ret = add_new_host(list, host, ent_num, weight, this, 0, options); if (!ret) break; this = this->ai_next; @@ -1027,7 +1030,7 @@ try_name: rr++; this = ni; while (this) { - ret = add_new_host(list, host, weight, this, rr, options); + ret = add_new_host(list, host, ent_num, weight, this, rr, options); if (!ret) break; this = this->ai_next; @@ -1120,6 +1123,7 @@ int parse_location(unsigned logopt, struct host **hosts, { char *str, *p, *delim; unsigned int empty = 1; + int ent_num = 1; if (!list) return 0; @@ -1177,7 +1181,7 @@ int parse_location(unsigned logopt, struct host **hosts, } if (p != delim) { - if (!add_host_addrs(hosts, p, weight, options)) { + if (!add_host_addrs(hosts, p, ent_num, weight, options)) { if (empty) { p = next; continue; @@ -1199,7 +1203,7 @@ int parse_location(unsigned logopt, struct host **hosts, *delim = '\0'; next = delim + 1; - if (!add_host_addrs(hosts, p, weight, options)) { + if (!add_host_addrs(hosts, p, ent_num, weight, options)) { p = next; continue; } @@ -1213,6 +1217,7 @@ int parse_location(unsigned logopt, struct host **hosts, return 0; } + ent_num++; p = next; }