Mercurial > dovecot > core-2.2
annotate src/director/doveadm-connection.c @ 21079:d6f399a7f672
director: Keep per-tag directory
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Thu, 20 Oct 2016 19:06:22 +0300 |
parents | ef9d8f4c6c67 |
children | f9db0ad9001e |
rev | line source |
---|---|
19552
0f22db71df7a
global: freshen copyright
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19497
diff
changeset
|
1 /* Copyright (c) 2010-2016 Dovecot authors, see the included COPYING file */ |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "ioloop.h" |
15187
02451e967a06
Renamed network.[ch] to net.[ch].
Timo Sirainen <tss@iki.fi>
parents:
14682
diff
changeset
|
5 #include "net.h" |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "istream.h" |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "ostream.h" |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "array.h" |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "str.h" |
18067
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
10 #include "strescape.h" |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "llist.h" |
11373
26cfc1c3a4b1
director: Update connection count when client disconnects.
Timo Sirainen <tss@iki.fi>
parents:
11355
diff
changeset
|
12 #include "master-service.h" |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include "user-directory.h" |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "mail-host.h" |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #include "director.h" |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include "director-host.h" |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #include "director-request.h" |
13320
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
18 #include "director-connection.h" |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 #include "doveadm-connection.h" |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 #include <unistd.h> |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 |
11458
4274d1549fa0
Added version_string_verify() and removed code duplication with it.
Timo Sirainen <tss@iki.fi>
parents:
11373
diff
changeset
|
23 #define DOVEADM_PROTOCOL_VERSION_MAJOR 1 |
4274d1549fa0
Added version_string_verify() and removed code duplication with it.
Timo Sirainen <tss@iki.fi>
parents:
11373
diff
changeset
|
24 #define DOVEADM_HANDSHAKE "VERSION\tdirector-doveadm\t1\t0\n" |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 #define MAX_VALID_VHOST_COUNT 1000 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
27 #define DEFAULT_MAX_MOVING_USERS 100 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
28 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
29 struct director_reset_cmd { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
30 struct director_reset_cmd *prev, *next; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
31 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
32 struct director *dir; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
33 struct doveadm_connection *_conn; |
21075
6a363cb51d7f
director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21074
diff
changeset
|
34 struct director_user_iter *iter; |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
35 unsigned int host_idx, hosts_count; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
36 unsigned int max_moving_users; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
37 }; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 struct doveadm_connection { |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 struct doveadm_connection *prev, *next; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 int fd; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 struct io *io; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 struct istream *input; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 struct ostream *output; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 struct director *dir; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
48 struct director_reset_cmd *reset_cmd; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
49 |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 unsigned int handshaked:1; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 }; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 static struct doveadm_connection *doveadm_connections; |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
54 static struct director_reset_cmd *reset_cmds = NULL; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
56 static void doveadm_connection_set_io(struct doveadm_connection *conn); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 static void doveadm_connection_deinit(struct doveadm_connection **_conn); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 static void doveadm_cmd_host_list(struct doveadm_connection *conn) |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 { |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 struct mail_host *const *hostp; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 string_t *str = t_str_new(1024); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 |
11352
19336bddada2
director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents:
11351
diff
changeset
|
64 array_foreach(mail_hosts_get(conn->dir->mail_hosts), hostp) { |
18067
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
65 str_printfa(str, "%s\t%u\t%u\t", |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 net_ip2addr(&(*hostp)->ip), (*hostp)->vhost_count, |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 (*hostp)->user_count); |
19408
7e47f561ad49
director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents:
19407
diff
changeset
|
68 str_append_tabescaped(str, mail_host_get_tag(*hostp)); |
18729
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
69 str_printfa(str, "\t%c\t%ld", (*hostp)->down ? 'D' : 'U', |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
70 (long)(*hostp)->last_updown_change); |
18067
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
71 str_append_c(str, '\n'); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 str_append_c(str, '\n'); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
74 o_stream_nsend(conn->output, str_data(str), str_len(str)); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
12986
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
77 static void doveadm_cmd_host_list_removed(struct doveadm_connection *conn) |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
78 { |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
79 struct mail_host_list *orig_hosts_list; |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
80 struct mail_host *const *orig_hosts, *const *cur_hosts; |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
81 unsigned int i, j, orig_hosts_count, cur_hosts_count; |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
82 string_t *str = t_str_new(1024); |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
83 int ret; |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
84 |
21079
d6f399a7f672
director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21076
diff
changeset
|
85 orig_hosts_list = mail_hosts_init(conn->dir->set->director_user_expire, |
d6f399a7f672
director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21076
diff
changeset
|
86 conn->dir->set->director_consistent_hashing, |
d6f399a7f672
director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21076
diff
changeset
|
87 NULL); |
12986
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
88 (void)mail_hosts_parse_and_add(orig_hosts_list, |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
89 conn->dir->set->director_mail_servers); |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
90 |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
91 orig_hosts = array_get(mail_hosts_get(orig_hosts_list), |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
92 &orig_hosts_count); |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
93 cur_hosts = array_get(mail_hosts_get(conn->dir->mail_hosts), |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
94 &cur_hosts_count); |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
95 |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
96 /* the hosts are sorted by IP */ |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
97 for (i = j = 0; i < orig_hosts_count && j < cur_hosts_count; ) { |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
98 ret = net_ip_cmp(&orig_hosts[i]->ip, &cur_hosts[j]->ip); |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
99 if (ret == 0) |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
100 i++, j++; |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
101 else if (ret > 0) |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
102 j++; |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
103 else { |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
104 str_printfa(str, "%s\n", |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
105 net_ip2addr(&orig_hosts[i]->ip)); |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
106 i++; |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
107 } |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
108 } |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
109 for (; i < orig_hosts_count; i++) |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
110 str_printfa(str, "%s\n", net_ip2addr(&orig_hosts[i]->ip)); |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
111 str_append_c(str, '\n'); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
112 o_stream_nsend(conn->output, str_data(str), str_len(str)); |
12986
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
113 |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
114 mail_hosts_deinit(&orig_hosts_list); |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
115 } |
c838d40bd38e
doveadm: Added "director dump" command.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
116 |
18062
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
117 static void doveadm_director_append_status(struct director *dir, string_t *str) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
118 { |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
119 if (!dir->ring_handshaked) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
120 str_append(str, "handshaking"); |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
121 else if (dir->ring_synced) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
122 str_append(str, "synced"); |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
123 else { |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
124 str_printfa(str, "syncing - last sync %d secs ago", |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
125 (int)(ioloop_time - dir->ring_last_sync_time)); |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
126 } |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
127 } |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
128 |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
129 static void |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
130 doveadm_director_connection_append_status(struct director_connection *conn, |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
131 string_t *str) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
132 { |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
133 if (!director_connection_is_handshaked(conn)) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
134 str_append(str, "handshaking"); |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
135 else if (director_connection_is_synced(conn)) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
136 str_append(str, "synced"); |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
137 else |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
138 str_append(str, "syncing"); |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
139 } |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
140 |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
141 static void |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
142 doveadm_director_host_append_status(struct director *dir, |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
143 const struct director_host *host, |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
144 string_t *str) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
145 { |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
146 struct director_connection *conn = NULL; |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
147 |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
148 if (dir->left != NULL && |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
149 director_connection_get_host(dir->left) == host) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
150 conn = dir->left; |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
151 else if (dir->right != NULL && |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
152 director_connection_get_host(dir->right) == host) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
153 conn = dir->right; |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
154 else { |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
155 /* we might have a connection that is being connected */ |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
156 struct director_connection *const *connp; |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
157 |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
158 array_foreach(&dir->connections, connp) { |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
159 if (director_connection_get_host(*connp) == host) { |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
160 conn = *connp; |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
161 break; |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
162 } |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
163 } |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
164 } |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
165 |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
166 if (conn != NULL) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
167 doveadm_director_connection_append_status(conn, str); |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
168 } |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
169 |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 static void doveadm_cmd_director_list(struct doveadm_connection *conn) |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 { |
13320
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
172 struct director *dir = conn->dir; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 struct director_host *const *hostp; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 string_t *str = t_str_new(1024); |
13320
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
175 const char *type; |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
176 bool left, right; |
14432
366b9e5fc85c
director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents:
14292
diff
changeset
|
177 time_t last_failed; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 |
13320
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
179 array_foreach(&dir->dir_hosts, hostp) { |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
180 const struct director_host *host = *hostp; |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
181 |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
182 left = dir->left != NULL && |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
183 director_connection_get_host(dir->left) == host; |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
184 right = dir->right != NULL && |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
185 director_connection_get_host(dir->right) == host; |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
186 |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
187 if (host->removed) |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
188 type = "removed"; |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
189 else if (dir->self_host == host) |
13320
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
190 type = "self"; |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
191 else if (left) |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
192 type = right ? "l+r" : "left"; |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
193 else if (right) |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
194 type = "right"; |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
195 else |
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
196 type = ""; |
14432
366b9e5fc85c
director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents:
14292
diff
changeset
|
197 |
366b9e5fc85c
director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents:
14292
diff
changeset
|
198 last_failed = I_MAX(host->last_network_failure, |
366b9e5fc85c
director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents:
14292
diff
changeset
|
199 host->last_protocol_failure); |
18062
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
200 str_printfa(str, "%s\t%u\t%s\t%lu\t", |
13320
63680f6e21a2
director: Updated DIRECTOR-LIST doveadm command.
Timo Sirainen <tss@iki.fi>
parents:
13045
diff
changeset
|
201 net_ip2addr(&host->ip), host->port, type, |
14432
366b9e5fc85c
director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents:
14292
diff
changeset
|
202 (unsigned long)last_failed); |
18062
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
203 if (dir->self_host == host) |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
204 doveadm_director_append_status(dir, str); |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
205 else |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
206 doveadm_director_host_append_status(dir, host, str); |
ade6dcace5cd
doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents:
17725
diff
changeset
|
207 str_append_c(str, '\n'); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 str_append_c(str, '\n'); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
210 o_stream_nsend(conn->output, str_data(str), str_len(str)); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
213 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
214 doveadm_cmd_director_add(struct doveadm_connection *conn, |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
215 const char *const *args) |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
216 { |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
217 struct director_host *host; |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
218 struct ip_addr ip; |
19035
aabfe48db1cf
Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents:
18729
diff
changeset
|
219 in_port_t port = conn->dir->self_port; |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
220 |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
221 if (args[0] == NULL || |
20968
2a7e47e01509
director: Make sure IP address parsing works in DIRECTOR-ADD/REMOVE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20967
diff
changeset
|
222 net_addr2ip(args[0], &ip) < 0 || |
19035
aabfe48db1cf
Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents:
18729
diff
changeset
|
223 (args[1] != NULL && net_str2port(args[1], &port) < 0)) { |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
224 i_error("doveadm sent invalid DIRECTOR-ADD parameters"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
225 return -1; |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
226 } |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
227 |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
228 if (director_host_lookup(conn->dir, &ip, port) == NULL) { |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
229 host = director_host_add(conn->dir, &ip, port); |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
230 director_notify_ring_added(host, conn->dir->self_host); |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
231 } |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
232 o_stream_nsend(conn->output, "OK\n", 3); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
233 return 1; |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
234 } |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
235 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
236 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
237 doveadm_cmd_director_remove(struct doveadm_connection *conn, |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
238 const char *const *args) |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
239 { |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
240 struct director_host *host; |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
241 struct ip_addr ip; |
19035
aabfe48db1cf
Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents:
18729
diff
changeset
|
242 in_port_t port = 0; |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
243 |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
244 if (args[0] == NULL || |
20968
2a7e47e01509
director: Make sure IP address parsing works in DIRECTOR-ADD/REMOVE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20967
diff
changeset
|
245 net_addr2ip(args[0], &ip) < 0 || |
19035
aabfe48db1cf
Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents:
18729
diff
changeset
|
246 (args[1] != NULL && net_str2port(args[1], &port) < 0)) { |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
247 i_error("doveadm sent invalid DIRECTOR-REMOVE parameters"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
248 return -1; |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
249 } |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
250 |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
251 host = port != 0 ? |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
252 director_host_lookup(conn->dir, &ip, port) : |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
253 director_host_lookup_ip(conn->dir, &ip); |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
254 if (host == NULL) |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
255 o_stream_nsend_str(conn->output, "NOTFOUND\n"); |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
256 else { |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
257 director_ring_remove(host, conn->dir->self_host); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
258 o_stream_nsend(conn->output, "OK\n", 3); |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
259 } |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
260 return 1; |
14571
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
261 } |
42cca8a1d179
director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents:
14471
diff
changeset
|
262 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
263 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
264 doveadm_cmd_host_set_or_update(struct doveadm_connection *conn, |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
265 const char *const *args, bool update) |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 { |
11352
19336bddada2
director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents:
11351
diff
changeset
|
267 struct director *dir = conn->dir; |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
268 const char *ip_str, *tag = ""; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 struct mail_host *host; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 struct ip_addr ip; |
15904
d3cf06639864
Replaced all -1U and (unsigned int)-1 with UINT_MAX.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
271 unsigned int vhost_count = UINT_MAX; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 |
18067
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
273 ip_str = args[0]; |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
274 if (ip_str != NULL) { |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
275 tag = strchr(ip_str, '@'); |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
276 if (tag == NULL) |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
277 tag = ""; |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
278 else |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
279 ip_str = t_strdup_until(ip_str, tag++); |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
280 } |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
281 if (ip_str == NULL || net_addr2ip(ip_str, &ip) < 0 || |
19078
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
282 (args[1] != NULL && str_to_uint(args[1], &vhost_count) < 0) || |
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
283 (args[1] == NULL && update)) { |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
284 i_error("doveadm sent invalid %s parameters", |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
285 update ? "HOST-UPDATE" : "HOST-SET"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
286 return -1; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 } |
15904
d3cf06639864
Replaced all -1U and (unsigned int)-1 with UINT_MAX.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
288 if (vhost_count > MAX_VALID_VHOST_COUNT && vhost_count != UINT_MAX) { |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
289 o_stream_nsend_str(conn->output, "vhost count too large\n"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
290 return 1; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 } |
11352
19336bddada2
director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents:
11351
diff
changeset
|
292 host = mail_host_lookup(dir->mail_hosts, &ip); |
19078
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
293 if (host == NULL) { |
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
294 if (update) { |
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
295 o_stream_nsend_str(conn->output, "NOTFOUND\n"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
296 return 1; |
19078
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
297 } |
18067
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
298 host = mail_host_add_ip(dir->mail_hosts, &ip, tag); |
19497
1d2999cfe0a4
director: If doveadm attempts to change tag for an existing host, return error.
Timo Sirainen <tss@iki.fi>
parents:
19437
diff
changeset
|
299 } else if (tag[0] != '\0' && strcmp(mail_host_get_tag(host), tag) != 0) { |
1d2999cfe0a4
director: If doveadm attempts to change tag for an existing host, return error.
Timo Sirainen <tss@iki.fi>
parents:
19437
diff
changeset
|
300 o_stream_nsend_str(conn->output, "host tag can't be changed\n"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
301 return 1; |
19288
5939512ff017
director: Don't allow doveadm to update backend's state if the state is already being changed.
Timo Sirainen <tss@iki.fi>
parents:
19078
diff
changeset
|
302 } else if (host->desynced) { |
5939512ff017
director: Don't allow doveadm to update backend's state if the state is already being changed.
Timo Sirainen <tss@iki.fi>
parents:
19078
diff
changeset
|
303 o_stream_nsend_str(conn->output, |
5939512ff017
director: Don't allow doveadm to update backend's state if the state is already being changed.
Timo Sirainen <tss@iki.fi>
parents:
19078
diff
changeset
|
304 "host is already being updated - try again later\n"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
305 return 1; |
19078
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
306 } |
15904
d3cf06639864
Replaced all -1U and (unsigned int)-1 with UINT_MAX.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
307 if (vhost_count != UINT_MAX) |
19407
39cfca637d60
director: Code cleanup - make most mail_host_*() list parameters unnecessary.
Timo Sirainen <tss@iki.fi>
parents:
19288
diff
changeset
|
308 mail_host_set_vhost_count(host, vhost_count); |
19078
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
309 /* NOTE: we don't support changing a tag for an existing host. |
18067
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
310 it needs to be removed first. otherwise it would be a bit ugly to |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
311 handle. */ |
11629
a07aa85f68c9
director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents:
11585
diff
changeset
|
312 director_update_host(dir, dir->self_host, NULL, host); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
314 o_stream_nsend(conn->output, "OK\n", 3); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
315 return 1; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
318 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
319 doveadm_cmd_host_set(struct doveadm_connection *conn, const char *const *args) |
19078
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
320 { |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
321 return doveadm_cmd_host_set_or_update(conn, args, FALSE); |
19078
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
322 } |
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
323 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
324 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
325 doveadm_cmd_host_update(struct doveadm_connection *conn, const char *const *args) |
19078
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
326 { |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
327 return doveadm_cmd_host_set_or_update(conn, args, TRUE); |
19078
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
328 } |
7ac9ec913a39
doveadm director update command added.
Timo Sirainen <tss@iki.fi>
parents:
19035
diff
changeset
|
329 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
330 static int |
18729
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
331 doveadm_cmd_host_updown(struct doveadm_connection *conn, bool down, |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
332 const char *const *args) |
18729
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
333 { |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
334 struct mail_host *host; |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
335 struct ip_addr ip; |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
336 |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
337 if (args[0] == NULL || net_addr2ip(args[0], &ip) < 0) { |
18729
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
338 i_error("doveadm sent invalid %s parameters: %s", |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
339 down ? "HOST-DOWN" : "HOST-UP", |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
340 args[0] == NULL ? "" : args[0]); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
341 return -1; |
18729
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
342 } |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
343 host = mail_host_lookup(conn->dir->mail_hosts, &ip); |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
344 if (host == NULL) { |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
345 o_stream_nsend_str(conn->output, "NOTFOUND\n"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
346 return 1; |
18729
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
347 } |
19288
5939512ff017
director: Don't allow doveadm to update backend's state if the state is already being changed.
Timo Sirainen <tss@iki.fi>
parents:
19078
diff
changeset
|
348 if (host->down == down) |
5939512ff017
director: Don't allow doveadm to update backend's state if the state is already being changed.
Timo Sirainen <tss@iki.fi>
parents:
19078
diff
changeset
|
349 ; |
5939512ff017
director: Don't allow doveadm to update backend's state if the state is already being changed.
Timo Sirainen <tss@iki.fi>
parents:
19078
diff
changeset
|
350 else if (host->desynced) { |
5939512ff017
director: Don't allow doveadm to update backend's state if the state is already being changed.
Timo Sirainen <tss@iki.fi>
parents:
19078
diff
changeset
|
351 o_stream_nsend_str(conn->output, |
5939512ff017
director: Don't allow doveadm to update backend's state if the state is already being changed.
Timo Sirainen <tss@iki.fi>
parents:
19078
diff
changeset
|
352 "host is already being updated - try again later\n"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
353 return 1; |
19288
5939512ff017
director: Don't allow doveadm to update backend's state if the state is already being changed.
Timo Sirainen <tss@iki.fi>
parents:
19078
diff
changeset
|
354 } else { |
19407
39cfca637d60
director: Code cleanup - make most mail_host_*() list parameters unnecessary.
Timo Sirainen <tss@iki.fi>
parents:
19288
diff
changeset
|
355 mail_host_set_down(host, down, ioloop_time); |
18729
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
356 director_update_host(conn->dir, conn->dir->self_host, |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
357 NULL, host); |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
358 } |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
359 o_stream_nsend(conn->output, "OK\n", 3); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
360 return 1; |
18729
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
361 } |
0ee3e734249a
director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents:
18709
diff
changeset
|
362 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
363 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
364 doveadm_cmd_host_remove(struct doveadm_connection *conn, |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
365 const char *const *args) |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 { |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 struct mail_host *host; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 struct ip_addr ip; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
369 |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
370 if (args[0] == NULL || net_addr2ip(args[0], &ip) < 0) { |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
371 i_error("doveadm sent invalid HOST-REMOVE parameters"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
372 return -1; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 } |
11352
19336bddada2
director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents:
11351
diff
changeset
|
374 host = mail_host_lookup(conn->dir->mail_hosts, &ip); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 if (host == NULL) |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
376 o_stream_nsend_str(conn->output, "NOTFOUND\n"); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
377 else { |
11629
a07aa85f68c9
director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents:
11585
diff
changeset
|
378 director_remove_host(conn->dir, conn->dir->self_host, |
a07aa85f68c9
director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents:
11585
diff
changeset
|
379 NULL, host); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
380 o_stream_nsend(conn->output, "OK\n", 3); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 } |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
382 return 1; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
385 static void |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
386 doveadm_cmd_host_flush_all(struct doveadm_connection *conn) |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
387 { |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
388 struct mail_host *const *hostp; |
17725
bd381e882485
director: Log a warning when using "director host flush" for all hosts.
Timo Sirainen <tss@iki.fi>
parents:
17418
diff
changeset
|
389 unsigned int total_user_count = 0; |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
390 |
11629
a07aa85f68c9
director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents:
11585
diff
changeset
|
391 array_foreach(mail_hosts_get(conn->dir->mail_hosts), hostp) { |
17725
bd381e882485
director: Log a warning when using "director host flush" for all hosts.
Timo Sirainen <tss@iki.fi>
parents:
17418
diff
changeset
|
392 total_user_count += (*hostp)->user_count; |
11629
a07aa85f68c9
director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents:
11585
diff
changeset
|
393 director_flush_host(conn->dir, conn->dir->self_host, |
a07aa85f68c9
director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents:
11585
diff
changeset
|
394 NULL, *hostp); |
a07aa85f68c9
director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents:
11585
diff
changeset
|
395 } |
17725
bd381e882485
director: Log a warning when using "director host flush" for all hosts.
Timo Sirainen <tss@iki.fi>
parents:
17418
diff
changeset
|
396 i_warning("Flushed all backend hosts with %u users. This is an unsafe " |
bd381e882485
director: Log a warning when using "director host flush" for all hosts.
Timo Sirainen <tss@iki.fi>
parents:
17418
diff
changeset
|
397 "operation and may cause the same users to end up in multiple backends.", |
bd381e882485
director: Log a warning when using "director host flush" for all hosts.
Timo Sirainen <tss@iki.fi>
parents:
17418
diff
changeset
|
398 total_user_count); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
399 o_stream_nsend(conn->output, "OK\n", 3); |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
400 } |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
401 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
402 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
403 doveadm_cmd_host_flush(struct doveadm_connection *conn, const char *const *args) |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
404 { |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
405 struct mail_host *host; |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
406 struct ip_addr ip; |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
407 |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
408 if (args[0] == NULL || args[0][0] == '\0') { |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
409 doveadm_cmd_host_flush_all(conn); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
410 return 1; |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
411 } |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
412 |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
413 if (net_addr2ip(args[0], &ip) < 0) { |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
414 i_error("doveadm sent invalid HOST-FLUSH parameters"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
415 return -1; |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
416 } |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
417 host = mail_host_lookup(conn->dir->mail_hosts, &ip); |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
418 if (host == NULL) |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
419 o_stream_nsend_str(conn->output, "NOTFOUND\n"); |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
420 else { |
11629
a07aa85f68c9
director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents:
11585
diff
changeset
|
421 director_flush_host(conn->dir, conn->dir->self_host, |
a07aa85f68c9
director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents:
11585
diff
changeset
|
422 NULL, host); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
423 o_stream_nsend(conn->output, "OK\n", 3); |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
424 } |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
425 return 1; |
11355
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
426 } |
ef1de95396d4
Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents:
11353
diff
changeset
|
427 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
428 static void doveadm_reset_cmd_free(struct director_reset_cmd *cmd) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
429 { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
430 DLLIST_REMOVE(&reset_cmds, cmd); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
431 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
432 if (cmd->iter != NULL) |
21075
6a363cb51d7f
director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21074
diff
changeset
|
433 director_iterate_users_deinit(&cmd->iter); |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
434 if (cmd->_conn != NULL) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
435 cmd->_conn->reset_cmd = NULL; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
436 i_free(cmd); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
437 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
438 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
439 static bool |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
440 director_host_reset_users(struct director_reset_cmd *cmd, |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
441 struct mail_host *host) |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
442 { |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
443 struct director *dir = cmd->dir; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
444 struct user *user; |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
445 struct mail_host *new_host; |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
446 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
447 if (dir->users_moving_count >= cmd->max_moving_users) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
448 return FALSE; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
449 |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
450 if (dir->right != NULL) |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
451 director_connection_cork(dir->right); |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
452 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
453 if (cmd->iter == NULL) |
21075
6a363cb51d7f
director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21074
diff
changeset
|
454 cmd->iter = director_iterate_users_init(dir); |
21079
d6f399a7f672
director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21076
diff
changeset
|
455 |
21075
6a363cb51d7f
director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21074
diff
changeset
|
456 while ((user = director_iterate_users_next(cmd->iter)) != NULL) { |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
457 if (user->host != host) |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
458 continue; |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
459 new_host = mail_host_get_by_hash(dir->mail_hosts, |
19408
7e47f561ad49
director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents:
19407
diff
changeset
|
460 user->username_hash, |
7e47f561ad49
director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents:
19407
diff
changeset
|
461 mail_host_get_tag(host)); |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
462 if (new_host != host) T_BEGIN { |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
463 director_move_user(dir, dir->self_host, NULL, |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
464 user->username_hash, new_host); |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
465 } T_END; |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
466 if (dir->users_moving_count >= cmd->max_moving_users) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
467 break; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
468 } |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
469 if (user == NULL) |
21075
6a363cb51d7f
director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21074
diff
changeset
|
470 director_iterate_users_deinit(&cmd->iter); |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
471 if (dir->right != NULL) |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
472 director_connection_uncork(dir->right); |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
473 return user == NULL; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
474 } |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
475 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
476 static bool |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
477 director_reset_cmd_run(struct director_reset_cmd *cmd) |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
478 { |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
479 struct mail_host *const *hosts; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
480 unsigned int count; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
481 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
482 hosts = array_get(mail_hosts_get(cmd->dir->mail_hosts), &count); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
483 if (count > cmd->hosts_count) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
484 count = cmd->hosts_count; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
485 while (cmd->host_idx < count) { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
486 if (!director_host_reset_users(cmd, hosts[cmd->host_idx])) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
487 return FALSE; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
488 cmd->host_idx++; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
489 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
490 if (cmd->_conn != NULL) { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
491 struct doveadm_connection *conn = cmd->_conn; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
492 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
493 o_stream_nsend(conn->output, "OK\n", 3); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
494 if (conn->io == NULL) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
495 doveadm_connection_set_io(conn); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
496 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
497 doveadm_reset_cmd_free(cmd); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
498 return TRUE; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
499 } |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
500 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
501 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
502 doveadm_cmd_host_reset_users(struct doveadm_connection *conn, |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
503 const char *const *args) |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
504 { |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
505 struct director_reset_cmd *cmd; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
506 struct ip_addr ip; |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
507 struct mail_host *const *hosts; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
508 unsigned int i = 0, count; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
509 unsigned int max_moving_users = DEFAULT_MAX_MOVING_USERS; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
510 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
511 if (args[0] != NULL && args[1] != NULL && |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
512 str_to_uint(args[1], &max_moving_users) < 0) { |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
513 i_error("doveadm sent invalid HOST-RESET-USERS parameters"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
514 return -1; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
515 } |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
516 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
517 hosts = array_get(mail_hosts_get(conn->dir->mail_hosts), &count); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
518 if (args[0] != NULL && args[0][0] != '\0') { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
519 if (net_addr2ip(args[0], &ip) < 0) { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
520 i_error("doveadm sent invalid HOST-RESET-USERS ip: %s", |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
521 args[0]); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
522 return -1; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
523 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
524 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
525 for (i = 0; i < count; i++) { |
20984
d3f2fc420d2b
director: Fix HOST-RESET-USERS with host parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20976
diff
changeset
|
526 if (net_ip_compare(&hosts[i]->ip, &ip)) |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
527 break; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
528 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
529 if (i == count) { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
530 o_stream_nsend_str(conn->output, "NOTFOUND\n"); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
531 return 1; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
532 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
533 count = i+1; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
534 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
535 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
536 conn->reset_cmd = cmd = i_new(struct director_reset_cmd, 1); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
537 cmd->dir = conn->dir; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
538 cmd->_conn = conn; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
539 cmd->max_moving_users = max_moving_users; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
540 cmd->host_idx = i; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
541 cmd->hosts_count = count; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
542 DLLIST_PREPEND(&reset_cmds, cmd); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
543 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
544 if (!director_reset_cmd_run(cmd)) { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
545 /* we still have work to do. don't handle any more doveadm |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
546 input until we're finished. */ |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
547 io_remove(&conn->io); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
548 return 0; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
549 } |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
550 return 1; |
18709
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
551 } |
618c8d76bc5d
director: Added HOST-RESET-USERS command to move users to their hash-assigned hosts.
Timo Sirainen <tss@iki.fi>
parents:
18541
diff
changeset
|
552 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
553 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
554 doveadm_cmd_user_lookup(struct doveadm_connection *conn, |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
555 const char *const *args) |
11351
c57c1ff9c5f1
doveadm director status username now returns which server the user is assigned to.
Timo Sirainen <tss@iki.fi>
parents:
11322
diff
changeset
|
556 { |
c57c1ff9c5f1
doveadm director status username now returns which server the user is assigned to.
Timo Sirainen <tss@iki.fi>
parents:
11322
diff
changeset
|
557 struct user *user; |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
558 struct mail_host *host; |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
559 const char *username, *tag; |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
560 unsigned int username_hash; |
21079
d6f399a7f672
director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21076
diff
changeset
|
561 struct mail_tag *mail_tag; |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
562 string_t *str = t_str_new(256); |
11351
c57c1ff9c5f1
doveadm director status username now returns which server the user is assigned to.
Timo Sirainen <tss@iki.fi>
parents:
11322
diff
changeset
|
563 |
18067
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
564 if (args[0] == NULL) { |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
565 username = ""; |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
566 tag = ""; |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
567 } else { |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
568 username = args[0]; |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
569 tag = args[1] != NULL ? args[1] : ""; |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
570 } |
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
571 if (str_to_uint(username, &username_hash) < 0) |
21076
ef9d8f4c6c67
director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21075
diff
changeset
|
572 username_hash = director_get_username_hash(conn->dir, username); |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
573 |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
574 /* get user's current host */ |
21079
d6f399a7f672
director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21076
diff
changeset
|
575 mail_tag = mail_tag_find(conn->dir->mail_hosts, tag); |
d6f399a7f672
director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21076
diff
changeset
|
576 user = mail_tag == NULL ? NULL : |
d6f399a7f672
director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21076
diff
changeset
|
577 user_directory_lookup(mail_tag->users, username_hash); |
11351
c57c1ff9c5f1
doveadm director status username now returns which server the user is assigned to.
Timo Sirainen <tss@iki.fi>
parents:
11322
diff
changeset
|
578 if (user == NULL) |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
579 str_append(str, "\t0"); |
11351
c57c1ff9c5f1
doveadm director status username now returns which server the user is assigned to.
Timo Sirainen <tss@iki.fi>
parents:
11322
diff
changeset
|
580 else { |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
581 str_printfa(str, "%s\t%u", net_ip2addr(&user->host->ip), |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
582 user->timestamp + |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
583 conn->dir->set->director_user_expire); |
11351
c57c1ff9c5f1
doveadm director status username now returns which server the user is assigned to.
Timo Sirainen <tss@iki.fi>
parents:
11322
diff
changeset
|
584 } |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
585 |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
586 /* get host if it wasn't in user directory */ |
18067
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
587 host = mail_host_get_by_hash(conn->dir->mail_hosts, username_hash, tag); |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
588 if (host == NULL) |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
589 str_append(str, "\t"); |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
590 else |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
591 str_printfa(str, "\t%s", net_ip2addr(&host->ip)); |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
592 |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
593 /* get host with default configuration */ |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
594 host = mail_host_get_by_hash(conn->dir->orig_config_hosts, |
18067
a7e830b9b967
director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents:
18065
diff
changeset
|
595 username_hash, tag); |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
596 if (host == NULL) |
19437
ac30316bed82
director: Fixed "doveadm director status user@domain" not to hang due to missing LF.
Timo Sirainen <tss@iki.fi>
parents:
19408
diff
changeset
|
597 str_append(str, "\t\n"); |
11353
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
598 else |
1bc3d5589c5a
doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents:
11352
diff
changeset
|
599 str_printfa(str, "\t%s\n", net_ip2addr(&host->ip)); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
600 o_stream_nsend(conn->output, str_data(str), str_len(str)); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
601 return 1; |
11351
c57c1ff9c5f1
doveadm director status username now returns which server the user is assigned to.
Timo Sirainen <tss@iki.fi>
parents:
11322
diff
changeset
|
602 } |
c57c1ff9c5f1
doveadm director status username now returns which server the user is assigned to.
Timo Sirainen <tss@iki.fi>
parents:
11322
diff
changeset
|
603 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
604 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
605 doveadm_cmd_user_list(struct doveadm_connection *conn, const char *const *args) |
11823
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
606 { |
21075
6a363cb51d7f
director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21074
diff
changeset
|
607 struct director_user_iter *iter; |
11823
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
608 struct user *user; |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
609 struct ip_addr ip; |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
610 |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
611 if (args[0] != NULL && args[0][0] != '\0') { |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
612 if (net_addr2ip(args[0], &ip) < 0) { |
11823
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
613 i_error("doveadm sent invalid USER-LIST parameters"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
614 return -1; |
11823
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
615 } |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
616 } else { |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
617 ip.family = 0; |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
618 } |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
619 |
21075
6a363cb51d7f
director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21074
diff
changeset
|
620 iter = director_iterate_users_init(conn->dir); |
6a363cb51d7f
director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21074
diff
changeset
|
621 while ((user = director_iterate_users_next(iter)) != NULL) { |
11823
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
622 if (ip.family == 0 || |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
623 net_ip_compare(&ip, &user->host->ip)) T_BEGIN { |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
624 unsigned int expire_time = user->timestamp + |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
625 conn->dir->set->director_user_expire; |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
626 |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
627 o_stream_nsend_str(conn->output, t_strdup_printf( |
11823
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
628 "%u\t%u\t%s\n", |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
629 user->username_hash, expire_time, |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
630 net_ip2addr(&user->host->ip))); |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
631 } T_END; |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
632 } |
21075
6a363cb51d7f
director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21074
diff
changeset
|
633 director_iterate_users_deinit(&iter); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
634 o_stream_nsend(conn->output, "\n", 1); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
635 return 1; |
11823
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
636 } |
4138737f41e6
doveadm: Added "director map" command to list user -> host mappings.
Timo Sirainen <tss@iki.fi>
parents:
11629
diff
changeset
|
637 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
638 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
639 doveadm_cmd_user_move(struct doveadm_connection *conn, const char *const *args) |
13045
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
640 { |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
641 unsigned int username_hash; |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
642 struct user *user; |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
643 struct mail_host *host; |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
644 struct ip_addr ip; |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
645 |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
646 if (args[0] == NULL || args[1] == NULL || |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
647 net_addr2ip(args[1], &ip) < 0) { |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
648 i_error("doveadm sent invalid USER-MOVE parameters"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
649 return -1; |
13045
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
650 } |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
651 host = mail_host_lookup(conn->dir->mail_hosts, &ip); |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
652 if (host == NULL) { |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
653 o_stream_nsend_str(conn->output, "NOTFOUND\n"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
654 return 1; |
13045
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
655 } |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
656 |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
657 if (str_to_uint(args[0], &username_hash) < 0) |
21076
ef9d8f4c6c67
director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21075
diff
changeset
|
658 username_hash = director_get_username_hash(conn->dir, args[0]); |
21079
d6f399a7f672
director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21076
diff
changeset
|
659 user = user_directory_lookup(host->tag->users, username_hash); |
20986
410eacd7ad40
director: Code cleanup - added USER_IS_BEING_KILLED() macro
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20984
diff
changeset
|
660 if (user != NULL && USER_IS_BEING_KILLED(user)) { |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
661 o_stream_nsend_str(conn->output, "TRYAGAIN\n"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
662 return 1; |
13045
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
663 } |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
664 |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
665 director_move_user(conn->dir, conn->dir->self_host, NULL, |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
666 username_hash, host); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
667 o_stream_nsend(conn->output, "OK\n", 3); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
668 return 1; |
13045
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
669 } |
79f9dce5d5fd
director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents:
12986
diff
changeset
|
670 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
671 static int |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
672 doveadm_cmd_user_kick(struct doveadm_connection *conn, const char *const *args) |
17418
64808a9703db
doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
673 { |
64808a9703db
doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
674 if (args[0] == NULL) { |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
675 i_error("doveadm sent invalid USER-KICK parameters"); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
676 return -1; |
17418
64808a9703db
doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
677 } |
64808a9703db
doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
678 |
64808a9703db
doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
679 director_kick_user(conn->dir, conn->dir->self_host, NULL, args[0]); |
64808a9703db
doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
680 o_stream_nsend(conn->output, "OK\n", 3); |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
681 return 1; |
17418
64808a9703db
doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
682 } |
64808a9703db
doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
683 |
20967
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
684 static int |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
685 doveadm_connection_cmd(struct doveadm_connection *conn, const char *line) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
686 { |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
687 const char *cmd, *const *args; |
20967
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
688 int ret = 1; |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
689 |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
690 args = t_strsplit_tabescaped(line); |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
691 if (args[0] == NULL) { |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
692 i_error("doveadm sent empty command line"); |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
693 return -1; |
20967
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
694 } |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
695 cmd = args[0]; |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
696 args++; |
20967
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
697 |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
698 if (strcmp(cmd, "HOST-LIST") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
699 doveadm_cmd_host_list(conn); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
700 else if (strcmp(cmd, "HOST-LIST-REMOVED") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
701 doveadm_cmd_host_list_removed(conn); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
702 else if (strcmp(cmd, "DIRECTOR-LIST") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
703 doveadm_cmd_director_list(conn); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
704 else if (strcmp(cmd, "DIRECTOR-ADD") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
705 ret = doveadm_cmd_director_add(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
706 else if (strcmp(cmd, "DIRECTOR-REMOVE") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
707 ret = doveadm_cmd_director_remove(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
708 else if (strcmp(cmd, "HOST-SET") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
709 ret = doveadm_cmd_host_set(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
710 else if (strcmp(cmd, "HOST-UPDATE") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
711 ret = doveadm_cmd_host_update(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
712 else if (strcmp(cmd, "HOST-UP") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
713 ret = doveadm_cmd_host_updown(conn, FALSE, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
714 else if (strcmp(cmd, "HOST-DOWN") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
715 ret = doveadm_cmd_host_updown(conn, TRUE, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
716 else if (strcmp(cmd, "HOST-REMOVE") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
717 ret = doveadm_cmd_host_remove(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
718 else if (strcmp(cmd, "HOST-FLUSH") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
719 ret = doveadm_cmd_host_flush(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
720 else if (strcmp(cmd, "HOST-RESET-USERS") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
721 ret = doveadm_cmd_host_reset_users(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
722 else if (strcmp(cmd, "USER-LOOKUP") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
723 ret = doveadm_cmd_user_lookup(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
724 else if (strcmp(cmd, "USER-LIST") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
725 ret = doveadm_cmd_user_list(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
726 else if (strcmp(cmd, "USER-MOVE") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
727 ret = doveadm_cmd_user_move(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
728 else if (strcmp(cmd, "USER-KICK") == 0) |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
729 ret = doveadm_cmd_user_kick(conn, args); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
730 else { |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
731 i_error("doveadm sent unknown command: %s", line); |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
732 ret = -1; |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
733 } |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
734 return ret; |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
735 } |
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
736 |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
737 static void doveadm_connection_input(struct doveadm_connection *conn) |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
738 { |
20967
1be6845a989b
director: Code cleanup - moved command handling to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20963
diff
changeset
|
739 const char *line; |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
740 int ret = 1; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
741 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
742 if (!conn->handshaked) { |
11894
06a7435b6f53
director: If doveadm connection disconnects before handshake, don't loop forever.
Timo Sirainen <tss@iki.fi>
parents:
11823
diff
changeset
|
743 if ((line = i_stream_read_next_line(conn->input)) == NULL) { |
06a7435b6f53
director: If doveadm connection disconnects before handshake, don't loop forever.
Timo Sirainen <tss@iki.fi>
parents:
11823
diff
changeset
|
744 if (conn->input->eof || conn->input->stream_errno != 0) |
06a7435b6f53
director: If doveadm connection disconnects before handshake, don't loop forever.
Timo Sirainen <tss@iki.fi>
parents:
11823
diff
changeset
|
745 doveadm_connection_deinit(&conn); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
746 return; |
11894
06a7435b6f53
director: If doveadm connection disconnects before handshake, don't loop forever.
Timo Sirainen <tss@iki.fi>
parents:
11823
diff
changeset
|
747 } |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
748 |
11458
4274d1549fa0
Added version_string_verify() and removed code duplication with it.
Timo Sirainen <tss@iki.fi>
parents:
11373
diff
changeset
|
749 if (!version_string_verify(line, "director-doveadm", |
4274d1549fa0
Added version_string_verify() and removed code duplication with it.
Timo Sirainen <tss@iki.fi>
parents:
11373
diff
changeset
|
750 DOVEADM_PROTOCOL_VERSION_MAJOR)) { |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
751 i_error("doveadm not compatible with this server " |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
752 "(mixed old and new binaries?)"); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
753 doveadm_connection_deinit(&conn); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
754 return; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
755 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
756 conn->handshaked = TRUE; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
757 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
758 |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
759 while ((line = i_stream_read_next_line(conn->input)) != NULL && ret > 0) { |
20970
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
760 T_BEGIN { |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
761 ret = doveadm_connection_cmd(conn, line); |
d653bcdff8a2
director: Code cleanup - Give tab-unescaped args to all doveadm command handlers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20969
diff
changeset
|
762 } T_END; |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
763 } |
20963
076b552163d2
director: Code cleanup - allow commands handlers to stop processing input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
764 if (conn->input->eof || conn->input->stream_errno != 0 || ret < 0) |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
765 doveadm_connection_deinit(&conn); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
766 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
767 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
768 static void doveadm_connection_set_io(struct doveadm_connection *conn) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
769 { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
770 conn->io = io_add(conn->fd, IO_READ, doveadm_connection_input, conn); |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
771 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
772 |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
773 struct doveadm_connection * |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
774 doveadm_connection_init(struct director *dir, int fd) |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
775 { |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
776 struct doveadm_connection *conn; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
777 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
778 conn = i_new(struct doveadm_connection, 1); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
779 conn->fd = fd; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
780 conn->dir = dir; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
781 conn->input = i_stream_create_fd(conn->fd, 1024, FALSE); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
782 conn->output = o_stream_create_fd(conn->fd, (size_t)-1, FALSE); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
783 o_stream_set_no_error_handling(conn->output, TRUE); |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
784 doveadm_connection_set_io(conn); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14571
diff
changeset
|
785 o_stream_nsend_str(conn->output, DOVEADM_HANDSHAKE); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
786 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
787 DLLIST_PREPEND(&doveadm_connections, conn); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
788 return conn; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
789 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
790 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
791 static void doveadm_connection_deinit(struct doveadm_connection **_conn) |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
792 { |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
793 struct doveadm_connection *conn = *_conn; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
794 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
795 *_conn = NULL; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
796 |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
797 if (conn->reset_cmd != NULL) { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
798 /* finish the move even if doveadm disconnected */ |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
799 conn->reset_cmd->_conn = NULL; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
800 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
801 |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
802 DLLIST_REMOVE(&doveadm_connections, conn); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
803 io_remove(&conn->io); |
11322 | 804 i_stream_unref(&conn->input); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
805 o_stream_unref(&conn->output); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
806 if (close(conn->fd) < 0) |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
807 i_error("close(doveadm connection) failed: %m"); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
808 i_free(conn); |
11373
26cfc1c3a4b1
director: Update connection count when client disconnects.
Timo Sirainen <tss@iki.fi>
parents:
11355
diff
changeset
|
809 |
26cfc1c3a4b1
director: Update connection count when client disconnects.
Timo Sirainen <tss@iki.fi>
parents:
11355
diff
changeset
|
810 master_service_client_connection_destroyed(master_service); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
811 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
812 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
813 void doveadm_connections_deinit(void) |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
814 { |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
815 while (reset_cmds != NULL) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
816 doveadm_reset_cmd_free(reset_cmds); |
11321
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
817 while (doveadm_connections != NULL) { |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
818 struct doveadm_connection *conn = doveadm_connections; |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
819 |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
820 doveadm_connection_deinit(&conn); |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
821 } |
5f350b5ff6d9
Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
822 } |
20976
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
823 |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
824 void doveadm_connections_continue_reset_cmds(void) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
825 { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
826 while (reset_cmds != NULL) { |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
827 if (!director_reset_cmd_run(reset_cmds)) |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
828 break; |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
829 } |
39d96d2dad95
director: HOST-RESET-USERS moves users more slowly now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20970
diff
changeset
|
830 } |