Skip to content

Commit d46c251

Browse files
committed
support traffic limit option.
1 parent fc4801f commit d46c251

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

doc/man/ossfs.1.in

+8
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ Specify the path of the mime.types file.
316316
If this option is not specified, the existence of "/etc/mime.types" is checked, and that file is loaded as mime information.
317317
If this file does not exist on macOS, then "/etc/apache2/mime.types" is checked as well.
318318
.TP
319+
\fB\-o\fR upload_traffic_limit (default="0")
320+
The single-connection bandwidth throttling, in bit/s, for each upload request.
321+
The minimum value is 819200 bit/s and the maximum value is 838860800 bit/s. 0 value means disable.
322+
.TP
323+
\fB\-o\fR download_traffic_limit (default="0")
324+
The single-connection bandwidth throttling, in bit/s, for each download request.
325+
The minimum value is 819200 bit/s and the maximum value is 838860800 bit/s. 0 value means disable.
326+
.TP
319327
\fB\-o\fR logfile - specify the log output file.
320328
ossfs outputs the log file to syslog. Alternatively, if ossfs is started with the "-f" option specified, the log will be output to the stdout/stderr.
321329
You can use this option to specify the log file that ossfs outputs.

src/curl.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ bool S3fsCurl::is_ua = true; // default
120120
bool S3fsCurl::listobjectsv2 = false; // default
121121
bool S3fsCurl::requester_pays = false; // default
122122

123+
long S3fsCurl::upload_traffic_limit = 0; // default
124+
long S3fsCurl::download_traffic_limit = 0; // default
125+
123126
//-------------------------------------------------------------------
124127
// Class methods for S3fsCurl
125128
//-------------------------------------------------------------------
@@ -3344,6 +3347,11 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
33443347
// set additional header by ahbe conf
33453348
requestHeaders = AdditionalHeader::get()->AddHeader(requestHeaders, tpath);
33463349
}
3350+
if(S3fsCurl::upload_traffic_limit != 0) {
3351+
char buff[64];
3352+
sprintf(buff, "%ld", S3fsCurl::upload_traffic_limit);
3353+
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-oss-traffic-limit", buff);
3354+
}
33473355

33483356
op = "PUT";
33493357
type = REQTYPE_PUT;
@@ -3417,6 +3425,12 @@ int S3fsCurl::PreGetObjectRequest(const char* tpath, int fd, off_t start, off_t
34173425
S3FS_PRN_WARN("Failed to set SSE header, but continue...");
34183426
}
34193427

3428+
if(S3fsCurl::download_traffic_limit != 0) {
3429+
char buff[64];
3430+
sprintf(buff, "%ld", S3fsCurl::download_traffic_limit);
3431+
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-oss-traffic-limit", buff);
3432+
}
3433+
34203434
op = "GET";
34213435
type = REQTYPE_GET;
34223436

@@ -3931,6 +3945,12 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const st
39313945
}
39323946
}
39333947

3948+
if(S3fsCurl::upload_traffic_limit != 0) {
3949+
char buff[64];
3950+
sprintf(buff, "%ld", S3fsCurl::upload_traffic_limit);
3951+
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-oss-traffic-limit", buff);
3952+
}
3953+
39343954
requestHeaders = curl_slist_sort_insert(requestHeaders, "Accept", NULL);
39353955

39363956
op = "PUT";

src/curl.h

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ class S3fsCurl
156156
static bool is_ua; // User-Agent
157157
static bool listobjectsv2;
158158
static bool requester_pays;
159+
static long upload_traffic_limit;
160+
static long download_traffic_limit;
159161

160162
// variables
161163
CURL* hCurl;
@@ -334,6 +336,8 @@ class S3fsCurl
334336
static bool IsListObjectsV2() { return S3fsCurl::listobjectsv2; }
335337
static bool SetRequesterPays(bool flag) { bool old_flag = S3fsCurl::requester_pays; S3fsCurl::requester_pays = flag; return old_flag; }
336338
static bool IsRequesterPays() { return S3fsCurl::requester_pays; }
339+
static bool SetUploadTrafficLimit(long value) { bool old_value = S3fsCurl::upload_traffic_limit; S3fsCurl::upload_traffic_limit = value; return old_value; }
340+
static bool SetDownloadTrafficLimit(long value) { bool old_value = S3fsCurl::download_traffic_limit; S3fsCurl::download_traffic_limit = value; return old_value; }
337341

338342
// methods
339343
bool CreateCurlHandle(bool only_pool = false, bool remake = false);

src/s3fs.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -4294,6 +4294,16 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
42944294
mimetype_file = strchr(arg, '=') + sizeof(char);
42954295
return 0;
42964296
}
4297+
if(is_prefix(arg, "upload_traffic_limit=")){
4298+
long traffic_limit = static_cast<long>(cvt_strtoofft(strchr(arg, '=') + sizeof(char), /*base=*/ 10));
4299+
S3fsCurl::SetUploadTrafficLimit(traffic_limit);
4300+
return 0;
4301+
}
4302+
if(is_prefix(arg, "download_traffic_limit=")){
4303+
long traffic_limit = static_cast<long>(cvt_strtoofft(strchr(arg, '=') + sizeof(char), /*base=*/ 10));
4304+
S3fsCurl::SetDownloadTrafficLimit(traffic_limit);
4305+
return 0;
4306+
}
42974307
//
42984308
// log file option
42994309
//

src/s3fs_help.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,16 @@ static const char help_string[] =
393393
" If this file does not exist on macOS, then \"/etc/apache2/mime.types\"\n"
394394
" is checked as well.\n"
395395
"\n"
396+
" upload_traffic_limit (default=\"0\")\n"
397+
" The single-connection bandwidth throttling, in bit/s, for each upload request.\n"
398+
" The minimum value is 819200 bit/s and the maximum value is 838860800 bit/s.\n"
399+
" 0 value means disable.\n"
400+
"\n"
401+
" download_traffic_limit (default=\"0\")\n"
402+
" The single-connection bandwidth throttling, in bit/s, for each download request.\n"
403+
" The minimum value is 819200 bit/s and the maximum value is 838860800 bit/s.\n"
404+
" 0 value means disable.\n"
405+
"\n"
396406
" logfile - specify the log output file.\n"
397407
" ossfs outputs the log file to syslog. Alternatively, if ossfs is\n"
398408
" started with the \"-f\" option specified, the log will be output\n"

0 commit comments

Comments
 (0)