Commit 677b3672 authored by Christoph Böhmwalder's avatar Christoph Böhmwalder Committed by Jens Axboe

drbd: add context parameter to expect() macro

Originally-from: Andreas Gruenbacher <agruen@linbit.com>
Signed-off-by: default avatarChristoph Böhmwalder <christoph.boehmwalder@linbit.com>
Link: https://lore.kernel.org/r/20221201110349.1282687-6-christoph.boehmwalder@linbit.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent e3fa02d7
...@@ -868,9 +868,9 @@ int __drbd_change_sync(struct drbd_device *device, sector_t sector, int size, ...@@ -868,9 +868,9 @@ int __drbd_change_sync(struct drbd_device *device, sector_t sector, int size,
nr_sectors = get_capacity(device->vdisk); nr_sectors = get_capacity(device->vdisk);
esector = sector + (size >> 9) - 1; esector = sector + (size >> 9) - 1;
if (!expect(sector < nr_sectors)) if (!expect(device, sector < nr_sectors))
goto out; goto out;
if (!expect(esector < nr_sectors)) if (!expect(device, esector < nr_sectors))
esector = nr_sectors - 1; esector = nr_sectors - 1;
lbnr = BM_SECT_TO_BIT(nr_sectors-1); lbnr = BM_SECT_TO_BIT(nr_sectors-1);
......
...@@ -448,7 +448,7 @@ int drbd_bm_init(struct drbd_device *device) ...@@ -448,7 +448,7 @@ int drbd_bm_init(struct drbd_device *device)
sector_t drbd_bm_capacity(struct drbd_device *device) sector_t drbd_bm_capacity(struct drbd_device *device)
{ {
if (!expect(device->bitmap)) if (!expect(device, device->bitmap))
return 0; return 0;
return device->bitmap->bm_dev_capacity; return device->bitmap->bm_dev_capacity;
} }
...@@ -457,7 +457,7 @@ sector_t drbd_bm_capacity(struct drbd_device *device) ...@@ -457,7 +457,7 @@ sector_t drbd_bm_capacity(struct drbd_device *device)
*/ */
void drbd_bm_cleanup(struct drbd_device *device) void drbd_bm_cleanup(struct drbd_device *device)
{ {
if (!expect(device->bitmap)) if (!expect(device, device->bitmap))
return; return;
bm_free_pages(device->bitmap->bm_pages, device->bitmap->bm_number_of_pages); bm_free_pages(device->bitmap->bm_pages, device->bitmap->bm_number_of_pages);
bm_vk_free(device->bitmap->bm_pages); bm_vk_free(device->bitmap->bm_pages);
...@@ -636,7 +636,7 @@ int drbd_bm_resize(struct drbd_device *device, sector_t capacity, int set_new_bi ...@@ -636,7 +636,7 @@ int drbd_bm_resize(struct drbd_device *device, sector_t capacity, int set_new_bi
int err = 0; int err = 0;
bool growing; bool growing;
if (!expect(b)) if (!expect(device, b))
return -ENOMEM; return -ENOMEM;
drbd_bm_lock(device, "resize", BM_LOCKED_MASK); drbd_bm_lock(device, "resize", BM_LOCKED_MASK);
...@@ -757,9 +757,9 @@ unsigned long _drbd_bm_total_weight(struct drbd_device *device) ...@@ -757,9 +757,9 @@ unsigned long _drbd_bm_total_weight(struct drbd_device *device)
unsigned long s; unsigned long s;
unsigned long flags; unsigned long flags;
if (!expect(b)) if (!expect(device, b))
return 0; return 0;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return 0; return 0;
spin_lock_irqsave(&b->bm_lock, flags); spin_lock_irqsave(&b->bm_lock, flags);
...@@ -783,9 +783,9 @@ unsigned long drbd_bm_total_weight(struct drbd_device *device) ...@@ -783,9 +783,9 @@ unsigned long drbd_bm_total_weight(struct drbd_device *device)
size_t drbd_bm_words(struct drbd_device *device) size_t drbd_bm_words(struct drbd_device *device)
{ {
struct drbd_bitmap *b = device->bitmap; struct drbd_bitmap *b = device->bitmap;
if (!expect(b)) if (!expect(device, b))
return 0; return 0;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return 0; return 0;
return b->bm_words; return b->bm_words;
...@@ -794,7 +794,7 @@ size_t drbd_bm_words(struct drbd_device *device) ...@@ -794,7 +794,7 @@ size_t drbd_bm_words(struct drbd_device *device)
unsigned long drbd_bm_bits(struct drbd_device *device) unsigned long drbd_bm_bits(struct drbd_device *device)
{ {
struct drbd_bitmap *b = device->bitmap; struct drbd_bitmap *b = device->bitmap;
if (!expect(b)) if (!expect(device, b))
return 0; return 0;
return b->bm_bits; return b->bm_bits;
...@@ -816,9 +816,9 @@ void drbd_bm_merge_lel(struct drbd_device *device, size_t offset, size_t number, ...@@ -816,9 +816,9 @@ void drbd_bm_merge_lel(struct drbd_device *device, size_t offset, size_t number,
end = offset + number; end = offset + number;
if (!expect(b)) if (!expect(device, b))
return; return;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return; return;
if (number == 0) if (number == 0)
return; return;
...@@ -863,9 +863,9 @@ void drbd_bm_get_lel(struct drbd_device *device, size_t offset, size_t number, ...@@ -863,9 +863,9 @@ void drbd_bm_get_lel(struct drbd_device *device, size_t offset, size_t number,
end = offset + number; end = offset + number;
if (!expect(b)) if (!expect(device, b))
return; return;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return; return;
spin_lock_irq(&b->bm_lock); spin_lock_irq(&b->bm_lock);
...@@ -894,9 +894,9 @@ void drbd_bm_get_lel(struct drbd_device *device, size_t offset, size_t number, ...@@ -894,9 +894,9 @@ void drbd_bm_get_lel(struct drbd_device *device, size_t offset, size_t number,
void drbd_bm_set_all(struct drbd_device *device) void drbd_bm_set_all(struct drbd_device *device)
{ {
struct drbd_bitmap *b = device->bitmap; struct drbd_bitmap *b = device->bitmap;
if (!expect(b)) if (!expect(device, b))
return; return;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return; return;
spin_lock_irq(&b->bm_lock); spin_lock_irq(&b->bm_lock);
...@@ -910,9 +910,9 @@ void drbd_bm_set_all(struct drbd_device *device) ...@@ -910,9 +910,9 @@ void drbd_bm_set_all(struct drbd_device *device)
void drbd_bm_clear_all(struct drbd_device *device) void drbd_bm_clear_all(struct drbd_device *device)
{ {
struct drbd_bitmap *b = device->bitmap; struct drbd_bitmap *b = device->bitmap;
if (!expect(b)) if (!expect(device, b))
return; return;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return; return;
spin_lock_irq(&b->bm_lock); spin_lock_irq(&b->bm_lock);
...@@ -1332,9 +1332,9 @@ static unsigned long bm_find_next(struct drbd_device *device, ...@@ -1332,9 +1332,9 @@ static unsigned long bm_find_next(struct drbd_device *device,
struct drbd_bitmap *b = device->bitmap; struct drbd_bitmap *b = device->bitmap;
unsigned long i = DRBD_END_OF_BITMAP; unsigned long i = DRBD_END_OF_BITMAP;
if (!expect(b)) if (!expect(device, b))
return i; return i;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return i; return i;
spin_lock_irq(&b->bm_lock); spin_lock_irq(&b->bm_lock);
...@@ -1436,9 +1436,9 @@ static int bm_change_bits_to(struct drbd_device *device, const unsigned long s, ...@@ -1436,9 +1436,9 @@ static int bm_change_bits_to(struct drbd_device *device, const unsigned long s,
struct drbd_bitmap *b = device->bitmap; struct drbd_bitmap *b = device->bitmap;
int c = 0; int c = 0;
if (!expect(b)) if (!expect(device, b))
return 1; return 1;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return 0; return 0;
spin_lock_irqsave(&b->bm_lock, flags); spin_lock_irqsave(&b->bm_lock, flags);
...@@ -1582,9 +1582,9 @@ int drbd_bm_test_bit(struct drbd_device *device, const unsigned long bitnr) ...@@ -1582,9 +1582,9 @@ int drbd_bm_test_bit(struct drbd_device *device, const unsigned long bitnr)
unsigned long *p_addr; unsigned long *p_addr;
int i; int i;
if (!expect(b)) if (!expect(device, b))
return 0; return 0;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return 0; return 0;
spin_lock_irqsave(&b->bm_lock, flags); spin_lock_irqsave(&b->bm_lock, flags);
...@@ -1619,9 +1619,9 @@ int drbd_bm_count_bits(struct drbd_device *device, const unsigned long s, const ...@@ -1619,9 +1619,9 @@ int drbd_bm_count_bits(struct drbd_device *device, const unsigned long s, const
* robust in case we screwed up elsewhere, in that case pretend there * robust in case we screwed up elsewhere, in that case pretend there
* was one dirty bit in the requested area, so we won't try to do a * was one dirty bit in the requested area, so we won't try to do a
* local read there (no bitmap probably implies no disk) */ * local read there (no bitmap probably implies no disk) */
if (!expect(b)) if (!expect(device, b))
return 1; return 1;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return 1; return 1;
spin_lock_irqsave(&b->bm_lock, flags); spin_lock_irqsave(&b->bm_lock, flags);
...@@ -1635,7 +1635,7 @@ int drbd_bm_count_bits(struct drbd_device *device, const unsigned long s, const ...@@ -1635,7 +1635,7 @@ int drbd_bm_count_bits(struct drbd_device *device, const unsigned long s, const
bm_unmap(p_addr); bm_unmap(p_addr);
p_addr = bm_map_pidx(b, idx); p_addr = bm_map_pidx(b, idx);
} }
if (expect(bitnr < b->bm_bits)) if (expect(device, bitnr < b->bm_bits))
c += (0 != test_bit_le(bitnr - (page_nr << (PAGE_SHIFT+3)), p_addr)); c += (0 != test_bit_le(bitnr - (page_nr << (PAGE_SHIFT+3)), p_addr));
else else
drbd_err(device, "bitnr=%lu bm_bits=%lu\n", bitnr, b->bm_bits); drbd_err(device, "bitnr=%lu bm_bits=%lu\n", bitnr, b->bm_bits);
...@@ -1668,9 +1668,9 @@ int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr) ...@@ -1668,9 +1668,9 @@ int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr)
unsigned long flags; unsigned long flags;
unsigned long *p_addr, *bm; unsigned long *p_addr, *bm;
if (!expect(b)) if (!expect(device, b))
return 0; return 0;
if (!expect(b->bm_pages)) if (!expect(device, b->bm_pages))
return 0; return 0;
spin_lock_irqsave(&b->bm_lock, flags); spin_lock_irqsave(&b->bm_lock, flags);
......
...@@ -1259,7 +1259,7 @@ static int _drbd_send_bitmap(struct drbd_device *device) ...@@ -1259,7 +1259,7 @@ static int _drbd_send_bitmap(struct drbd_device *device)
struct bm_xfer_ctx c; struct bm_xfer_ctx c;
int err; int err;
if (!expect(device->bitmap)) if (!expect(device, device->bitmap))
return false; return false;
if (get_ldev(device)) { if (get_ldev(device)) {
...@@ -2250,9 +2250,9 @@ static void do_retry(struct work_struct *ws) ...@@ -2250,9 +2250,9 @@ static void do_retry(struct work_struct *ws)
bool expected; bool expected;
expected = expected =
expect(atomic_read(&req->completion_ref) == 0) && expect(device, atomic_read(&req->completion_ref) == 0) &&
expect(req->rq_state & RQ_POSTPONED) && expect(device, req->rq_state & RQ_POSTPONED) &&
expect((req->rq_state & RQ_LOCAL_PENDING) == 0 || expect(device, (req->rq_state & RQ_LOCAL_PENDING) == 0 ||
(req->rq_state & RQ_LOCAL_ABORTED) != 0); (req->rq_state & RQ_LOCAL_ABORTED) != 0);
if (!expected) if (!expected)
......
...@@ -1543,7 +1543,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) ...@@ -1543,7 +1543,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
goto fail_unlock; goto fail_unlock;
} }
if (!expect(new_disk_conf->resync_rate >= 1)) if (!expect(device, new_disk_conf->resync_rate >= 1))
new_disk_conf->resync_rate = 1; new_disk_conf->resync_rate = 1;
sanitize_disk_conf(device, new_disk_conf, device->ldev); sanitize_disk_conf(device, new_disk_conf, device->ldev);
......
...@@ -130,10 +130,10 @@ void drbd_dyn_dbg_with_wrong_object_type(void); ...@@ -130,10 +130,10 @@ void drbd_dyn_dbg_with_wrong_object_type(void);
* *
* Unlike the assert macro, this macro returns a boolean result. * Unlike the assert macro, this macro returns a boolean result.
*/ */
#define expect(exp) ({ \ #define expect(x, exp) ({ \
bool _bool = (exp); \ bool _bool = (exp); \
if (!_bool && drbd_ratelimit()) \ if (!_bool && drbd_ratelimit()) \
drbd_err(device, "ASSERTION %s FAILED in %s\n", \ drbd_err(x, "ASSERTION %s FAILED in %s\n", \
#exp, __func__); \ #exp, __func__); \
_bool; \ _bool; \
}) })
......
...@@ -413,7 +413,7 @@ void __drbd_free_peer_req(struct drbd_device *device, struct drbd_peer_request * ...@@ -413,7 +413,7 @@ void __drbd_free_peer_req(struct drbd_device *device, struct drbd_peer_request *
drbd_free_pages(device, peer_req->pages, is_net); drbd_free_pages(device, peer_req->pages, is_net);
D_ASSERT(device, atomic_read(&peer_req->pending_bios) == 0); D_ASSERT(device, atomic_read(&peer_req->pending_bios) == 0);
D_ASSERT(device, drbd_interval_empty(&peer_req->i)); D_ASSERT(device, drbd_interval_empty(&peer_req->i));
if (!expect(!(peer_req->flags & EE_CALL_AL_COMPLETE_IO))) { if (!expect(device, !(peer_req->flags & EE_CALL_AL_COMPLETE_IO))) {
peer_req->flags &= ~EE_CALL_AL_COMPLETE_IO; peer_req->flags &= ~EE_CALL_AL_COMPLETE_IO;
drbd_al_complete_io(device, &peer_req->i); drbd_al_complete_io(device, &peer_req->i);
} }
...@@ -1873,21 +1873,21 @@ read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector, ...@@ -1873,21 +1873,21 @@ read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector,
/* assume request_size == data_size, but special case trim. */ /* assume request_size == data_size, but special case trim. */
ds = data_size; ds = data_size;
if (trim) { if (trim) {
if (!expect(data_size == 0)) if (!expect(peer_device, data_size == 0))
return NULL; return NULL;
ds = be32_to_cpu(trim->size); ds = be32_to_cpu(trim->size);
} else if (zeroes) { } else if (zeroes) {
if (!expect(data_size == 0)) if (!expect(peer_device, data_size == 0))
return NULL; return NULL;
ds = be32_to_cpu(zeroes->size); ds = be32_to_cpu(zeroes->size);
} }
if (!expect(IS_ALIGNED(ds, 512))) if (!expect(peer_device, IS_ALIGNED(ds, 512)))
return NULL; return NULL;
if (trim || zeroes) { if (trim || zeroes) {
if (!expect(ds <= (DRBD_MAX_BBIO_SECTORS << 9))) if (!expect(peer_device, ds <= (DRBD_MAX_BBIO_SECTORS << 9)))
return NULL; return NULL;
} else if (!expect(ds <= DRBD_MAX_BIO_SIZE)) } else if (!expect(peer_device, ds <= DRBD_MAX_BIO_SIZE))
return NULL; return NULL;
/* even though we trust out peer, /* even though we trust out peer,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment