Skip to content

Commit c056fb8

Browse files
committed
check bucket exist at the beginning
1 parent c5e0568 commit c056fb8

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

src/s3fs.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ static int s3fs_getxattr(const char* path, const char* name, char* value, size_t
217217
#endif
218218
static int s3fs_listxattr(const char* path, char* list, size_t size);
219219
static int s3fs_removexattr(const char* path, const char* name);
220+
static void s3fs_exit_fuseloop(int exit_status);
220221

221222
//-------------------------------------------------------------------
222223
// Functions
@@ -3305,6 +3306,14 @@ static int s3fs_removexattr(const char* path, const char* name)
33053306

33063307
static void* s3fs_init(struct fuse_conn_info* conn)
33073308
{
3309+
// check bucket
3310+
{
3311+
int result;
3312+
if (EXIT_SUCCESS != (result = s3fs_check_service())) {
3313+
s3fs_exit_fuseloop(result);
3314+
return NULL;
3315+
}
3316+
}
33083317
// Investigate system capabilities
33093318
#ifndef __APPLE__
33103319
if((unsigned int)conn->capable & FUSE_CAP_ATOMIC_O_TRUNC){
@@ -3632,12 +3641,6 @@ static int s3fs_check_service(void)
36323641
{
36333642
S3FS_PRN_INFO("check services.");
36343643

3635-
// At first time for access S3, we check RAM role if it sets.
3636-
if(!S3fsCurl::CheckRAMCredentialUpdate()){
3637-
S3FS_PRN_CRIT("Failed to check RAM role name(%s).", S3fsCurl::GetRAMRole());
3638-
return EXIT_FAILURE;
3639-
}
3640-
36413644
S3fsCurl s3fscurl;
36423645
int res;
36433646
if(0 > (res = s3fscurl.CheckBucket())){
@@ -3661,18 +3664,6 @@ static int s3fs_check_service(void)
36613664
}
36623665
}
36633666

3664-
// try signature v2
3665-
if(0 > res && (responseCode == 400 || responseCode == 403) && S3fsCurl::IsSignatureV4()){
3666-
// switch sigv2
3667-
S3FS_PRN_WARN("Could not connect, so retry to connect by signature version 2.");
3668-
S3fsCurl::SetSignatureV4(false);
3669-
3670-
// retry to check with sigv2
3671-
s3fscurl.DestroyCurlHandle();
3672-
res = s3fscurl.CheckBucket();
3673-
responseCode = s3fscurl.GetLastResponseCode();
3674-
}
3675-
36763667
// check errors(after retrying)
36773668
if(0 > res && responseCode != 200 && responseCode != 301){
36783669
if(responseCode == 400){
@@ -4601,6 +4592,19 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
46014592
return 1;
46024593
}
46034594

4595+
// s3fs_init calls this function to exit cleanly from the fuse event loop.
4596+
// //
4597+
// // There's no way to pass an exit status to the high-level event loop API, so
4598+
// // this function stores the exit value in a global for main()
4599+
static void s3fs_exit_fuseloop(int exit_status) {
4600+
S3FS_PRN_ERR("Exiting FUSE event loop due to errors\n");
4601+
s3fs_init_deferred_exit_status = exit_status;
4602+
struct fuse_context *ctx = fuse_get_context();
4603+
if (NULL != ctx) {
4604+
fuse_exit(ctx->fuse);
4605+
}
4606+
}
4607+
46044608
int main(int argc, char* argv[])
46054609
{
46064610
int ch;
@@ -4838,6 +4842,12 @@ int main(int argc, char* argv[])
48384842
S3FS_PRN_EXIT("could not set signal handler for SIGUSR2.");
48394843
exit(EXIT_FAILURE);
48404844
}
4845+
4846+
int result;
4847+
if (EXIT_SUCCESS != (result = s3fs_check_service())) {
4848+
S3FS_PRN_EXIT("bucket not exist, exiting...");
4849+
exit(result);
4850+
}
48414851

48424852
// now passing things off to fuse, fuse will finish evaluating the command line args
48434853
fuse_res = fuse_main(custom_args.argc, custom_args.argv, &s3fs_oper, NULL);

0 commit comments

Comments
 (0)