Originally the Linux kernel was lacking a uniform bitmap API so
Lustre created its own. Todays modern kernels support a standard
bitmap API so migrate tgt_descs to the standard API.
Change-Id: If43b520c29d16355189b1eb7f9fdab7309446545
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/38981
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Lai Siyao <lai.siyao@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
]) # LIBCFS_WAIT_VAR_EVENT
#
]) # LIBCFS_WAIT_VAR_EVENT
#
+# LIBCFS_BITMAP_ALLOC
+#
+# Kernel version 4.17 commit c42b65e363ce97a828f81b59033c3558f8fa7f70
+# added bitmap memory allocation handling.
+#
+AC_DEFUN([LIBCFS_BITMAP_ALLOC], [
+LB_CHECK_COMPILE([if Linux bitmap memory management exist],
+bitmap_alloc, [
+ #include <linux/bitmap.h>
+],[
+ unsigned long *map = bitmap_alloc(1, GFP_KERNEL);
+],[
+ AC_DEFINE(HAVE_BITMAP_ALLOC, 1,
+ [Linux bitmap can be allocated])
+])
+]) # LIBCFS_BITMAP_ALLOC
+
+#
# LIBCFS_CLEAR_AND_WAKE_UP_BIT
#
# Kernel version 4.17-rc2 commit 8236b0ae31c837d2b3a2565c5f8d77f637e824cc
# LIBCFS_CLEAR_AND_WAKE_UP_BIT
#
# Kernel version 4.17-rc2 commit 8236b0ae31c837d2b3a2565c5f8d77f637e824cc
# 4.16
LIBCFS_WAIT_VAR_EVENT
# 4.17
# 4.16
LIBCFS_WAIT_VAR_EVENT
# 4.17
LIBCFS_CLEAR_AND_WAKE_UP_BIT
# 4.19
LIBCFS_XARRAY_SUPPORT
LIBCFS_CLEAR_AND_WAKE_UP_BIT
# 4.19
LIBCFS_XARRAY_SUPPORT
}
#endif /* !HAVE_MEMALLOC_RECLAIM */
}
#endif /* !HAVE_MEMALLOC_RECLAIM */
+#ifndef HAVE_BITMAP_ALLOC
+static inline unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags)
+{
+ return kmalloc_array(BITS_TO_LONGS(nbits), sizeof(unsigned long),
+ flags);
+}
+
+static inline unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags)
+{
+ return bitmap_alloc(nbits, flags | __GFP_ZERO);
+}
+
+static inline void bitmap_free(const unsigned long *bitmap)
+{
+ kfree(bitmap);
+}
+#endif /* !HAVE_BITMAP_ALLOC */
+
#undef NEED_KTIME_GET_REAL_NS
#endif
#undef NEED_KTIME_GET_REAL_NS
#endif
+/* MOFED has its own bitmap_alloc backport */
+#define HAVE_BITMAP_ALLOC 1
+
#endif
#include <linux/module.h>
#endif
#include <linux/module.h>
/* Size of the lu_tgts array, granted to be a power of 2 */
__u32 ltd_tgts_size;
/* bitmap of TGTs available */
/* Size of the lu_tgts array, granted to be a power of 2 */
__u32 ltd_tgts_size;
/* bitmap of TGTs available */
- struct cfs_bitmap *ltd_tgt_bitmap;
+ unsigned long *ltd_tgt_bitmap;
/* TGTs scheduled to be deleted */
__u32 ltd_death_row;
/* Table refcount used for delayed deletion */
/* TGTs scheduled to be deleted */
__u32 ltd_death_row;
/* Table refcount used for delayed deletion */
- index = find_first_bit(ltd->ltd_tgt_bitmap->data,
- ltd->ltd_tgt_bitmap->size);
- return (index < ltd->ltd_tgt_bitmap->size) ? LTD_TGT(ltd, index) : NULL;
+ index = find_first_bit(ltd->ltd_tgt_bitmap,
+ ltd->ltd_tgts_size);
+ return (index < ltd->ltd_tgts_size) ? LTD_TGT(ltd, index) : NULL;
}
static inline struct lu_tgt_desc *ltd_next_tgt(struct lu_tgt_descs *ltd,
}
static inline struct lu_tgt_desc *ltd_next_tgt(struct lu_tgt_descs *ltd,
return NULL;
index = tgt->ltd_index;
return NULL;
index = tgt->ltd_index;
- LASSERT(index < ltd->ltd_tgt_bitmap->size);
- index = find_next_bit(ltd->ltd_tgt_bitmap->data,
- ltd->ltd_tgt_bitmap->size, index + 1);
- return (index < ltd->ltd_tgt_bitmap->size) ? LTD_TGT(ltd, index) : NULL;
+ LASSERT(index < ltd->ltd_tgts_size);
+ index = find_next_bit(ltd->ltd_tgt_bitmap,
+ ltd->ltd_tgts_size, index + 1);
+ return (index < ltd->ltd_tgts_size) ? LTD_TGT(ltd, index) : NULL;
}
#define ltd_foreach_tgt(ltd, tgt) \
}
#define ltd_foreach_tgt(ltd, tgt) \
static inline struct lu_tgt_desc *
lmv_tgt(struct lmv_obd *lmv, __u32 index)
{
static inline struct lu_tgt_desc *
lmv_tgt(struct lmv_obd *lmv, __u32 index)
{
- return index < lmv->lmv_mdt_descs.ltd_tgt_bitmap->size ?
+ return index < lmv->lmv_mdt_descs.ltd_tgts_size ?
LTD_TGT(&lmv->lmv_mdt_descs, index) : NULL;
}
static inline bool
lmv_mdt0_inited(struct lmv_obd *lmv)
{
LTD_TGT(&lmv->lmv_mdt_descs, index) : NULL;
}
static inline bool
lmv_mdt0_inited(struct lmv_obd *lmv)
{
- return lmv->lmv_mdt_descs.ltd_tgt_bitmap->size > 0 &&
- cfs_bitmap_check(lmv->lmv_mdt_descs.ltd_tgt_bitmap, 0);
+ return lmv->lmv_mdt_descs.ltd_tgts_size > 0 &&
+ test_bit(0, lmv->lmv_mdt_descs.ltd_tgt_bitmap);
}
#define lmv_foreach_tgt(lmv, tgt) ltd_foreach_tgt(&(lmv)->lmv_mdt_descs, tgt)
}
#define lmv_foreach_tgt(lmv, tgt) ltd_foreach_tgt(&(lmv)->lmv_mdt_descs, tgt)
mutex_lock(<d->ltd_mutex);
tgt = LTD_TGT(ltd, idx);
/* check that the index is allocated in the bitmap */
mutex_lock(<d->ltd_mutex);
tgt = LTD_TGT(ltd, idx);
/* check that the index is allocated in the bitmap */
- if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap, idx) || !tgt) {
+ if (!test_bit(idx, ltd->ltd_tgt_bitmap) || !tgt) {
CERROR("%s: device %d is not set up\n", obd->obd_name, idx);
GOTO(out, rc = -EINVAL);
}
CERROR("%s: device %d is not set up\n", obd->obd_name, idx);
GOTO(out, rc = -EINVAL);
}
static int validate_lod_and_idx(struct lod_device *md, __u32 idx)
{
if (unlikely(idx >= md->lod_ost_descs.ltd_tgts_size ||
static int validate_lod_and_idx(struct lod_device *md, __u32 idx)
{
if (unlikely(idx >= md->lod_ost_descs.ltd_tgts_size ||
- !cfs_bitmap_check(md->lod_ost_bitmap, idx))) {
+ !test_bit(idx, md->lod_ost_bitmap))) {
CERROR("%s: bad idx: %d of %d\n", lod2obd(md)->obd_name, idx,
md->lod_ost_descs.ltd_tgts_size);
return -EINVAL;
CERROR("%s: bad idx: %d of %d\n", lod2obd(md)->obd_name, idx,
md->lod_ost_descs.ltd_tgts_size);
return -EINVAL;
}
/* if lmm_stripe_offset is *not* in bitmap */
}
/* if lmm_stripe_offset is *not* in bitmap */
- if (!cfs_bitmap_check(d->lod_ost_bitmap, stripe_offset)) {
+ if (!test_bit(stripe_offset, d->lod_ost_bitmap)) {
CDEBUG(D_LAYOUT, "stripe offset %u not in bitmap\n",
stripe_offset);
GOTO(out, rc = -EINVAL);
CDEBUG(D_LAYOUT, "stripe offset %u not in bitmap\n",
stripe_offset);
GOTO(out, rc = -EINVAL);
/* Sigh, this index is not in the bitmap, let's check
* next available target */
/* Sigh, this index is not in the bitmap, let's check
* next available target */
- if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap, idx) &&
+ if (!test_bit(idx, ltd->ltd_tgt_bitmap) &&
idx != master_index)
continue;
idx != master_index)
continue;
if (j < lod_comp->llc_stripe_count)
continue;
if (j < lod_comp->llc_stripe_count)
continue;
- if (!cfs_bitmap_check(lod->lod_ost_bitmap, index)) {
+ if (!test_bit(index, lod->lod_ost_bitmap)) {
CDEBUG(D_LAYOUT, "ost %d no longer present\n", index);
ret = false;
break;
CDEBUG(D_LAYOUT, "ost %d no longer present\n", index);
ret = false;
break;
if (ltd != NULL) {
if (ltd->ltd_tgts_size > idx &&
if (ltd != NULL) {
if (ltd->ltd_tgts_size > idx &&
- cfs_bitmap_check(ltd->ltd_tgt_bitmap, idx)) {
+ test_bit(idx, ltd->ltd_tgt_bitmap)) {
tgt = LTD_TGT(ltd, idx);
LASSERT(tgt != NULL);
tgt = LTD_TGT(ltd, idx);
LASSERT(tgt != NULL);
for (i = 0; i < lqr->lqr_pool.op_count; i++) {
int next;
for (i = 0; i < lqr->lqr_pool.op_count; i++) {
int next;
- if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap,
- src_pool->op_array[i]))
+ if (!test_bit(src_pool->op_array[i],
+ ltd->ltd_tgt_bitmap))
continue;
tgt = LTD_TGT(ltd, src_pool->op_array[i]);
continue;
tgt = LTD_TGT(ltd, src_pool->op_array[i]);
bool used = false;
int i;
bool used = false;
int i;
- if (!cfs_bitmap_check(lod->lod_ost_bitmap, index)) {
+ if (!test_bit(index, lod->lod_ost_bitmap)) {
QOS_DEBUG("OST%d: been used in conflicting mirror component\n",
index);
return true;
QOS_DEBUG("OST%d: been used in conflicting mirror component\n",
index);
return true;
stripe_idx, array_idx, ost_idx);
if ((ost_idx == LOV_QOS_EMPTY) ||
stripe_idx, array_idx, ost_idx);
if ((ost_idx == LOV_QOS_EMPTY) ||
- !cfs_bitmap_check(m->lod_ost_bitmap, ost_idx))
+ !test_bit(ost_idx, m->lod_ost_bitmap))
continue;
/* Fail Check before osc_precreate() is called
continue;
/* Fail Check before osc_precreate() is called
for (j = 0; j < pool->op_count; j++) {
mdt_idx = pool->op_array[j];
for (j = 0; j < pool->op_count; j++) {
mdt_idx = pool->op_array[j];
- if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap, mdt_idx))
+ if (!test_bit(mdt_idx, ltd->ltd_tgt_bitmap))
continue;
mdt = LTD_TGT(ltd, mdt_idx);
continue;
mdt = LTD_TGT(ltd, mdt_idx);
stripe_idx, pool_idx, mdt_idx);
if (mdt_idx == LOV_QOS_EMPTY ||
stripe_idx, pool_idx, mdt_idx);
if (mdt_idx == LOV_QOS_EMPTY ||
- !cfs_bitmap_check(ltd->ltd_tgt_bitmap, mdt_idx))
+ !test_bit(mdt_idx, ltd->ltd_tgt_bitmap))
continue;
/* do not put >1 objects on one MDT */
continue;
/* do not put >1 objects on one MDT */
i++, array_idx = (array_idx + 1) % lod_comp->llc_stripe_count) {
__u32 ost_idx = lod_comp->llc_ostlist.op_array[array_idx];
i++, array_idx = (array_idx + 1) % lod_comp->llc_stripe_count) {
__u32 ost_idx = lod_comp->llc_ostlist.op_array[array_idx];
- if (!cfs_bitmap_check(m->lod_ost_bitmap, ost_idx)) {
+ if (!test_bit(ost_idx, m->lod_ost_bitmap)) {
i++, array_idx = (array_idx + 1) % ost_count) {
ost_idx = osts->op_array[array_idx];
i++, array_idx = (array_idx + 1) % ost_count) {
ost_idx = osts->op_array[array_idx];
- if (!cfs_bitmap_check(m->lod_ost_bitmap, ost_idx))
+ if (!test_bit(ost_idx, m->lod_ost_bitmap))
continue;
/* Fail Check before osc_precreate() is called
continue;
/* Fail Check before osc_precreate() is called
good_osts = 0;
/* Find all the OSTs that are valid stripe candidates */
for (i = 0; i < osts->op_count; i++) {
good_osts = 0;
/* Find all the OSTs that are valid stripe candidates */
for (i = 0; i < osts->op_count; i++) {
- if (!cfs_bitmap_check(lod->lod_ost_bitmap, osts->op_array[i]))
+ if (!test_bit(osts->op_array[i], lod->lod_ost_bitmap))
continue;
ost = OST_TGT(lod, osts->op_array[i]);
continue;
ost = OST_TGT(lod, osts->op_array[i]);
good_mdts = 0;
/* Find all the MDTs that are valid stripe candidates */
for (i = 0; i < pool->op_count; i++) {
good_mdts = 0;
/* Find all the MDTs that are valid stripe candidates */
for (i = 0; i < pool->op_count; i++) {
- if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap, pool->op_array[i]))
+ if (!test_bit(pool->op_array[i], ltd->ltd_tgt_bitmap))
continue;
mdt = LTD_TGT(ltd, pool->op_array[i]);
continue;
mdt = LTD_TGT(ltd, pool->op_array[i]);
LASSERT(obd != NULL);
lod_getref(ltd); /* released in lod_tgts_seq_stop */
LASSERT(obd != NULL);
lod_getref(ltd); /* released in lod_tgts_seq_stop */
- if (*pos >= ltd->ltd_tgt_bitmap->size)
+ if (*pos >= ltd->ltd_tgts_size)
- *pos = find_next_bit(ltd->ltd_tgt_bitmap->data,
- ltd->ltd_tgt_bitmap->size, *pos);
- if (*pos < ltd->ltd_tgt_bitmap->size)
+ *pos = find_next_bit(ltd->ltd_tgt_bitmap,
+ ltd->ltd_tgts_size, *pos);
+ if (*pos < ltd->ltd_tgts_size)
return LTD_TGT(ltd, *pos);
else
return NULL;
return LTD_TGT(ltd, *pos);
else
return NULL;
struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
&lod->lod_ost_descs;
struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs :
&lod->lod_ost_descs;
- if (*pos >= ltd->ltd_tgt_bitmap->size - 1)
+ if (*pos >= ltd->ltd_tgts_size - 1)
- *pos = find_next_bit(ltd->ltd_tgt_bitmap->data,
- ltd->ltd_tgt_bitmap->size, *pos + 1);
- if (*pos < ltd->ltd_tgt_bitmap->size)
+ *pos = find_next_bit(ltd->ltd_tgt_bitmap,
+ ltd->ltd_tgts_size, *pos + 1);
+ if (*pos < ltd->ltd_tgts_size)
return LTD_TGT(ltd, *pos);
else
return NULL;
return LTD_TGT(ltd, *pos);
else
return NULL;
* the tgt array and bitmap are allocated/grown dynamically as tgts are
* added to the LOD/LMV, see lu_tgt_descs_add()
*/
* the tgt array and bitmap are allocated/grown dynamically as tgts are
* added to the LOD/LMV, see lu_tgt_descs_add()
*/
- ltd->ltd_tgt_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
+ ltd->ltd_tgt_bitmap = bitmap_zalloc(BITS_PER_LONG, GFP_NOFS);
if (!ltd->ltd_tgt_bitmap)
return -ENOMEM;
if (!ltd->ltd_tgt_bitmap)
return -ENOMEM;
- CFS_FREE_BITMAP(ltd->ltd_tgt_bitmap);
+ bitmap_free(ltd->ltd_tgt_bitmap);
for (i = 0; i < TGT_PTRS; i++) {
if (ltd->ltd_tgt_idx[i])
OBD_FREE_PTR(ltd->ltd_tgt_idx[i]);
for (i = 0; i < TGT_PTRS; i++) {
if (ltd->ltd_tgt_idx[i])
OBD_FREE_PTR(ltd->ltd_tgt_idx[i]);
*/
static int lu_tgt_descs_resize(struct lu_tgt_descs *ltd, __u32 newsize)
{
*/
static int lu_tgt_descs_resize(struct lu_tgt_descs *ltd, __u32 newsize)
{
- struct cfs_bitmap *new_bitmap, *old_bitmap = NULL;
+ unsigned long *new_bitmap, *old_bitmap = NULL;
/* someone else has already resize the array */
if (newsize <= ltd->ltd_tgts_size)
return 0;
/* someone else has already resize the array */
if (newsize <= ltd->ltd_tgts_size)
return 0;
- new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
+ new_bitmap = bitmap_zalloc(newsize, GFP_NOFS);
if (!new_bitmap)
return -ENOMEM;
if (ltd->ltd_tgts_size > 0) {
/* the bitmap already exists, copy data from old one */
if (!new_bitmap)
return -ENOMEM;
if (ltd->ltd_tgts_size > 0) {
/* the bitmap already exists, copy data from old one */
- cfs_bitmap_copy(new_bitmap, ltd->ltd_tgt_bitmap);
+ bitmap_copy(new_bitmap, ltd->ltd_tgt_bitmap,
+ ltd->ltd_tgts_size);
old_bitmap = ltd->ltd_tgt_bitmap;
}
ltd->ltd_tgts_size = newsize;
ltd->ltd_tgt_bitmap = new_bitmap;
old_bitmap = ltd->ltd_tgt_bitmap;
}
ltd->ltd_tgts_size = newsize;
ltd->ltd_tgt_bitmap = new_bitmap;
- if (old_bitmap)
- CFS_FREE_BITMAP(old_bitmap);
+ bitmap_free(old_bitmap);
CDEBUG(D_CONFIG, "tgt size: %d\n", ltd->ltd_tgts_size);
CDEBUG(D_CONFIG, "tgt size: %d\n", ltd->ltd_tgts_size);
rc = lu_tgt_descs_resize(ltd, newsize);
if (rc)
RETURN(rc);
rc = lu_tgt_descs_resize(ltd, newsize);
if (rc)
RETURN(rc);
- } else if (cfs_bitmap_check(ltd->ltd_tgt_bitmap, index)) {
+ } else if (test_bit(index, ltd->ltd_tgt_bitmap)) {
}
LTD_TGT(ltd, tgt->ltd_index) = tgt;
}
LTD_TGT(ltd, tgt->ltd_index) = tgt;
- cfs_bitmap_set(ltd->ltd_tgt_bitmap, tgt->ltd_index);
+ set_bit(tgt->ltd_index, ltd->ltd_tgt_bitmap);
ltd->ltd_lov_desc.ld_tgt_count++;
if (tgt->ltd_active)
ltd->ltd_lov_desc.ld_tgt_count++;
if (tgt->ltd_active)
{
lu_qos_del_tgt(<d->ltd_qos, tgt);
LTD_TGT(ltd, tgt->ltd_index) = NULL;
{
lu_qos_del_tgt(<d->ltd_qos, tgt);
LTD_TGT(ltd, tgt->ltd_index) = NULL;
- cfs_bitmap_clear(ltd->ltd_tgt_bitmap, tgt->ltd_index);
+ clear_bit(tgt->ltd_index, ltd->ltd_tgt_bitmap);
ltd->ltd_lov_desc.ld_tgt_count--;
if (tgt->ltd_active)
ltd->ltd_lov_desc.ld_active_tgt_count--;
ltd->ltd_lov_desc.ld_tgt_count--;
if (tgt->ltd_active)
ltd->ltd_lov_desc.ld_active_tgt_count--;