-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
glusterfsd.c
2974 lines (2503 loc) · 90.3 KB
/
glusterfsd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2006-2016 Red Hat, Inc. <http://www.redhat.com>
This file is part of GlusterFS.
This file is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3 or
later), or the GNU General Public License, version 2 (GPLv2), in all
cases as published by the Free Software Foundation.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <dlfcn.h>
#include <pthread.h>
#include <errno.h>
#include <pwd.h>
#ifdef GF_LINUX_HOST_OS
#ifdef HAVE_LINUX_OOM_H
#include <linux/oom.h>
#else
#define OOM_SCORE_ADJ_MIN (-1000)
#define OOM_SCORE_ADJ_MAX 1000
#define OOM_DISABLE (-17)
#define OOM_ADJUST_MAX 15
#endif
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <glusterfs/compat.h>
#include <glusterfs/logging.h>
#include "glusterfsd-messages.h"
#include <glusterfs/dict.h>
#include <glusterfs/list.h>
#include <glusterfs/timer.h>
#include <glusterfs/revision.h>
#include <glusterfs/gf-event.h>
#include <glusterfs/statedump.h>
#include <glusterfs/latency.h>
#include "glusterfsd-mem-types.h"
#include <glusterfs/syscall.h>
#include <glusterfs/syncop.h>
#include <glusterfs/client_t.h>
#include <glusterfs/monitoring.h>
#include <glusterfs/gf-io.h>
#include <glusterfs/daemon.h>
#include "glusterfsd.h"
#include "rpc-clnt.h"
#include "netgroups.h"
#include "exports.h"
/* using argp for command line parsing */
static char gf_doc[] = "";
static char argp_doc[] =
"--volfile-server=SERVER [MOUNT-POINT]\n"
"--volfile=VOLFILE [MOUNT-POINT]";
const char *argp_program_version =
"" PACKAGE_NAME " " PACKAGE_VERSION
"\nRepository revision: " GLUSTERFS_REPOSITORY_REVISION
"\n"
"Copyright (c) 2006-2016 Red Hat, Inc. "
"<https://www.gluster.org/>\n"
"GlusterFS comes with ABSOLUTELY NO WARRANTY.\n"
"It is licensed to you under your choice of the GNU Lesser\n"
"General Public License, version 3 or any later version (LGPLv3\n"
"or later), or the GNU General Public License, version 2 (GPLv2),\n"
"in all cases as published by the Free Software Foundation.";
const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
static error_t
parse_opts(int32_t key, char *arg, struct argp_state *_state);
static struct argp_option gf_options[] = {
{0, 0, 0, 0, "Basic options:"},
{"volfile-server", ARGP_VOLFILE_SERVER_KEY, "SERVER", 0,
"Server to get the volume file from. Unix domain socket path when "
"transport type 'unix'. This option overrides --volfile option"},
{"volfile", ARGP_VOLUME_FILE_KEY, "VOLFILE", 0,
"File to use as VOLUME_FILE"},
{"spec-file", ARGP_VOLUME_FILE_KEY, "VOLFILE", OPTION_HIDDEN,
"File to use as VOLUME FILE"},
{"log-level", ARGP_LOG_LEVEL_KEY, "LOGLEVEL", 0,
"Logging severity. Valid options are DEBUG, INFO, WARNING, ERROR, "
"CRITICAL, TRACE and NONE [default: INFO]"},
{"log-file", ARGP_LOG_FILE_KEY, "LOGFILE", 0,
"File to use for logging [default: " DEFAULT_LOG_FILE_DIRECTORY
"/" PACKAGE_NAME ".log"
"]"},
{"logger", ARGP_LOGGER, "LOGGER", 0,
"Set which logging sub-system to "
"log to, valid options are: gluster-log and syslog, "
"[default: \"gluster-log\"]"},
{"log-format", ARGP_LOG_FORMAT, "LOG-FORMAT", 0,
"Set log format, valid"
" options are: no-msg-id and with-msg-id, [default: \"with-msg-id\"]"},
{"log-buf-size", ARGP_LOG_BUF_SIZE, "LOG-BUF-SIZE", 0,
"Set logging "
"buffer size, [default: 5]"},
{"log-flush-timeout", ARGP_LOG_FLUSH_TIMEOUT, "LOG-FLUSH-TIMEOUT", 0,
"Set log flush timeout, [default: 2 minutes]"},
{0, 0, 0, 0, "Advanced Options:"},
{"volfile-server-port", ARGP_VOLFILE_SERVER_PORT_KEY, "PORT", 0,
"Listening port number of volfile server"},
{"volfile-server-transport", ARGP_VOLFILE_SERVER_TRANSPORT_KEY, "TRANSPORT",
0, "Transport type to get volfile from server [default: socket]"},
{"volfile-id", ARGP_VOLFILE_ID_KEY, "KEY", 0,
"'key' of the volfile to be fetched from server"},
{"pid-file", ARGP_PID_FILE_KEY, "PIDFILE", 0, "File to use as pid file"},
{"socket-file", ARGP_SOCK_FILE_KEY, "SOCKFILE", 0,
"File to use as unix-socket"},
{"no-daemon", ARGP_NO_DAEMON_KEY, 0, 0, "Run in foreground"},
{"run-id", ARGP_RUN_ID_KEY, "RUN-ID", OPTION_HIDDEN,
"Run ID for the process, used by scripts to keep track of process "
"they started, defaults to none"},
{"debug", ARGP_DEBUG_KEY, 0, 0,
"Run in debug mode. This option sets --no-daemon, --log-level "
"to DEBUG and --log-file to console"},
{"volume-name", ARGP_VOLUME_NAME_KEY, "XLATOR-NAME", 0,
"Translator name to be used for MOUNT-POINT [default: top most volume "
"definition in VOLFILE]"},
{"xlator-option", ARGP_XLATOR_OPTION_KEY, "XLATOR-NAME.OPTION=VALUE", 0,
"Add/override an option for a translator in volume file with specified"
" value"},
{"read-only", ARGP_READ_ONLY_KEY, 0, 0,
"Mount the filesystem in 'read-only' mode"},
{"acl", ARGP_ACL_KEY, 0, 0, "Mount the filesystem with POSIX ACL support"},
{"selinux", ARGP_SELINUX_KEY, 0, 0,
"Enable SELinux label (extended attributes) support on inodes"},
{"capability", ARGP_CAPABILITY_KEY, 0, 0,
"Enable Capability (extended attributes) support on inodes"},
{"subdir-mount", ARGP_SUBDIR_MOUNT_KEY, "SUBDIR-PATH", 0,
"Mount subdirectory given [default: NULL]"},
{"print-netgroups", ARGP_PRINT_NETGROUPS, "NETGROUP-FILE", 0,
"Validate the netgroups file and print it out"},
{"print-exports", ARGP_PRINT_EXPORTS, "EXPORTS-FILE", 0,
"Validate the exports file and print it out"},
{"print-xlatordir", ARGP_PRINT_XLATORDIR_KEY, 0, OPTION_ARG_OPTIONAL,
"Print xlator directory path"},
{"print-statedumpdir", ARGP_PRINT_STATEDUMPDIR_KEY, 0, OPTION_ARG_OPTIONAL,
"Print directory path in which statedumps shall be generated"},
{"print-logdir", ARGP_PRINT_LOGDIR_KEY, 0, OPTION_ARG_OPTIONAL,
"Print path of default log directory"},
{"print-libexecdir", ARGP_PRINT_LIBEXECDIR_KEY, 0, OPTION_ARG_OPTIONAL,
"Print path of default libexec directory"},
{"volfile-max-fetch-attempts", ARGP_VOLFILE_MAX_FETCH_ATTEMPTS, "0",
OPTION_HIDDEN, "Maximum number of attempts to fetch the volfile"},
{"aux-gfid-mount", ARGP_AUX_GFID_MOUNT_KEY, 0, 0,
"Enable access to filesystem through gfid directly"},
{"enable-ino32", ARGP_INODE32_KEY, "BOOL", OPTION_ARG_OPTIONAL,
"Use 32-bit inodes when mounting to workaround broken applications"
"that don't support 64-bit inodes"},
{"worm", ARGP_WORM_KEY, 0, 0, "Mount the filesystem in 'worm' mode"},
{"mac-compat", ARGP_MAC_COMPAT_KEY, "BOOL", OPTION_ARG_OPTIONAL,
"Provide stubs for attributes needed for seamless operation on Macs "
#ifdef GF_DARWIN_HOST_OS
"[default: \"on\" on client side, else \"off\"]"
#else
"[default: \"off\"]"
#endif
},
{"brick-name", ARGP_BRICK_NAME_KEY, "BRICK-NAME", OPTION_HIDDEN,
"Brick name to be registered with Gluster portmapper"},
{"brick-port", ARGP_BRICK_PORT_KEY, "BRICK-PORT", OPTION_HIDDEN,
"Brick Port to be registered with Gluster portmapper"},
{"fopen-keep-cache", ARGP_FOPEN_KEEP_CACHE_KEY, "BOOL", OPTION_ARG_OPTIONAL,
"Do not purge the cache on file open [default: false]"},
{"global-timer-wheel", ARGP_GLOBAL_TIMER_WHEEL, "BOOL", OPTION_ARG_OPTIONAL,
"Instantiate process global timer-wheel"},
{"thin-client", ARGP_THIN_CLIENT_KEY, 0, 0,
"Enables thin mount and connects via gfproxyd daemon"},
{"global-threading", ARGP_GLOBAL_THREADING_KEY, "BOOL", OPTION_ARG_OPTIONAL,
"Use the global thread pool instead of io-threads"},
{0, 0, 0, 0, "Fuse options:"},
{"direct-io-mode", ARGP_DIRECT_IO_MODE_KEY, "BOOL|auto",
OPTION_ARG_OPTIONAL, "Specify direct I/O strategy [default: \"auto\"]"},
{"entry-timeout", ARGP_ENTRY_TIMEOUT_KEY, "SECONDS", 0,
"Set entry timeout to SECONDS in fuse kernel module [default: 1]"},
{"negative-timeout", ARGP_NEGATIVE_TIMEOUT_KEY, "SECONDS", 0,
"Set negative timeout to SECONDS in fuse kernel module [default: 0]"},
{"attribute-timeout", ARGP_ATTRIBUTE_TIMEOUT_KEY, "SECONDS", 0,
"Set attribute timeout to SECONDS for inodes in fuse kernel module "
"[default: 1]"},
{"gid-timeout", ARGP_GID_TIMEOUT_KEY, "SECONDS", 0,
"Set auxiliary group list timeout to SECONDS for fuse translator "
"[default: 300]"},
{"resolve-gids", ARGP_RESOLVE_GIDS_KEY, 0, 0,
"Resolve all auxiliary groups in fuse translator (max 32 otherwise)"},
{"lru-limit", ARGP_FUSE_LRU_LIMIT_KEY, "N", 0,
"Set fuse module's limit for number of inodes kept in LRU list to N "
"[default: 65536]"},
{"inode-table-size", ARGP_FUSE_INODE_TABLESIZE_KEY, "N", 0,
"Set the inode hash table size to N - this must be a power of 2 and "
"will be rounded up if not [default: 65536]"},
{"invalidate-limit", ARGP_FUSE_INVALIDATE_LIMIT_KEY, "N", 0,
"Suspend inode invalidations implied by 'lru-limit' if the number of "
"outstanding invalidations reaches N"},
{"background-qlen", ARGP_FUSE_BACKGROUND_QLEN_KEY, "N", 0,
"Set fuse module's background queue length to N "
"[default: 64]"},
{"congestion-threshold", ARGP_FUSE_CONGESTION_THRESHOLD_KEY, "N", 0,
"Set fuse module's congestion threshold to N "
"[default: 48]"},
#ifdef GF_LINUX_HOST_OS
{"oom-score-adj", ARGP_OOM_SCORE_ADJ_KEY, "INTEGER", 0,
"Set oom_score_adj value for process"
"[default: 0]"},
#endif
{"client-pid", ARGP_CLIENT_PID_KEY, "PID", OPTION_HIDDEN,
"client will authenticate itself with process id PID to server"},
{"no-root-squash", ARGP_FUSE_NO_ROOT_SQUASH_KEY, "BOOL",
OPTION_ARG_OPTIONAL,
"disable/enable root squashing for the trusted "
"client"},
{"user-map-root", ARGP_USER_MAP_ROOT_KEY, "USER", OPTION_HIDDEN,
"replace USER with root in messages"},
{"dump-fuse", ARGP_DUMP_FUSE_KEY, "PATH", 0, "Dump fuse traffic to PATH"},
{"volfile-check", ARGP_VOLFILE_CHECK_KEY, 0, 0,
"Enable strict volume file checking"},
{"no-mem-accounting", ARGP_MEM_ACCOUNTING_KEY, 0, OPTION_HIDDEN,
"disable internal memory accounting"},
{"fuse-mountopts", ARGP_FUSE_MOUNTOPTS_KEY, "OPTIONS", OPTION_HIDDEN,
"Extra mount options to pass to FUSE"},
{"use-readdirp", ARGP_FUSE_USE_READDIRP_KEY, "BOOL", OPTION_ARG_OPTIONAL,
"Use readdirp mode in fuse kernel module"
" [default: \"yes\"]"},
{"secure-mgmt", ARGP_SECURE_MGMT_KEY, "BOOL", OPTION_ARG_OPTIONAL,
"Override default for secure (SSL) management connections"},
{"localtime-logging", ARGP_LOCALTIME_LOGGING_KEY, 0, 0,
"Enable localtime logging"},
{"process-name", ARGP_PROCESS_NAME_KEY, "PROCESS-NAME", OPTION_HIDDEN,
"option to specify the process type"},
{"event-history", ARGP_FUSE_EVENT_HISTORY_KEY, "BOOL", OPTION_ARG_OPTIONAL,
"disable/enable fuse event-history"},
{"reader-thread-count", ARGP_READER_THREAD_COUNT_KEY, "INTEGER",
OPTION_ARG_OPTIONAL, "set fuse reader thread count"},
{"kernel-writeback-cache", ARGP_KERNEL_WRITEBACK_CACHE_KEY, "BOOL",
OPTION_ARG_OPTIONAL, "enable fuse in-kernel writeback cache"},
{"attr-times-granularity", ARGP_ATTR_TIMES_GRANULARITY_KEY, "NS",
OPTION_ARG_OPTIONAL,
"declare supported granularity of file attribute"
" times in nanoseconds"},
{"fuse-flush-handle-interrupt", ARGP_FUSE_FLUSH_HANDLE_INTERRUPT_KEY,
"BOOL", OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
"handle interrupt in fuse FLUSH handler"},
{"fuse-setlk-handle-interrupt", ARGP_FUSE_SETLK_HANDLE_INTERRUPT_KEY,
"BOOL", OPTION_ARG_OPTIONAL, "handle interrupt in fuse SETLK handler"},
{"auto-invalidation", ARGP_FUSE_AUTO_INVAL_KEY, "BOOL", OPTION_ARG_OPTIONAL,
"controls whether fuse-kernel can auto-invalidate "
"attribute, dentry and page-cache. "
"Disable this only if same files/directories are not accessed across "
"two different mounts concurrently [default: \"on\"]"},
{"fuse-dev-eperm-ratelimit-ns", ARGP_FUSE_DEV_EPERM_RATELIMIT_NS_KEY,
"OPTIONS", OPTION_HIDDEN,
"rate limit reading from fuse device upon EPERM failure"},
{"fs-display-name", ARGP_FUSE_DISPLAY_NAME_KEY, "DISPLAY-NAME",
OPTION_HIDDEN,
"Filesystem display name, shown with mount point (as source). Used with "
"commands like 'mount', 'df', etc."},
{"brick-mux", ARGP_BRICK_MUX_KEY, 0, 0, "Enable brick mux. "},
{"io-engine", ARGP_IO_ENGINE_KEY, "ENGINE", OPTION_ARG_OPTIONAL,
"force utilization of the given I/O ENGINE"},
{"fuse-handle-copy_file_range", ARGP_FUSE_HANDLE_COPY_FILE_RANGE, "BOOL",
OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
"enable the handler of the FUSE_COPY_FILE_RANGE message"},
{0, 0, 0, 0, "Miscellaneous Options:"},
{
0,
}};
static struct argp argp = {gf_options, parse_opts, argp_doc, gf_doc};
static void
glusterfs_pidfile_cleanup(glusterfs_ctx_t *ctx)
{
cmd_args_t *cmd_args = NULL;
cmd_args = &ctx->cmd_args;
if (!ctx->pidfp)
return;
gf_msg_trace("glusterfsd", 0, "pidfile %s cleanup", cmd_args->pid_file);
if (ctx->cmd_args.pid_file) {
GF_FREE(ctx->cmd_args.pid_file);
ctx->cmd_args.pid_file = NULL;
}
lockf(fileno(ctx->pidfp), F_ULOCK, 0);
fclose(ctx->pidfp);
ctx->pidfp = NULL;
}
#define DICT_SET_VAL(method, dict, key, val, msgid) \
if (method(dict, key, val)) { \
gf_smsg("glusterfsd", GF_LOG_ERROR, 0, msgid, "key=%s", key); \
goto err; \
}
static int
set_fuse_mount_options(glusterfs_ctx_t *ctx, dict_t *options)
{
int ret = 0;
cmd_args_t *cmd_args = NULL;
char *mount_point = NULL;
char cwd[PATH_MAX] = {
0,
};
cmd_args = &ctx->cmd_args;
/* Check if mount-point is absolute path,
* if not convert to absolute path by concatenating with CWD
*/
if (cmd_args->mount_point[0] != '/') {
if (getcwd(cwd, PATH_MAX) != NULL) {
ret = gf_asprintf(&mount_point, "%s/%s", cwd,
cmd_args->mount_point);
if (ret == -1) {
gf_smsg("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_1,
"gf_asprintf failed", NULL);
goto err;
}
} else {
gf_smsg("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_2,
"getcwd failed", NULL);
goto err;
}
} else {
mount_point = gf_strdup(cmd_args->mount_point);
}
DICT_SET_VAL(dict_set_dynstr_sizen, options, ZR_MOUNTPOINT_OPT, mount_point,
glusterfsd_msg_3);
if (cmd_args->fuse_attribute_timeout >= 0) {
DICT_SET_VAL(dict_set_double, options, ZR_ATTR_TIMEOUT_OPT,
cmd_args->fuse_attribute_timeout, glusterfsd_msg_3);
}
if (cmd_args->fuse_entry_timeout >= 0) {
DICT_SET_VAL(dict_set_double, options, ZR_ENTRY_TIMEOUT_OPT,
cmd_args->fuse_entry_timeout, glusterfsd_msg_3);
}
if (cmd_args->fuse_negative_timeout >= 0) {
DICT_SET_VAL(dict_set_double, options, ZR_NEGATIVE_TIMEOUT_OPT,
cmd_args->fuse_negative_timeout, glusterfsd_msg_3);
}
if (cmd_args->client_pid_set) {
DICT_SET_VAL(dict_set_int32_sizen, options, "client-pid",
cmd_args->client_pid, glusterfsd_msg_3);
}
if (cmd_args->uid_map_root) {
DICT_SET_VAL(dict_set_int32_sizen, options, "uid-map-root",
cmd_args->uid_map_root, glusterfsd_msg_3);
}
if (cmd_args->volfile_check) {
DICT_SET_VAL(dict_set_int32_sizen, options, ZR_STRICT_VOLFILE_CHECK,
cmd_args->volfile_check, glusterfsd_msg_3);
}
if (cmd_args->dump_fuse) {
DICT_SET_VAL(dict_set_static_ptr, options, ZR_DUMP_FUSE,
cmd_args->dump_fuse, glusterfsd_msg_3);
}
if (cmd_args->acl) {
DICT_SET_VAL(dict_set_static_ptr, options, "acl", "on",
glusterfsd_msg_3);
}
if (cmd_args->selinux) {
DICT_SET_VAL(dict_set_static_ptr, options, "selinux", "on",
glusterfsd_msg_3);
}
if (cmd_args->capability) {
DICT_SET_VAL(dict_set_static_ptr, options, "capability", "on",
glusterfsd_msg_3);
}
if (cmd_args->aux_gfid_mount) {
DICT_SET_VAL(dict_set_static_ptr, options, "virtual-gfid-access", "on",
glusterfsd_msg_3);
}
if (cmd_args->enable_ino32) {
DICT_SET_VAL(dict_set_static_ptr, options, "enable-ino32", "on",
glusterfsd_msg_3);
}
if (cmd_args->read_only) {
DICT_SET_VAL(dict_set_static_ptr, options, "read-only", "on",
glusterfsd_msg_3);
}
switch (cmd_args->fopen_keep_cache) {
case GF_OPTION_ENABLE:
DICT_SET_VAL(dict_set_static_ptr, options, "fopen-keep-cache", "on",
glusterfsd_msg_3);
break;
case GF_OPTION_DISABLE:
DICT_SET_VAL(dict_set_static_ptr, options, "fopen-keep-cache",
"off", glusterfsd_msg_3);
break;
default:
gf_msg_debug("glusterfsd", 0, "fopen-keep-cache mode %d",
cmd_args->fopen_keep_cache);
break;
}
if (cmd_args->gid_timeout_set) {
DICT_SET_VAL(dict_set_int32_sizen, options, "gid-timeout",
cmd_args->gid_timeout, glusterfsd_msg_3);
}
if (cmd_args->resolve_gids) {
DICT_SET_VAL(dict_set_static_ptr, options, "resolve-gids", "on",
glusterfsd_msg_3);
}
if (cmd_args->lru_limit >= 0) {
DICT_SET_VAL(dict_set_int32_sizen, options, "lru-limit",
cmd_args->lru_limit, glusterfsd_msg_3);
}
if (cmd_args->inode_table_size >= 0) {
DICT_SET_VAL(dict_set_int32_sizen, options, "inode-table-size",
cmd_args->inode_table_size, glusterfsd_msg_3);
}
if (cmd_args->invalidate_limit >= 0) {
DICT_SET_VAL(dict_set_int32_sizen, options, "invalidate-limit",
cmd_args->invalidate_limit, glusterfsd_msg_3);
}
if (cmd_args->background_qlen) {
DICT_SET_VAL(dict_set_int32_sizen, options, "background-qlen",
cmd_args->background_qlen, glusterfsd_msg_3);
}
if (cmd_args->congestion_threshold) {
DICT_SET_VAL(dict_set_int32_sizen, options, "congestion-threshold",
cmd_args->congestion_threshold, glusterfsd_msg_3);
}
switch (cmd_args->fuse_direct_io_mode) {
case GF_OPTION_DISABLE: /* disable */
DICT_SET_VAL(dict_set_static_ptr, options, ZR_DIRECT_IO_OPT,
"disable", glusterfsd_msg_3);
break;
case GF_OPTION_ENABLE: /* enable */
DICT_SET_VAL(dict_set_static_ptr, options, ZR_DIRECT_IO_OPT,
"enable", glusterfsd_msg_3);
break;
default:
gf_msg_debug("glusterfsd", 0, "fuse direct io type %d",
cmd_args->fuse_direct_io_mode);
break;
}
switch (cmd_args->no_root_squash) {
case GF_OPTION_ENABLE: /* enable */
DICT_SET_VAL(dict_set_static_ptr, options, "no-root-squash",
"enable", glusterfsd_msg_3);
break;
default:
DICT_SET_VAL(dict_set_static_ptr, options, "no-root-squash",
"disable", glusterfsd_msg_3);
gf_msg_debug("glusterfsd", 0, "fuse no-root-squash mode %d",
cmd_args->no_root_squash);
break;
}
if (!cmd_args->no_daemon_mode) {
DICT_SET_VAL(dict_set_static_ptr, options, "sync-to-mount", "enable",
glusterfsd_msg_3);
}
if (cmd_args->use_readdirp) {
DICT_SET_VAL(dict_set_static_ptr, options, "use-readdirp",
cmd_args->use_readdirp, glusterfsd_msg_3);
}
if (cmd_args->event_history) {
ret = dict_set_str(options, "event-history", cmd_args->event_history);
DICT_SET_VAL(dict_set_static_ptr, options, "event-history",
cmd_args->event_history, glusterfsd_msg_3);
}
if (cmd_args->thin_client) {
DICT_SET_VAL(dict_set_static_ptr, options, "thin-client", "on",
glusterfsd_msg_3);
}
if (cmd_args->reader_thread_count) {
DICT_SET_VAL(dict_set_uint32, options, "reader-thread-count",
cmd_args->reader_thread_count, glusterfsd_msg_3);
}
DICT_SET_VAL(dict_set_uint32, options, "auto-invalidation",
cmd_args->fuse_auto_inval, glusterfsd_msg_3);
switch (cmd_args->kernel_writeback_cache) {
case GF_OPTION_ENABLE:
DICT_SET_VAL(dict_set_static_ptr, options, "kernel-writeback-cache",
"on", glusterfsd_msg_3);
break;
case GF_OPTION_DISABLE:
DICT_SET_VAL(dict_set_static_ptr, options, "kernel-writeback-cache",
"off", glusterfsd_msg_3);
break;
default:
gf_msg_debug("glusterfsd", 0, "kernel-writeback-cache mode %d",
cmd_args->kernel_writeback_cache);
break;
}
if (cmd_args->attr_times_granularity) {
DICT_SET_VAL(dict_set_uint32, options, "attr-times-granularity",
cmd_args->attr_times_granularity, glusterfsd_msg_3);
}
switch (cmd_args->fuse_flush_handle_interrupt) {
case GF_OPTION_ENABLE:
DICT_SET_VAL(dict_set_static_ptr, options, "flush-handle-interrupt",
"on", glusterfsd_msg_3);
break;
case GF_OPTION_DISABLE:
DICT_SET_VAL(dict_set_static_ptr, options, "flush-handle-interrupt",
"off", glusterfsd_msg_3);
break;
default:
gf_msg_debug("glusterfsd", 0, "fuse-flush-handle-interrupt mode %d",
cmd_args->fuse_flush_handle_interrupt);
break;
}
if (cmd_args->global_threading) {
DICT_SET_VAL(dict_set_static_ptr, options, "global-threading", "on",
glusterfsd_msg_3);
}
if (cmd_args->fuse_dev_eperm_ratelimit_ns) {
DICT_SET_VAL(dict_set_uint32, options, "fuse-dev-eperm-ratelimit-ns",
cmd_args->fuse_dev_eperm_ratelimit_ns, glusterfsd_msg_3);
}
switch (cmd_args->fuse_handle_copy_file_range) {
case GF_OPTION_ENABLE:
DICT_SET_VAL(dict_set_static_ptr, options, "handle-copy_file_range",
"on", glusterfsd_msg_3);
break;
case GF_OPTION_DISABLE:
DICT_SET_VAL(dict_set_static_ptr, options, "handle-copy_file_range",
"off", glusterfsd_msg_3);
break;
default:
gf_msg_debug("glusterfsd", 0, "fuse-handle-copy_file_range mode %d",
cmd_args->fuse_handle_copy_file_range);
break;
}
if (cmd_args->fs_display_name) {
DICT_SET_VAL(dict_set_dynstr, options, "fs-display-name",
cmd_args->fs_display_name, glusterfsd_msg_3);
}
if (cmd_args->io_engine != NULL) {
DICT_SET_VAL(dict_set_static_ptr, options, "io-engine",
cmd_args->io_engine, glusterfsd_msg_3);
}
switch (cmd_args->fuse_setlk_handle_interrupt) {
case GF_OPTION_ENABLE:
ret = dict_set_static_ptr(options, "setlk-handle-interrupt", "on");
if (ret < 0) {
gf_msg("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4,
"failed to set dict value for key "
"setlk-handle-interrupt");
goto err;
}
break;
case GF_OPTION_DISABLE:
ret = dict_set_static_ptr(options, "setlk-handle-interrupt", "off");
if (ret < 0) {
gf_msg("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4,
"failed to set dict value for key "
"setlk-handle-interrupt");
goto err;
}
break;
case GF_OPTION_DEFERRED: /* default */
default:
gf_msg_debug("glusterfsd", 0, "fuse-setlk-handle-interrupt mode %d",
cmd_args->fuse_setlk_handle_interrupt);
break;
}
ret = 0;
err:
return ret;
}
static int
create_fuse_mount(glusterfs_ctx_t *ctx)
{
int ret = 0;
cmd_args_t *cmd_args = NULL;
xlator_t *root = NULL;
cmd_args = &ctx->cmd_args;
if (!cmd_args->mount_point) {
gf_msg_trace("glusterfsd", 0,
"mount point not found, not a client process");
return 0;
}
if (ctx->process_mode != GF_CLIENT_PROCESS) {
gf_smsg("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_7, NULL);
return -1;
}
root = GF_CALLOC(1, sizeof(*root), gfd_mt_xlator_t);
if (!root)
goto err;
root->name = gf_strdup("fuse");
if (!root->name)
goto err;
if (xlator_set_type(root, "mount/fuse") == -1) {
gf_smsg("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_8,
"MOUNT-POINT=%s", cmd_args->mount_point, NULL);
goto err;
}
root->ctx = ctx;
root->options = dict_new();
if (!root->options)
goto err;
ret = set_fuse_mount_options(ctx, root->options);
if (ret)
goto err;
if (cmd_args->fuse_mountopts) {
ret = dict_set_static_ptr(root->options, ZR_FUSE_MOUNTOPTS,
cmd_args->fuse_mountopts);
if (ret < 0) {
gf_smsg("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_3,
ZR_FUSE_MOUNTOPTS, NULL);
goto err;
}
}
ret = xlator_init(root);
if (ret) {
gf_msg_debug("glusterfsd", 0, "failed to initialize fuse translator");
goto err;
}
ctx->root = root;
return 0;
err:
if (root) {
xlator_destroy(root);
}
return 1;
}
static int
gf_remember_backup_volfile_server(char *arg)
{
glusterfs_ctx_t *ctx = NULL;
cmd_args_t *cmd_args = NULL;
int ret = -1;
ctx = glusterfsd_ctx;
if (!ctx)
goto out;
cmd_args = &ctx->cmd_args;
if (!cmd_args)
goto out;
ret = gf_set_volfile_server_common(
cmd_args, arg, GF_DEFAULT_VOLFILE_TRANSPORT, GF_DEFAULT_BASE_PORT);
if (ret) {
gf_log("glusterfs", GF_LOG_ERROR, "failed to set volfile server: %s",
strerror(errno));
}
out:
return ret;
}
static int
gf_remember_xlator_option(char *arg)
{
glusterfs_ctx_t *ctx = NULL;
cmd_args_t *cmd_args = NULL;
xlator_cmdline_option_t *option = NULL;
int ret = -1;
char *dot = NULL;
char *equals = NULL;
ctx = glusterfsd_ctx;
cmd_args = &ctx->cmd_args;
option = GF_CALLOC(1, sizeof(xlator_cmdline_option_t),
gfd_mt_xlator_cmdline_option_t);
if (!option)
goto out;
INIT_LIST_HEAD(&option->cmd_args);
dot = strchr(arg, '.');
if (!dot) {
gf_smsg("", GF_LOG_WARNING, 0, glusterfsd_msg_10, "arg=%s", arg, NULL);
goto out;
}
option->volume = GF_MALLOC((dot - arg) + 1, gfd_mt_char);
if (!option->volume)
goto out;
strncpy(option->volume, arg, (dot - arg));
option->volume[(dot - arg)] = '\0';
equals = strchr(arg, '=');
if (!equals) {
gf_smsg("", GF_LOG_WARNING, 0, glusterfsd_msg_10, "arg=%s", arg, NULL);
goto out;
}
option->key = GF_MALLOC((equals - dot) + 1, gfd_mt_char);
if (!option->key)
goto out;
strncpy(option->key, dot + 1, (equals - dot - 1));
option->key[(equals - dot - 1)] = '\0';
if (!*(equals + 1)) {
gf_smsg("", GF_LOG_WARNING, 0, glusterfsd_msg_10, "arg=%s", arg, NULL);
goto out;
}
option->value = gf_strdup(equals + 1);
list_add(&option->cmd_args, &cmd_args->xlator_options);
ret = 0;
out:
if (ret == -1) {
if (option) {
GF_FREE(option->volume);
GF_FREE(option->key);
GF_FREE(option->value);
GF_FREE(option);
}
}
return ret;
}
#ifdef GF_LINUX_HOST_OS
static struct oom_api_info {
char *oom_api_file;
int32_t oom_min;
int32_t oom_max;
} oom_api_info[] = {
{"/proc/self/oom_score_adj", OOM_SCORE_ADJ_MIN, OOM_SCORE_ADJ_MAX},
{"/proc/self/oom_adj", OOM_DISABLE, OOM_ADJUST_MAX},
{NULL, 0, 0}};
static struct oom_api_info *
get_oom_api_info(void)
{
struct oom_api_info *api = NULL;
for (api = oom_api_info; api->oom_api_file; api++) {
if (sys_access(api->oom_api_file, F_OK) != -1) {
return api;
}
}
return NULL;
}
#endif
static error_t
parse_opts(int key, char *arg, struct argp_state *state)
{
cmd_args_t *cmd_args = NULL;
uint32_t n = 0;
#ifdef GF_LINUX_HOST_OS
int32_t k = 0;
struct oom_api_info *api = NULL;
#endif
double d = 0.0;
gf_boolean_t b = _gf_false;
char *tmp_str = NULL;
char *port_str = NULL;
struct passwd *pw = NULL;
int ret = 0;
cmd_args = state->input;
switch (key) {
case ARGP_VOLFILE_SERVER_KEY:
gf_remember_backup_volfile_server(arg);
break;
case ARGP_READ_ONLY_KEY:
cmd_args->read_only = 1;
break;
case ARGP_ACL_KEY:
cmd_args->acl = 1;
gf_remember_xlator_option("*-md-cache.cache-posix-acl=true");
break;
case ARGP_SELINUX_KEY:
cmd_args->selinux = 1;
gf_remember_xlator_option("*-md-cache.cache-selinux=true");
break;
case ARGP_CAPABILITY_KEY:
cmd_args->capability = 1;
break;
case ARGP_AUX_GFID_MOUNT_KEY:
cmd_args->aux_gfid_mount = 1;
break;
case ARGP_INODE32_KEY:
cmd_args->enable_ino32 = 1;
break;
case ARGP_WORM_KEY:
cmd_args->worm = 1;
break;
case ARGP_PRINT_NETGROUPS:
cmd_args->print_netgroups = arg;
break;
case ARGP_PRINT_EXPORTS:
cmd_args->print_exports = arg;
break;
case ARGP_PRINT_XLATORDIR_KEY:
cmd_args->print_xlatordir = _gf_true;
break;
case ARGP_PRINT_STATEDUMPDIR_KEY:
cmd_args->print_statedumpdir = _gf_true;
break;
case ARGP_PRINT_LOGDIR_KEY:
cmd_args->print_logdir = _gf_true;
break;
case ARGP_PRINT_LIBEXECDIR_KEY:
cmd_args->print_libexecdir = _gf_true;
break;
case ARGP_MAC_COMPAT_KEY:
if (!arg)
arg = "on";
if (gf_string2boolean(arg, &b) == 0) {
cmd_args->mac_compat = b;
break;
}
argp_failure(state, -1, 0, "invalid value \"%s\" for mac-compat",
arg);
break;
case ARGP_VOLUME_FILE_KEY:
GF_FREE(cmd_args->volfile);
if (arg[0] != '/') {
char pwd[PATH_MAX];
if (!getcwd(pwd, PATH_MAX)) {
argp_failure(state, -1, errno,
"getcwd failed with error no %d", errno);
break;
}
gf_asprintf(&cmd_args->volfile, "%s/%s", pwd, arg);
} else {
cmd_args->volfile = gf_strdup(arg);
}
break;
case ARGP_LOG_LEVEL_KEY:
if (strcasecmp(arg, ARGP_LOG_LEVEL_NONE_OPTION) == 0) {
cmd_args->log_level = GF_LOG_NONE;
break;
}
if (strcasecmp(arg, ARGP_LOG_LEVEL_CRITICAL_OPTION) == 0) {
cmd_args->log_level = GF_LOG_CRITICAL;
break;
}
if (strcasecmp(arg, ARGP_LOG_LEVEL_ERROR_OPTION) == 0) {
cmd_args->log_level = GF_LOG_ERROR;
break;
}
if (strcasecmp(arg, ARGP_LOG_LEVEL_WARNING_OPTION) == 0) {
cmd_args->log_level = GF_LOG_WARNING;
break;
}
if (strcasecmp(arg, ARGP_LOG_LEVEL_INFO_OPTION) == 0) {
cmd_args->log_level = GF_LOG_INFO;
break;
}
if (strcasecmp(arg, ARGP_LOG_LEVEL_DEBUG_OPTION) == 0) {
cmd_args->log_level = GF_LOG_DEBUG;
break;
}
if (strcasecmp(arg, ARGP_LOG_LEVEL_TRACE_OPTION) == 0) {
cmd_args->log_level = GF_LOG_TRACE;
break;
}
argp_failure(state, -1, 0, "unknown log level %s", arg);
break;
case ARGP_LOG_FILE_KEY:
cmd_args->log_file = gf_strdup(arg);
break;
case ARGP_VOLFILE_SERVER_PORT_KEY:
n = 0;
if (gf_string2uint_base10(arg, &n) == 0) {
cmd_args->volfile_server_port = n;
break;
}
argp_failure(state, -1, 0, "unknown volfile server port %s", arg);
break;
case ARGP_VOLFILE_SERVER_TRANSPORT_KEY:
cmd_args->volfile_server_transport = gf_strdup(arg);
break;
case ARGP_VOLFILE_ID_KEY:
cmd_args->volfile_id = gf_strdup(arg);
break;
case ARGP_THIN_CLIENT_KEY:
cmd_args->thin_client = _gf_true;
break;
case ARGP_BRICK_MUX_KEY:
cmd_args->brick_mux = _gf_true;
break;
case ARGP_PID_FILE_KEY:
cmd_args->pid_file = gf_strdup(arg);
break;
case ARGP_SOCK_FILE_KEY:
cmd_args->sock_file = gf_strdup(arg);
break;
case ARGP_NO_DAEMON_KEY:
cmd_args->no_daemon_mode = ENABLE_NO_DAEMON_MODE;
break;
case ARGP_RUN_ID_KEY:
cmd_args->run_id = gf_strdup(arg);
break;
case ARGP_DEBUG_KEY:
cmd_args->debug_mode = ENABLE_DEBUG_MODE;
break;
case ARGP_VOLFILE_MAX_FETCH_ATTEMPTS:
cmd_args->max_connect_attempts = 1;
break;
case ARGP_DIRECT_IO_MODE_KEY:
if (!arg)
arg = "on";
if (gf_string2boolean(arg, &b) == 0) {