Skip to content

Commit 57a7d03

Browse files
committed
kvs: support fence-max-ops
Problem: The new transaction-max-ops configuration limits the number of operations a user can submit in a KVS commit or fence. However, this does not cap the total number of operations from a combined fence, which could exceed the transaction-max-ops by a lot. Support a new KVS configuration "fence-max-ops" that will reject KVS fences with a combined number of options above a maximum. The default maximum is 1048576.
1 parent f77dd6b commit 57a7d03

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/modules/kvs/kvs.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const double max_namespace_age = 3600.;
6767
/* Transaction max ops
6868
*/
6969
const uint64_t kvs_transaction_max_ops = 65536;
70+
const uint64_t kvs_fence_max_ops = 1048576;
7071

7172
struct kvs_ctx {
7273
struct cache *cache; /* blobref => cache_entry */
@@ -79,6 +80,7 @@ struct kvs_ctx {
7980
flux_watcher_t *check_w;
8081
int transaction_merge;
8182
uint64_t transaction_max_ops;
83+
uint64_t fence_max_ops;
8284
bool events_init; /* flag */
8385
char *hash_name;
8486
unsigned int seq; /* for commit transactions */
@@ -192,6 +194,7 @@ static struct kvs_ctx *kvs_ctx_create (flux_t *h)
192194
}
193195
ctx->transaction_merge = 1;
194196
ctx->transaction_max_ops = kvs_transaction_max_ops;
197+
ctx->fence_max_ops = kvs_fence_max_ops;
195198
if (!(ctx->requests = msg_hash_create (MSG_HASH_TYPE_UUID_MATCHTAG)))
196199
goto error;
197200
list_head_init (&ctx->work_queue);
@@ -1927,6 +1930,11 @@ static void relayfence_request_cb (flux_t *h,
19271930
* earlier */
19281931
assert (!treq_get_processed (tr));
19291932

1933+
if (json_array_size (treq_get_ops (tr)) > ctx->fence_max_ops) {
1934+
errno = E2BIG;
1935+
goto error;
1936+
}
1937+
19301938
/* we use this flag to indicate if a treq has been added to
19311939
* the ready queue */
19321940
treq_set_processed (tr, true);
@@ -2053,6 +2061,11 @@ static void fence_request_cb (flux_t *h,
20532061
* earlier */
20542062
assert (!treq_get_processed (tr));
20552063

2064+
if (json_array_size (treq_get_ops (tr)) > ctx->fence_max_ops) {
2065+
errno = E2BIG;
2066+
goto error_all;
2067+
}
2068+
20562069
/* we use this flag to indicate if a treq has been added to
20572070
* the ready queue */
20582071
treq_set_processed (tr, true);
@@ -3140,20 +3153,27 @@ static int max_ops_parse (struct kvs_ctx *ctx,
31403153
flux_error_t *errp)
31413154
{
31423155
uint64_t t_max_ops = kvs_transaction_max_ops;
3156+
uint64_t f_max_ops = kvs_fence_max_ops;
31433157
flux_error_t error;
31443158
if (flux_conf_unpack (conf,
31453159
&error,
3146-
"{s?{s?I}}",
3160+
"{s?{s?I s?I}}",
31473161
"kvs",
3148-
"transaction-max-ops", &t_max_ops) < 0) {
3162+
"transaction-max-ops", &t_max_ops,
3163+
"fence-max-ops", &f_max_ops) < 0) {
31493164
errprintf (errp, "error reading config for kvs: %s", error.text);
31503165
return -1;
31513166
}
31523167
if (t_max_ops <= 0) {
31533168
errprintf (errp, "kvs transaction-max-ops invalid");
31543169
return -1;
31553170
}
3171+
if (f_max_ops <= 0) {
3172+
errprintf (errp, "kvs fence-max-ops invalid");
3173+
return -1;
3174+
}
31563175
ctx->transaction_max_ops = t_max_ops;
3176+
ctx->fence_max_ops = f_max_ops;
31573177
return 0;
31583178
}
31593179

t/kvs/fence_api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ int main (int argc, char *argv[])
168168
opcount = atoi (optarg);
169169
if (opcount <= 0)
170170
usage ();
171+
break;
171172
default:
172173
usage ();
173174
}

0 commit comments

Comments
 (0)