ceph: Reconstruct the func ceph_reserve_caps.
Drop ignored return value. Fix allocation failure case to not leak. Signed-off-by: Jianpeng Ma <majianpeng@gmail.com> Reviewed-by: Sage Weil <sage@inktank.com>
This commit is contained in:
parent
fb3101b6f0
commit
93faca6ef4
|
@ -147,7 +147,7 @@ void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta)
|
||||||
spin_unlock(&mdsc->caps_list_lock);
|
spin_unlock(&mdsc->caps_list_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ceph_reserve_caps(struct ceph_mds_client *mdsc,
|
void ceph_reserve_caps(struct ceph_mds_client *mdsc,
|
||||||
struct ceph_cap_reservation *ctx, int need)
|
struct ceph_cap_reservation *ctx, int need)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -155,7 +155,6 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc,
|
||||||
int have;
|
int have;
|
||||||
int alloc = 0;
|
int alloc = 0;
|
||||||
LIST_HEAD(newcaps);
|
LIST_HEAD(newcaps);
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
dout("reserve caps ctx=%p need=%d\n", ctx, need);
|
dout("reserve caps ctx=%p need=%d\n", ctx, need);
|
||||||
|
|
||||||
|
@ -174,14 +173,15 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc,
|
||||||
|
|
||||||
for (i = have; i < need; i++) {
|
for (i = have; i < need; i++) {
|
||||||
cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS);
|
cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS);
|
||||||
if (!cap) {
|
if (!cap)
|
||||||
ret = -ENOMEM;
|
break;
|
||||||
goto out_alloc_count;
|
|
||||||
}
|
|
||||||
list_add(&cap->caps_item, &newcaps);
|
list_add(&cap->caps_item, &newcaps);
|
||||||
alloc++;
|
alloc++;
|
||||||
}
|
}
|
||||||
BUG_ON(have + alloc != need);
|
/* we didn't manage to reserve as much as we needed */
|
||||||
|
if (have + alloc != need)
|
||||||
|
pr_warn("reserve caps ctx=%p ENOMEM need=%d got=%d\n",
|
||||||
|
ctx, need, have + alloc);
|
||||||
|
|
||||||
spin_lock(&mdsc->caps_list_lock);
|
spin_lock(&mdsc->caps_list_lock);
|
||||||
mdsc->caps_total_count += alloc;
|
mdsc->caps_total_count += alloc;
|
||||||
|
@ -197,13 +197,6 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc,
|
||||||
dout("reserve caps ctx=%p %d = %d used + %d resv + %d avail\n",
|
dout("reserve caps ctx=%p %d = %d used + %d resv + %d avail\n",
|
||||||
ctx, mdsc->caps_total_count, mdsc->caps_use_count,
|
ctx, mdsc->caps_total_count, mdsc->caps_use_count,
|
||||||
mdsc->caps_reserve_count, mdsc->caps_avail_count);
|
mdsc->caps_reserve_count, mdsc->caps_avail_count);
|
||||||
return 0;
|
|
||||||
|
|
||||||
out_alloc_count:
|
|
||||||
/* we didn't manage to reserve as much as we needed */
|
|
||||||
pr_warning("reserve caps ctx=%p ENOMEM need=%d got=%d\n",
|
|
||||||
ctx, need, have);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ceph_unreserve_caps(struct ceph_mds_client *mdsc,
|
int ceph_unreserve_caps(struct ceph_mds_client *mdsc,
|
||||||
|
|
|
@ -534,7 +534,7 @@ extern int __ceph_caps_mds_wanted(struct ceph_inode_info *ci);
|
||||||
extern void ceph_caps_init(struct ceph_mds_client *mdsc);
|
extern void ceph_caps_init(struct ceph_mds_client *mdsc);
|
||||||
extern void ceph_caps_finalize(struct ceph_mds_client *mdsc);
|
extern void ceph_caps_finalize(struct ceph_mds_client *mdsc);
|
||||||
extern void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta);
|
extern void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta);
|
||||||
extern int ceph_reserve_caps(struct ceph_mds_client *mdsc,
|
extern void ceph_reserve_caps(struct ceph_mds_client *mdsc,
|
||||||
struct ceph_cap_reservation *ctx, int need);
|
struct ceph_cap_reservation *ctx, int need);
|
||||||
extern int ceph_unreserve_caps(struct ceph_mds_client *mdsc,
|
extern int ceph_unreserve_caps(struct ceph_mds_client *mdsc,
|
||||||
struct ceph_cap_reservation *ctx);
|
struct ceph_cap_reservation *ctx);
|
||||||
|
|
Loading…
Reference in New Issue