diff options
author | Chengguang Xu <cgxu519@gmx.com> | 2018-07-28 11:15:35 -0400 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2018-08-13 11:55:43 -0400 |
commit | 7bf8f736c8e0f2e854d41838eed12e317fb29963 (patch) | |
tree | acc1000d6ea75354e23d00a6e45c9f9ae337cde8 | |
parent | d5548492902967dd088bd0a21df7d047df10f9f6 (diff) |
ceph: refactor ceph_unreserve_caps()
The code of ceph_unreserve_caps() and error handling in
ceph_reserve_caps() are duplicated, so introduce a helper
__ceph_unreserve_caps() to reduce duplicated code.
Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
-rw-r--r-- | fs/ceph/caps.c | 66 | ||||
-rw-r--r-- | fs/ceph/super.h | 2 |
2 files changed, 37 insertions, 31 deletions
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index f50cc008632a..fb4a19ee5b6d 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c | |||
@@ -156,6 +156,37 @@ void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta) | |||
156 | spin_unlock(&mdsc->caps_list_lock); | 156 | spin_unlock(&mdsc->caps_list_lock); |
157 | } | 157 | } |
158 | 158 | ||
159 | static void __ceph_unreserve_caps(struct ceph_mds_client *mdsc, int nr_caps) | ||
160 | { | ||
161 | struct ceph_cap *cap; | ||
162 | int i; | ||
163 | |||
164 | if (nr_caps) { | ||
165 | BUG_ON(mdsc->caps_reserve_count < nr_caps); | ||
166 | mdsc->caps_reserve_count -= nr_caps; | ||
167 | if (mdsc->caps_avail_count >= | ||
168 | mdsc->caps_reserve_count + mdsc->caps_min_count) { | ||
169 | mdsc->caps_total_count -= nr_caps; | ||
170 | for (i = 0; i < nr_caps; i++) { | ||
171 | cap = list_first_entry(&mdsc->caps_list, | ||
172 | struct ceph_cap, caps_item); | ||
173 | list_del(&cap->caps_item); | ||
174 | kmem_cache_free(ceph_cap_cachep, cap); | ||
175 | } | ||
176 | } else { | ||
177 | mdsc->caps_avail_count += nr_caps; | ||
178 | } | ||
179 | |||
180 | dout("%s: caps %d = %d used + %d resv + %d avail\n", | ||
181 | __func__, | ||
182 | mdsc->caps_total_count, mdsc->caps_use_count, | ||
183 | mdsc->caps_reserve_count, mdsc->caps_avail_count); | ||
184 | BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + | ||
185 | mdsc->caps_reserve_count + | ||
186 | mdsc->caps_avail_count); | ||
187 | } | ||
188 | } | ||
189 | |||
159 | /* | 190 | /* |
160 | * Called under mdsc->mutex. | 191 | * Called under mdsc->mutex. |
161 | */ | 192 | */ |
@@ -283,39 +314,14 @@ out_nomem: | |||
283 | return -ENOMEM; | 314 | return -ENOMEM; |
284 | } | 315 | } |
285 | 316 | ||
286 | int ceph_unreserve_caps(struct ceph_mds_client *mdsc, | 317 | void ceph_unreserve_caps(struct ceph_mds_client *mdsc, |
287 | struct ceph_cap_reservation *ctx) | 318 | struct ceph_cap_reservation *ctx) |
288 | { | 319 | { |
289 | int i; | ||
290 | struct ceph_cap *cap; | ||
291 | |||
292 | dout("unreserve caps ctx=%p count=%d\n", ctx, ctx->count); | 320 | dout("unreserve caps ctx=%p count=%d\n", ctx, ctx->count); |
293 | if (ctx->count) { | 321 | spin_lock(&mdsc->caps_list_lock); |
294 | spin_lock(&mdsc->caps_list_lock); | 322 | __ceph_unreserve_caps(mdsc, ctx->count); |
295 | BUG_ON(mdsc->caps_reserve_count < ctx->count); | 323 | ctx->count = 0; |
296 | mdsc->caps_reserve_count -= ctx->count; | 324 | spin_unlock(&mdsc->caps_list_lock); |
297 | if (mdsc->caps_avail_count >= | ||
298 | mdsc->caps_reserve_count + mdsc->caps_min_count) { | ||
299 | mdsc->caps_total_count -= ctx->count; | ||
300 | for (i = 0; i < ctx->count; i++) { | ||
301 | cap = list_first_entry(&mdsc->caps_list, | ||
302 | struct ceph_cap, caps_item); | ||
303 | list_del(&cap->caps_item); | ||
304 | kmem_cache_free(ceph_cap_cachep, cap); | ||
305 | } | ||
306 | } else { | ||
307 | mdsc->caps_avail_count += ctx->count; | ||
308 | } | ||
309 | ctx->count = 0; | ||
310 | dout("unreserve caps %d = %d used + %d resv + %d avail\n", | ||
311 | mdsc->caps_total_count, mdsc->caps_use_count, | ||
312 | mdsc->caps_reserve_count, mdsc->caps_avail_count); | ||
313 | BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + | ||
314 | mdsc->caps_reserve_count + | ||
315 | mdsc->caps_avail_count); | ||
316 | spin_unlock(&mdsc->caps_list_lock); | ||
317 | } | ||
318 | return 0; | ||
319 | } | 325 | } |
320 | 326 | ||
321 | struct ceph_cap *ceph_get_cap(struct ceph_mds_client *mdsc, | 327 | struct ceph_cap *ceph_get_cap(struct ceph_mds_client *mdsc, |
diff --git a/fs/ceph/super.h b/fs/ceph/super.h index f09dbf2a2e26..9b5f15d20b33 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h | |||
@@ -656,7 +656,7 @@ extern void ceph_caps_finalize(struct ceph_mds_client *mdsc); | |||
656 | extern void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta); | 656 | extern void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta); |
657 | extern int ceph_reserve_caps(struct ceph_mds_client *mdsc, | 657 | extern int ceph_reserve_caps(struct ceph_mds_client *mdsc, |
658 | struct ceph_cap_reservation *ctx, int need); | 658 | struct ceph_cap_reservation *ctx, int need); |
659 | extern int ceph_unreserve_caps(struct ceph_mds_client *mdsc, | 659 | extern void ceph_unreserve_caps(struct ceph_mds_client *mdsc, |
660 | struct ceph_cap_reservation *ctx); | 660 | struct ceph_cap_reservation *ctx); |
661 | extern void ceph_reservation_status(struct ceph_fs_client *client, | 661 | extern void ceph_reservation_status(struct ceph_fs_client *client, |
662 | int *total, int *avail, int *used, | 662 | int *total, int *avail, int *used, |