-
Notifications
You must be signed in to change notification settings - Fork 6
/
mysqlfs.c
795 lines (638 loc) · 19.9 KB
/
mysqlfs.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
/*
mysqlfs - MySQL Filesystem
Copyright (C) 2006 Tsukasa Hamano <[email protected]>
$Id: mysqlfs.c,v 1.18 2006/09/17 11:09:32 ludvigm Exp $
This program can be distributed under the terms of the GNU GPL.
See the file COPYING.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <fuse.h>
#ifdef HAVE_MYSQL_MYSQL_H
#include <mysql/mysql.h>
#endif
#ifdef HAVE_MYSQL_H
#include <mysql.h>
#endif
#include <pthread.h>
#include <sys/stat.h>
#ifdef DEBUG
#include <mcheck.h>
#endif
#include <stddef.h>
#include "mysqlfs.h"
#include "query.h"
#include "pool.h"
#include "log.h"
static int mysqlfs_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *f)
{
int ret;
MYSQL *dbconn;
// This is called far too often
log_printf(LOG_D_CALL, "mysqlfs_getattr(\"%s\")\n", path);
memset(stbuf, 0, sizeof(struct stat));
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
ret = query_getattr(dbconn, path, stbuf);
pool_put(dbconn);
return ret;
}
static int mysqlfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi,
enum fuse_readdir_flags flags)
{
(void) offset;
(void) fi;
int ret;
MYSQL *dbconn;
long inode;
struct stat st;
log_printf(LOG_D_CALL, "mysqlfs_readdir(\"%s\")\n", path);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
if (fi && fi->fh)
inode = fi->fh;
else
{
inode = query_inode(dbconn, path);
if(inode < 0){
log_printf(LOG_ERROR, "Error: query_inode()\n");
pool_put(dbconn);
return inode;
}
}
log_printf(LOG_D_CALL, "mysqlfs_readir: inode %ld\n", inode);
memset(&st, 0, sizeof st);
st.st_ino = 1;
st.st_mode = 0777;
filler(buf, ".", &st, 0, 0);
filler(buf, "..", &st, 0, 0);
ret = query_readdir(dbconn, inode, buf, filler, flags);
pool_put(dbconn);
log_printf(LOG_D_CALL, "mysqlfs_readdir(), return %d\n", ret);
return ret;
}
/** FUSE function for mknod(const char *pathname, mode_t mode, dev_t dev); API call. @see http://linux.die.net/man/2/mknod */
static int mysqlfs_mknod(const char *path, mode_t mode, dev_t rdev)
{
int ret;
MYSQL *dbconn;
long parent_inode;
char dir_path[PATH_MAX + 1];
log_printf(LOG_D_CALL, "mysqlfs_mknod(\"%s\", %o): %s\n", path, mode,
S_ISREG(mode) ? "file" :
S_ISDIR(mode) ? "directory" :
S_ISLNK(mode) ? "symlink" :
"other");
if(!(strlen(path) <= PATH_MAX)){
log_printf(LOG_ERROR, "Error: Filename too long\n");
return -ENAMETOOLONG;
}
strncpy(dir_path, path, PATH_MAX);
dirname(dir_path);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
parent_inode = query_inode(dbconn, dir_path);
if(parent_inode < 0){
pool_put(dbconn);
return -ENOENT;
}
ret = query_mknod(dbconn, path, mode, rdev, parent_inode, S_ISREG(mode) || S_ISLNK(mode));
if(ret < 0){
pool_put(dbconn);
return ret;
}
pool_put(dbconn);
return 0;
}
static int mysqlfs_mkdir(const char *path, mode_t mode){
int ret;
MYSQL *dbconn;
long inode;
char dir_path[PATH_MAX + 1];
log_printf(LOG_D_CALL, "mysqlfs_mkdir(\"%s\", 0%o)\n", path, mode);
if(!(strlen(path) <= PATH_MAX)){
log_printf(LOG_ERROR, "Error: Filename too long\n");
return -ENAMETOOLONG;
}
strncpy(dir_path, path, PATH_MAX);
dirname(dir_path);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
inode = query_inode(dbconn, dir_path);
if(inode < 0){
pool_put(dbconn);
return -ENOENT;
}
ret = query_mkdir(dbconn, path, mode, inode);
if(ret < 0){
log_printf(LOG_ERROR, "Error: query_mkdir()\n");
pool_put(dbconn);
return ret;
}
pool_put(dbconn);
return 0;
}
static int mysqlfs_unlink(const char *path)
{
int ret;
long inode, parent, nlinks;
char name[PATH_MAX];
MYSQL *dbconn;
log_printf(LOG_D_CALL, "mysqlfs_unlink(\"%s\")\n", path);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
ret = query_inode_full(dbconn, path, name, sizeof(name),
&inode, &parent, &nlinks);
if (ret < 0) {
if (ret != -ENOENT)
log_printf(LOG_ERROR, "Error: query_inode_full(%s): %s\n",
path, strerror(ret));
goto err_out;
}
ret = query_rmdirentry(dbconn, name, inode, parent);
if (ret < 0) {
log_printf(LOG_ERROR, "Error: query_rmdirentry()\n");
goto err_out;
}
/* Only the last unlink() must set deleted flag.
* This is a shortcut - query_set_deleted() wouldn't
* set the flag if there is still an existing direntry
* anyway. But we'll save some DB processing here. */
if (nlinks > 1)
return 0;
ret = query_set_deleted(dbconn, inode);
if (ret < 0) {
log_printf(LOG_ERROR, "Error: query_set_deleted()\n");
goto err_out;
}
ret = query_purge_deleted(dbconn, inode);
if (ret < 0) {
log_printf(LOG_ERROR, "Error: query_purge_deleted()\n");
goto err_out;
}
pool_put(dbconn);
return 0;
err_out:
pool_put(dbconn);
return ret;
}
static int mysqlfs_chmod(const char* path, mode_t mode,struct fuse_file_info *fi)
{
int ret;
long inode;
MYSQL *dbconn;
log_printf(LOG_D_CALL, "mysql_chmod(\"%s\", 0%3o)\n", path, mode);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
if (fi && fi->fh)
inode = fi->fh;
else {
inode = query_inode(dbconn, path);
if (inode < 0) {
pool_put(dbconn);
return inode;
}
}
ret = query_chmod(dbconn, inode, mode);
if(ret){
log_printf(LOG_ERROR, "Error: query_chmod()\n");
pool_put(dbconn);
return -EIO;
}
pool_put(dbconn);
return ret;
}
static int mysqlfs_chown(const char *path, uid_t uid, gid_t gid, struct fuse_file_info *fi)
{
int ret;
long inode;
MYSQL *dbconn;
log_printf(LOG_D_CALL, "mysql_chown(\"%s\", %ld, %ld)\n", path, uid, gid);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
if (fi && fi->fh)
inode = fi->fh;
else {
inode = query_inode(dbconn, path);
if (inode < 0) {
pool_put(dbconn);
return inode;
}
}
ret = query_chown(dbconn, inode, uid, gid);
if(ret){
log_printf(LOG_ERROR, "Error: query_chown()\n");
pool_put(dbconn);
return -EIO;
}
pool_put(dbconn);
return ret;
}
static int mysqlfs_truncate(const char* path, off_t length,
struct fuse_file_info *fi)
{
int ret;
MYSQL *dbconn;
long inode;
log_printf(LOG_D_CALL, "mysql_truncate(\"%s\"): len=%lld\n", path, length);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
if (fi && fi->fh)
inode = fi->fh;
else {
inode = query_inode(dbconn, path);
if (inode < 0) {
pool_put(dbconn);
return inode;
}
}
ret = query_truncate(dbconn, inode, length);
if (ret < 0) {
log_printf(LOG_ERROR, "Error: query_length()\n");
pool_put(dbconn);
return -EIO;
}
pool_put(dbconn);
return 0;
}
static int mysqlfs_utime(const char *path, const struct timespec tv[2], struct fuse_file_info *fi)
{
int ret;
long inode;
MYSQL *dbconn;
log_printf(LOG_D_CALL, "mysql_utime(\"%s\")\n", path);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
if (fi && fi->fh)
inode = fi->fh;
else
{
inode = query_inode(dbconn, path);
if (inode < 0) {
pool_put(dbconn);
return inode;
}
}
ret = query_utime(dbconn, inode, tv);
if (ret < 0) {
log_printf(LOG_ERROR, "Error: query_utime()\n");
pool_put(dbconn);
return -EIO;
}
pool_put(dbconn);
return 0;
}
static int mysqlfs_open(const char *path, struct fuse_file_info *fi)
{
MYSQL *dbconn;
long inode;
int ret;
log_printf(LOG_D_CALL, "mysqlfs_open(\"%s\")\n", path);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
inode = query_inode(dbconn, path);
if(inode < 0){
pool_put(dbconn);
return -ENOENT;
}
/* Save inode for future use. Lets us skip path->inode translation. */
fi->fh = inode;
log_printf(LOG_D_OTHER, "inode(\"%s\") = %d\n", path, fi->fh);
ret = query_inuse_inc(dbconn, inode, 1);
if (ret < 0) {
pool_put(dbconn);
return ret;
}
pool_put(dbconn);
return 0;
}
static int mysqlfs_read(const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
int ret;
MYSQL *dbconn;
log_printf(LOG_D_CALL, "mysqlfs_read(\"%s\" %zu@%llu)\n", path, size, offset);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
ret = query_read(dbconn, fi->fh, buf, size, offset);
pool_put(dbconn);
return ret;
}
static int mysqlfs_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
int ret;
MYSQL *dbconn;
log_printf(LOG_D_CALL, "mysqlfs_write(\"%s\" %zu@%lld)\n", path, size, offset);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
ret = query_write(dbconn, fi->fh, buf, size, offset);
pool_put(dbconn);
return ret;
}
static int mysqlfs_release(const char *path, struct fuse_file_info *fi)
{
int ret;
MYSQL *dbconn;
log_printf(LOG_D_CALL, "mysqlfs_release(\"%s\")\n", path);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
ret = query_inuse_inc(dbconn, fi->fh, -1);
if (ret < 0) {
pool_put(dbconn);
return ret;
}
ret = query_purge_deleted(dbconn, fi->fh);
if (ret < 0) {
pool_put(dbconn);
return ret;
}
pool_put(dbconn);
return 0;
}
static int mysqlfs_link(const char *from, const char *to)
{
int ret;
long inode, new_parent;
MYSQL *dbconn;
char *tmp, *name, esc_name[PATH_MAX * 2];
log_printf(LOG_D_CALL, "link(%s, %s)\n", from, to);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
inode = query_inode(dbconn, from);
if(inode < 0){
pool_put(dbconn);
return inode;
}
tmp = strdup(to);
name = dirname(tmp);
new_parent = query_inode(dbconn, name);
free(tmp);
if (new_parent < 0) {
pool_put(dbconn);
return new_parent;
}
tmp = strdup(to);
name = basename(tmp);
mysql_real_escape_string(dbconn, esc_name, name, strlen(name));
free(tmp);
ret = query_mkdirentry(dbconn, inode, esc_name, new_parent);
if(ret < 0){
pool_put(dbconn);
return ret;
}
pool_put(dbconn);
return 0;
}
static int mysqlfs_symlink(const char *from, const char *to)
{
int ret;
int inode;
MYSQL *dbconn;
log_printf(LOG_D_CALL, "%s(\"%s\" -> \"%s\")\n", __func__, from, to);
ret = mysqlfs_mknod(to, S_IFLNK | 0755, 0);
if (ret < 0)
return ret;
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
inode = query_inode(dbconn, to);
if(inode < 0){
pool_put(dbconn);
return -ENOENT;
}
ret = query_write(dbconn, inode, from, strlen(from), 0);
if (ret > 0) ret = 0;
pool_put(dbconn);
return ret;
}
static int mysqlfs_readlink(const char *path, char *buf, size_t size)
{
int ret;
long inode;
MYSQL *dbconn;
log_printf(LOG_D_CALL, "%s(\"%s\")\n", __func__, path);
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
inode = query_inode(dbconn, path);
if(inode < 0){
pool_put(dbconn);
return -ENOENT;
}
memset (buf, 0, size);
ret = query_read(dbconn, inode, buf, size, 0);
log_printf(LOG_DEBUG, "readlink(%s): %s [%zd -> %d]\n", path, buf, size, ret);
pool_put(dbconn);
if (ret > 0) ret = 0;
return ret;
}
static int mysqlfs_rename(const char *from, const char *to, unsigned int flags)
{
int ret;
MYSQL *dbconn;
log_printf(LOG_D_CALL, "%s(%s -> %s)\n", __func__, from, to);
/* We don't handle the EXCHANGE or NOREPLACE flags */
if (flags)
return -EINVAL;
if ((dbconn = pool_get()) == NULL)
return -EMFILE;
// FIXME: This should be wrapped in a transaction!!!
mysqlfs_unlink(to);
ret = query_rename(dbconn, from, to);
pool_put(dbconn);
return ret;
}
/*
* Set config options for correct operation
*/
static void *mysqlfs_init(struct fuse_conn_info *conn,
struct fuse_config *cfg)
{
/* Honour inode numbers we pass to getattr etc
*/
cfg->use_ino = 1;
/*
* Pick up changes straight away. This is also necessary for
* better hardlink support. When the kernel calls the unlink()
* handler, it does not know the inode of the to-be-removed entry
* and can therefore not invalidate the cache of the associated
* inode -- resulting in an incorrect st_nlink value being
* reported for any remaining hardlinks to this inode.
*/
cfg->entry_timeout = 60;
cfg->attr_timeout = 10;
cfg->negative_timeout = 10;
cfg->nullpath_ok = 0;
return NULL;
}
/** used below in fuse_main() to define the entry points for a FUSE filesystem; this is the same VMT-like jump table used throughout the UNIX kernel. */
static struct fuse_operations mysqlfs_oper = {
.init = mysqlfs_init,
.getattr = mysqlfs_getattr,
.readdir = mysqlfs_readdir,
.mknod = mysqlfs_mknod,
.mkdir = mysqlfs_mkdir,
.unlink = mysqlfs_unlink,
.rmdir = mysqlfs_unlink,
.chmod = mysqlfs_chmod,
.chown = mysqlfs_chown,
.truncate = mysqlfs_truncate,
.utimens = mysqlfs_utime,
.open = mysqlfs_open,
.read = mysqlfs_read,
.write = mysqlfs_write,
.release = mysqlfs_release,
.link = mysqlfs_link,
.symlink = mysqlfs_symlink,
.readlink = mysqlfs_readlink,
.rename = mysqlfs_rename,
};
/** print out a brief usage aide-memoire to stderr */
void usage(){
fprintf(stderr,
"usage: mysqlfs [opts] <mountpoint>\n\n");
fprintf(stderr,
" mysqlfs [-osocket=/tmp/mysql.sock] [-oport=####] -ohost=host -ouser=user -opassword=password "
"-odatabase=database ./mountpoint\n");
fprintf(stderr,
" mysqlfs [-d] [-ologfile=filename] -ohost=host -ouser=user -opassword=password "
"-odatabase=database ./mountpoint\n");
fprintf(stderr,
" mysqlfs [-mycnf_group=group_name] -ohost=host -ouser=user -opassword=password "
"-odatabase=database ./mountpoint\n");
fprintf(stderr, "\n(mimick mysql options)\n");
fprintf(stderr,
" mysqlfs --host=host --user=user --password=password --database=database ./mountpoint\n");
fprintf(stderr,
" mysqlfs -h host -u user --password=password -D database ./mountpoint\n");
}
/** macro to set a call value with a default -- defined yet? */
#define MYSQLFS_OPT_KEY(t, p, v) { t, offsetof(struct mysqlfs_opt, p), v }
/** FUSE_OPT_xxx keys defines for use with fuse_opt_parse() */
enum
{
KEY_BACKGROUND, /**< debug: key for option to activate mysqlfs::bg to force-background the server */
KEY_DEBUG_DNQ, /**< debug: Dump (Config) and Quit */
KEY_HELP,
KEY_VERSION,
};
/** fuse_opt for use with fuse_opt_parse() */
static struct fuse_opt mysqlfs_opts[] =
{
MYSQLFS_OPT_KEY( "background", bg, 1),
MYSQLFS_OPT_KEY( "database=%s", db, 1),
MYSQLFS_OPT_KEY("--database=%s", db, 1),
MYSQLFS_OPT_KEY( "-D %s", db, 1),
MYSQLFS_OPT_KEY( "fsck", fsck, 1),
MYSQLFS_OPT_KEY( "fsck=%d", fsck, 1),
MYSQLFS_OPT_KEY("--fsck=%d", fsck, 1),
MYSQLFS_OPT_KEY("nofsck", fsck, 0),
MYSQLFS_OPT_KEY( "host=%s", host, 0),
MYSQLFS_OPT_KEY("--host=%s", host, 0),
MYSQLFS_OPT_KEY( "-h %s", host, 0),
MYSQLFS_OPT_KEY( "logfile=%s", logfile, 0),
MYSQLFS_OPT_KEY("--logfile=%s", logfile, 0),
MYSQLFS_OPT_KEY( "mycnf_group=%s", mycnf_group, 0), /* Read defaults from specified group in my.cnf -- Command line options still have precedence. */
MYSQLFS_OPT_KEY("--mycnf_group=%s", mycnf_group, 0),
MYSQLFS_OPT_KEY( "password=%s", passwd, 0),
MYSQLFS_OPT_KEY("--password=%s", passwd, 0),
MYSQLFS_OPT_KEY( "port=%d", port, 0),
MYSQLFS_OPT_KEY("--port=%d", port, 0),
MYSQLFS_OPT_KEY( "-P %d", port, 0),
MYSQLFS_OPT_KEY( "socket=%s", socket, 0),
MYSQLFS_OPT_KEY("--socket=%s", socket, 0),
MYSQLFS_OPT_KEY( "-S %s", socket, 0),
MYSQLFS_OPT_KEY( "user=%s", user, 0),
MYSQLFS_OPT_KEY("--user=%s", user, 0),
MYSQLFS_OPT_KEY( "-u %s", user, 0),
FUSE_OPT_KEY("debug-dnq", KEY_DEBUG_DNQ),
FUSE_OPT_KEY("-v", KEY_VERSION),
FUSE_OPT_KEY("--version", KEY_VERSION),
FUSE_OPT_KEY("--help", KEY_HELP),
FUSE_OPT_KEY("allow_other", FUSE_OPT_KEY_OPT),
FUSE_OPT_END
};
static int mysqlfs_opt_proc(void *data, const char *arg, int key,
struct fuse_args *outargs){
struct mysqlfs_opt *opt = (struct mysqlfs_opt *) data;
switch (key)
{
case FUSE_OPT_KEY_OPT: /* dig through the list for matches */
/*
* There are primitives for this in FUSE, but no need to change at this point
*/
break;
case KEY_DEBUG_DNQ:
/*
* Debug: Dump Config and Quit -- used to debug options-handling changes
*/
fprintf (stderr, "DEBUG: Dump and Quit\n\n");
fprintf (stderr, "connect: mysql://%s:%s@%s:%d/%s\n", opt->user, opt->passwd, opt->host, opt->port, opt->db);
fprintf (stderr, "connect: sock://%s\n", opt->socket);
fprintf (stderr, "fsck? %s\n", (opt->fsck ? "yes" : "no"));
fprintf (stderr, "group: %s\n", opt->mycnf_group);
fprintf (stderr, "pool: %d initial connections\n", opt->init_conns);
fprintf (stderr, "pool: %d idling connections\n", opt->max_idling_conns);
fprintf (stderr, "logfile: file://%s\n", opt->logfile);
fprintf (stderr, "bg? %s (debug)\n\n", (opt->bg ? "yes" : "no"));
exit (2);
case KEY_HELP: /* trigger usage call */
usage ();
exit (0);
case KEY_VERSION: /* show version and quit */
fprintf (stderr, "%s-%s fuse-%2.1f\n\n", PACKAGE_TARNAME, PACKAGE_VERSION, ((double) FUSE_USE_VERSION)/10.0);
exit (0);
default: /* key != FUSE_OPT_KEY_OPT */
fuse_opt_add_arg(outargs, arg);
return 0;
}
fuse_opt_add_arg(outargs, arg);
return 0;
}
/**
* main
*/
int main(int argc, char *argv[])
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
struct mysqlfs_opt opt = {
.init_conns = 1,
.max_idling_conns = 5,
.mycnf_group = "mysqlfs",
.logfile = "mysqlfs.log",
};
log_file = stderr;
fuse_opt_parse(&args, &opt, mysqlfs_opts, mysqlfs_opt_proc);
fuse_opt_add_arg(&args, "-oallow_other");
fuse_opt_add_arg(&args, "-odefault_permissions");
if (pool_init(&opt) < 0) {
log_printf(LOG_ERROR, "Error: pool_init() failed\n");
fuse_opt_free_args(&args);
return EXIT_FAILURE;
}
/*
* I found that -- running from a script (ie no term?) -- the MySQLfs would not background, so the terminal is held; this makes automated testing difficult.
*
* I (allanc) put this into here to allow for AUTOTEST, but then autotest has to seek-and-destroy the app. This isn't quite perfect yet, I get some flakiness here, othertines the pid is 4 more than the parent, which is odd.
*/
if (0 < opt.bg)
{
if (0 < fork())
return EXIT_SUCCESS;
//else
// fprintf (stderr, "forked %d\n", getpid());
}
log_file = log_init(opt.logfile, 1);
fuse_main(args.argc, args.argv, &mysqlfs_oper, NULL);
fuse_opt_free_args(&args);
pool_cleanup();
return EXIT_SUCCESS;
}