|
9 | 9 | #ifdef HAVE_SYS_SYSCALL_H |
10 | 10 | #include <sys/syscall.h> |
11 | 11 | #endif |
12 | | - |
13 | 12 | extern int am_server; |
14 | 13 | extern int am_daemon; |
15 | 14 |
|
16 | 15 | #define PRIORITY_UNSET (-100) |
17 | 16 | #define DEFAULT_NICE 19 |
18 | 17 |
|
19 | | -#if defined HAVE_GETPRIORITY && defined HAVE_SYS_RESOURCE_H |
20 | | -#define SUPPORT_GET_PRIORITY 1 |
21 | | -#endif |
22 | | - |
23 | | -#if defined SUPPORT_GET_PRIORITY && defined HAVE_SETPRIORITY |
| 18 | +#if defined HAVE_SETPRIORITY && defined HAVE_SYS_RESOURCE_H |
24 | 19 | #define SUPPORT_NICE_PRIORITY 1 |
25 | 20 | #endif |
26 | 21 |
|
27 | 22 | #if defined HAVE_LINUX_IOPRIO_H && defined HAVE_SYS_SYSCALL_H \ |
28 | | - && defined SUPPORT_GET_PRIORITY \ |
29 | | - && defined SYS_ioprio_get && defined SYS_ioprio_set \ |
30 | | - && defined IOPRIO_PRIO_CLASS \ |
31 | | - && defined IOPRIO_PRIO_DATA && defined IOPRIO_PRIO_VALUE |
| 23 | + && defined SYS_ioprio_set && defined IOPRIO_PRIO_VALUE |
32 | 24 | #define SUPPORT_IO_PRIORITY 1 |
33 | 25 | #endif |
34 | 26 |
|
35 | | -#ifdef SUPPORT_IO_PRIORITY |
36 | | -#ifdef IOPRIO_PRIO_LEVEL |
37 | | -#define RSYNC_IOPRIO_LEVEL(value) IOPRIO_PRIO_LEVEL(value) |
38 | | -#else |
39 | | -/* Older headers expose the whole data field; the level is its low 3 bits. */ |
40 | | -#define RSYNC_IOPRIO_LEVEL(value) (IOPRIO_PRIO_DATA(value) & 7) |
41 | | -#endif |
42 | | -#endif |
43 | | - |
44 | 27 | enum io_priority_class { |
45 | 28 | IO_PRIORITY_NONE, |
46 | 29 | IO_PRIORITY_REALTIME, |
@@ -266,120 +249,21 @@ char *niceness_remote_option(void) |
266 | 249 | return arg; |
267 | 250 | } |
268 | 251 |
|
269 | | -#ifdef SUPPORT_IO_PRIORITY |
270 | | -static int effective_io_priority(int class, int data, int cpu, int *rank_p, int *data_p) |
271 | | -{ |
272 | | - if (class == IOPRIO_CLASS_NONE) { |
273 | | - class = IOPRIO_CLASS_BE; |
274 | | - data = (cpu + 20) / 5; |
275 | | - if (data > 7) |
276 | | - data = 7; |
277 | | - } |
278 | | - |
279 | | - switch (class) { |
280 | | - case IOPRIO_CLASS_RT: |
281 | | - *rank_p = 0; |
282 | | - break; |
283 | | - case IOPRIO_CLASS_BE: |
284 | | - *rank_p = 1; |
285 | | - break; |
286 | | - case IOPRIO_CLASS_IDLE: |
287 | | - *rank_p = 2; |
288 | | - data = 0; |
289 | | - break; |
290 | | - default: |
291 | | - return 0; |
292 | | - } |
293 | | - *data_p = data; |
294 | | - return 1; |
295 | | -} |
296 | | - |
297 | | -static int requested_io_priority(const struct priority_setting *setting, int cpu, |
298 | | - int *rank_p, int *data_p) |
299 | | -{ |
300 | | - int class; |
301 | | - |
302 | | - switch (setting->io_class) { |
303 | | - case IO_PRIORITY_NONE: |
304 | | - class = IOPRIO_CLASS_NONE; |
305 | | - break; |
306 | | - case IO_PRIORITY_REALTIME: |
307 | | - class = IOPRIO_CLASS_RT; |
308 | | - break; |
309 | | - case IO_PRIORITY_BEST_EFFORT: |
310 | | - class = IOPRIO_CLASS_BE; |
311 | | - break; |
312 | | - case IO_PRIORITY_IDLE: |
313 | | - class = IOPRIO_CLASS_IDLE; |
314 | | - break; |
315 | | - default: |
316 | | - return 0; |
317 | | - } |
318 | | - return effective_io_priority(class, setting->io_data, cpu, rank_p, data_p); |
319 | | -} |
320 | | -#endif |
321 | | - |
322 | 252 | int niceness_check_daemon_request(char *err_buf, size_t err_len) |
323 | 253 | { |
324 | 254 | struct priority_setting *setting = &priorities.local; |
325 | 255 |
|
326 | | - if (setting->cpu == PRIORITY_UNSET && setting->io_class == PRIORITY_UNSET) |
327 | | - return 1; |
328 | | - |
329 | | -#if defined SUPPORT_NICE_PRIORITY || defined SUPPORT_IO_PRIORITY |
330 | | - int current_cpu; |
331 | | - |
332 | | - errno = 0; |
333 | | - current_cpu = getpriority(PRIO_PROCESS, 0); |
334 | | - if (errno) { |
335 | | - snprintf(err_buf, err_len, "cannot inspect daemon process priority: %s\n", |
336 | | - strerror(errno)); |
| 256 | + if (setting->cpu != PRIORITY_UNSET && setting->cpu != DEFAULT_NICE) { |
| 257 | + snprintf(err_buf, err_len, |
| 258 | + "daemon clients may only request CPU nice 19\n"); |
337 | 259 | return 0; |
338 | 260 | } |
339 | | -#endif |
340 | | - |
341 | | -#ifdef SUPPORT_NICE_PRIORITY |
342 | | - if (setting->cpu != PRIORITY_UNSET && setting->cpu < current_cpu) { |
343 | | - snprintf(err_buf, err_len, "--nice cannot raise daemon CPU priority\n"); |
| 261 | + if (setting->io_class != PRIORITY_UNSET |
| 262 | + && setting->io_class != IO_PRIORITY_IDLE) { |
| 263 | + snprintf(err_buf, err_len, |
| 264 | + "daemon clients may only request idle I/O priority\n"); |
344 | 265 | return 0; |
345 | 266 | } |
346 | | -#endif |
347 | | - |
348 | | -#ifdef SUPPORT_IO_PRIORITY |
349 | | - if (setting->io_class != PRIORITY_UNSET) { |
350 | | - int raw = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, 0); |
351 | | - int requested_cpu = current_cpu; |
352 | | - int current_rank, current_data, requested_rank, requested_data; |
353 | | - |
354 | | - if (raw < 0) { |
355 | | - snprintf(err_buf, err_len, "cannot inspect daemon I/O priority: %s\n", |
356 | | - strerror(errno)); |
357 | | - return 0; |
358 | | - } |
359 | | -#ifdef SUPPORT_NICE_PRIORITY |
360 | | - if (setting->cpu != PRIORITY_UNSET) |
361 | | - requested_cpu = setting->cpu; |
362 | | -#endif |
363 | | - /* IOPRIO_CLASS_NONE derives its level from CPU nice. */ |
364 | | - if (!effective_io_priority(IOPRIO_PRIO_CLASS(raw), RSYNC_IOPRIO_LEVEL(raw), |
365 | | - current_cpu, ¤t_rank, ¤t_data) |
366 | | - || !requested_io_priority(setting, requested_cpu, |
367 | | - &requested_rank, &requested_data)) { |
368 | | - snprintf(err_buf, err_len, "unsupported daemon I/O priority class\n"); |
369 | | - return 0; |
370 | | - } |
371 | | - if (requested_rank < current_rank |
372 | | - || (requested_rank == current_rank && requested_data < current_data)) { |
373 | | - snprintf(err_buf, err_len, "--nice cannot raise daemon I/O priority\n"); |
374 | | - return 0; |
375 | | - } |
376 | | - } |
377 | | -#endif |
378 | | - |
379 | | -#if !defined SUPPORT_NICE_PRIORITY && !defined SUPPORT_IO_PRIORITY |
380 | | - (void)err_buf; |
381 | | - (void)err_len; |
382 | | -#endif |
383 | 267 |
|
384 | 268 | return 1; |
385 | 269 | } |
|
0 commit comments