175
168
* dev_printk() expects to be presented a struct device *;
176
169
* in older kernels, (<= 2.6.24), there is nothing suitable there.
177
170
* "backport" hack: redefine dev_printk.
178
* Trigger is definition of dev_to_disk marcro, introduced with the
171
* Trigger is definition of dev_to_disk macro, introduced with the
179
172
* commit edfaa7c36574f1bf09c65ad602412db9da5f96bf
180
173
* Driver core: convert block from raw kobjects to core devices
266
259
extern void trace_drbd_resync(struct drbd_conf *mdev, int level, const char *fmt, ...);
268
#ifdef DRBD_ENABLE_FAULTS
269
261
extern unsigned int
270
262
_drbd_insert_fault(struct drbd_conf *mdev, unsigned int type);
271
264
static inline int
272
265
drbd_insert_fault(struct drbd_conf *mdev, unsigned int type) {
266
#ifdef DRBD_ENABLE_FAULTS
273
267
return fault_rate &&
274
268
(enable_faults & (1<<type)) &&
275
269
_drbd_insert_fault(mdev, type);
277
#define FAULT_ACTIVE(_m, _t) (drbd_insert_fault((_m), (_t)))
280
#define FAULT_ACTIVE(_m, _t) (0)
283
275
/* integer division, round _UP_ to the next integer */
284
276
#define div_ceil(A, B) ((A)/(B) + ((A)%(B) ? 1 : 0))
356
348
/* P_CKPT_FENCE_REQ = 0x25, * currently reserved for protocol D */
357
349
/* P_CKPT_DISABLE_REQ = 0x26, * currently reserved for protocol D */
358
350
P_DELAY_PROBE = 0x27, /* is used on BOTH sockets */
351
P_OUT_OF_SYNC = 0x28, /* Mark as out of sync (Outrunning), data socket */
352
P_RS_CANCEL = 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */
361
355
P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
362
356
P_MAX_OPT_CMD = 0x101,
656
651
u64 d_size; /* size of disk */
657
652
u64 u_size; /* user requested size */
658
653
u64 c_size; /* current exported size */
659
u32 max_segment_size; /* Maximal size of a BIO */
654
u32 max_bio_size; /* Maximal size of a BIO */
660
655
u16 queue_order_type; /* not yet implemented in DRBD*/
661
656
u16 dds_flags; /* use enum dds_flags here. */
763
765
/* one bitmap packet, including the p_header,
764
* should fit within one _architecture independend_ page.
766
* should fit within one _architecture independent_ page.
765
767
* so we need to use the fixed size 4KiB page size
766
* most architechtures have used for a long time.
768
* most architectures have used for a long time.
768
770
#define BM_PACKET_PAYLOAD_BYTES (4096 - sizeof(struct p_header80))
769
771
#define BM_PACKET_WORDS (BM_PACKET_PAYLOAD_BYTES/sizeof(long))
1010
1002
* if set, also prevents the device from dying */
1011
1003
DEVICE_DYING, /* device became unconfigured,
1012
1004
* but worker thread is still handling the cleanup.
1013
* reconfiguring (nl_disk_conf, nl_net_conf) is dissalowed,
1005
* reconfiguring (nl_disk_conf, nl_net_conf) is disallowed,
1014
1006
* while this is set. */
1015
1007
RESIZE_PENDING, /* Size change detected locally, waiting for the response from
1016
1008
* the peer, if it changed there as well. */
1018
1010
GOT_PING_ACK, /* set when we receive a ping_ack packet, misc wait gets woken */
1019
1011
NEW_CUR_UUID, /* Create new current UUID when thawing IO */
1020
1012
AL_SUSPENDED, /* Activity logging is currently suspended. */
1013
AHEAD_TO_SYNC_SOURCE, /* Ahead -> SyncSource queued */
1023
1016
struct drbd_bitmap; /* opaque for drbd_conf */
1018
/* definition of bits in bm_flags to be used in drbd_bm_lock
1019
* and drbd_bitmap_io and friends. */
1021
/* do we need to kfree, or vfree bm_pages? */
1022
BM_P_VMALLOCED = 0x10000, /* internal use only, will be masked out */
1024
/* currently locked for bulk operation */
1025
BM_LOCKED_MASK = 0x7,
1027
/* in detail, that is: */
1028
BM_DONT_CLEAR = 0x1,
1032
/* (test bit, count bit) allowed (common case) */
1033
BM_LOCKED_TEST_ALLOWED = 0x3,
1035
/* testing bits, as well as setting new bits allowed, but clearing bits
1036
* would be unexpected. Used during bitmap receive. Setting new bits
1037
* requires sending of "out-of-sync" information, though. */
1038
BM_LOCKED_SET_ALLOWED = 0x1,
1040
/* clear is not expected while bitmap is locked for bulk operation */
1025
1044
/* TODO sort members for performance
1026
1045
* MAYBE group them further */
1162
1183
atomic_t ap_bio_cnt; /* Requests we need to complete */
1163
1184
atomic_t ap_pending_cnt; /* AP data packets on the wire, ack expected */
1164
1185
atomic_t rs_pending_cnt; /* RS request/data packets on the wire */
1165
atomic_t unacked_cnt; /* Need to send replys for */
1186
atomic_t unacked_cnt; /* Need to send replies for */
1166
1187
atomic_t local_cnt; /* Waiting for local completion */
1167
1188
atomic_t net_cnt; /* Users of net_conf */
1168
1189
spinlock_t req_lock;
1230
1251
struct list_head done_ee; /* send ack */
1231
1252
struct list_head read_ee; /* IO in progress (any read) */
1232
1253
struct list_head net_ee; /* zero-copy network send in progress */
1233
struct hlist_head *ee_hash; /* is proteced by req_lock! */
1254
struct hlist_head *ee_hash; /* is protected by req_lock! */
1234
1255
unsigned int ee_hash_s;
1236
1257
/* this one is protected by ee_lock, single thread */
1237
1258
struct drbd_epoch_entry *last_write_w_barrier;
1239
1260
int next_barrier_nr;
1240
struct hlist_head *app_reads_hash; /* is proteced by req_lock */
1261
struct hlist_head *app_reads_hash; /* is protected by req_lock */
1241
1262
struct list_head resync_reads;
1242
1263
atomic_t pp_in_use; /* allocated from page pool */
1243
1264
atomic_t pp_in_use_by_net; /* sendpage()d, still referenced by tcp */
1280
1301
int c_sync_rate; /* current resync rate after syncer throttle magic */
1281
1302
struct fifo_buffer rs_plan_s; /* correction values of resync planer */
1282
1303
int rs_in_flight; /* resync sectors in flight (to proxy, in proxy and from proxy) */
1283
int rs_planed; /* resync sectors already planed */
1304
int rs_planed; /* resync sectors already planned */
1305
atomic_t ap_in_flight; /* App sectors in flight (waiting for ack) */
1306
int peer_max_bio_size;
1307
int local_max_bio_size;
1286
1310
static inline struct drbd_conf *minor_to_mdev(unsigned int minor)
1344
1368
extern void drbd_init_set_defaults(struct drbd_conf *mdev);
1345
extern int drbd_change_state(struct drbd_conf *mdev, enum chg_state_flags f,
1346
union drbd_state mask, union drbd_state val);
1369
extern enum drbd_state_rv drbd_change_state(struct drbd_conf *mdev,
1370
enum chg_state_flags f,
1371
union drbd_state mask,
1372
union drbd_state val);
1347
1373
extern void drbd_force_state(struct drbd_conf *, union drbd_state,
1348
1374
union drbd_state);
1349
extern int _drbd_request_state(struct drbd_conf *, union drbd_state,
1350
union drbd_state, enum chg_state_flags);
1351
extern int __drbd_set_state(struct drbd_conf *, union drbd_state,
1352
enum chg_state_flags, struct completion *done);
1375
extern enum drbd_state_rv _drbd_request_state(struct drbd_conf *,
1378
enum chg_state_flags);
1379
extern enum drbd_state_rv __drbd_set_state(struct drbd_conf *, union drbd_state,
1380
enum chg_state_flags,
1381
struct completion *done);
1353
1382
extern void print_st_err(struct drbd_conf *, union drbd_state,
1354
1383
union drbd_state, int);
1355
1384
extern int drbd_thread_start(struct drbd_thread *thi);
1365
1394
extern void tl_release(struct drbd_conf *mdev, unsigned int barrier_nr,
1366
1395
unsigned int set_size);
1367
1396
extern void tl_clear(struct drbd_conf *mdev);
1368
enum drbd_req_event;
1369
extern void tl_restart(struct drbd_conf *mdev, enum drbd_req_event what);
1370
1397
extern void _tl_add_barrier(struct drbd_conf *, struct drbd_tl_epoch *);
1371
1398
extern void drbd_free_sock(struct drbd_conf *mdev);
1372
1399
extern int drbd_send(struct drbd_conf *mdev, struct socket *sock,
1374
1401
extern int drbd_send_protocol(struct drbd_conf *mdev);
1375
1402
extern int drbd_send_uuids(struct drbd_conf *mdev);
1376
1403
extern int drbd_send_uuids_skip_initial_sync(struct drbd_conf *mdev);
1377
extern int drbd_send_sync_uuid(struct drbd_conf *mdev, u64 val);
1404
extern int drbd_gen_and_send_sync_uuid(struct drbd_conf *mdev);
1378
1405
extern int drbd_send_sizes(struct drbd_conf *mdev, int trigger_reply, enum dds_flags flags);
1379
1406
#define drbd_send_state(m) drbd_send_state_(m, __func__ , __LINE__ )
1380
1407
extern int drbd_send_state_(struct drbd_conf *mdev, const char *func, unsigned int line);
1399
1426
struct p_data *dp, int data_size);
1400
1427
extern int drbd_send_ack_ex(struct drbd_conf *mdev, enum drbd_packets cmd,
1401
1428
sector_t sector, int blksize, u64 block_id);
1429
extern int drbd_send_oos(struct drbd_conf *mdev, struct drbd_request *req);
1402
1430
extern int drbd_send_block(struct drbd_conf *mdev, enum drbd_packets cmd,
1403
1431
struct drbd_epoch_entry *e);
1404
1432
extern int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req);
1405
extern int _drbd_send_barrier(struct drbd_conf *mdev,
1406
struct drbd_tl_epoch *barrier);
1407
1433
extern int drbd_send_drequest(struct drbd_conf *mdev, int cmd,
1408
1434
sector_t sector, int size, u64 block_id);
1409
1435
extern int drbd_send_drequest_csum(struct drbd_conf *mdev,
1415
1441
extern int drbd_send_bitmap(struct drbd_conf *mdev);
1416
1442
extern int _drbd_send_bitmap(struct drbd_conf *mdev);
1417
extern int drbd_send_sr_reply(struct drbd_conf *mdev, int retcode);
1443
extern int drbd_send_sr_reply(struct drbd_conf *mdev, enum drbd_state_rv retcode);
1418
1444
extern void drbd_free_bc(struct drbd_backing_dev *ldev);
1419
1445
extern void drbd_mdev_cleanup(struct drbd_conf *mdev);
1446
void drbd_print_uuids(struct drbd_conf *mdev, const char *text);
1421
/* drbd_meta-data.c (still in drbd_main.c) */
1422
1448
extern void drbd_md_sync(struct drbd_conf *mdev);
1423
1449
extern int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev);
1424
/* maybe define them below as inline? */
1425
1450
extern void drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local);
1426
1451
extern void _drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local);
1427
1452
extern void drbd_uuid_new_current(struct drbd_conf *mdev) __must_hold(local);
1440
1465
extern void drbd_queue_bitmap_io(struct drbd_conf *mdev,
1441
1466
int (*io_fn)(struct drbd_conf *),
1442
1467
void (*done)(struct drbd_conf *, int),
1468
char *why, enum bm_flag flags);
1469
extern int drbd_bitmap_io(struct drbd_conf *mdev,
1470
int (*io_fn)(struct drbd_conf *),
1471
char *why, enum bm_flag flags);
1444
1472
extern int drbd_bmio_set_n_write(struct drbd_conf *mdev);
1445
1473
extern int drbd_bmio_clear_n_write(struct drbd_conf *mdev);
1446
extern int drbd_bitmap_io(struct drbd_conf *mdev, int (*io_fn)(struct drbd_conf *), char *why);
1447
1474
extern void drbd_go_diskless(struct drbd_conf *mdev);
1448
1475
extern void drbd_ldev_destroy(struct drbd_conf *mdev);
1589
1620
extern void drbd_bm_cleanup(struct drbd_conf *mdev);
1590
1621
extern void drbd_bm_set_all(struct drbd_conf *mdev);
1591
1622
extern void drbd_bm_clear_all(struct drbd_conf *mdev);
1623
/* set/clear/test only a few bits at a time */
1592
1624
extern int drbd_bm_set_bits(
1593
1625
struct drbd_conf *mdev, unsigned long s, unsigned long e);
1594
1626
extern int drbd_bm_clear_bits(
1595
1627
struct drbd_conf *mdev, unsigned long s, unsigned long e);
1596
/* bm_set_bits variant for use while holding drbd_bm_lock */
1628
extern int drbd_bm_count_bits(
1629
struct drbd_conf *mdev, const unsigned long s, const unsigned long e);
1630
/* bm_set_bits variant for use while holding drbd_bm_lock,
1631
* may process the whole bitmap in one go */
1597
1632
extern void _drbd_bm_set_bits(struct drbd_conf *mdev,
1598
1633
const unsigned long s, const unsigned long e);
1599
1634
extern int drbd_bm_test_bit(struct drbd_conf *mdev, unsigned long bitnr);
1600
1635
extern int drbd_bm_e_weight(struct drbd_conf *mdev, unsigned long enr);
1601
extern int drbd_bm_write_sect(struct drbd_conf *mdev, unsigned long enr) __must_hold(local);
1636
extern int drbd_bm_write_page(struct drbd_conf *mdev, unsigned int idx) __must_hold(local);
1602
1637
extern int drbd_bm_read(struct drbd_conf *mdev) __must_hold(local);
1603
1638
extern int drbd_bm_write(struct drbd_conf *mdev) __must_hold(local);
1604
1639
extern unsigned long drbd_bm_ALe_set_all(struct drbd_conf *mdev,
1606
1641
extern size_t drbd_bm_words(struct drbd_conf *mdev);
1607
1642
extern unsigned long drbd_bm_bits(struct drbd_conf *mdev);
1608
1643
extern sector_t drbd_bm_capacity(struct drbd_conf *mdev);
1645
#define DRBD_END_OF_BITMAP (~(unsigned long)0)
1609
1646
extern unsigned long drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo);
1610
1647
/* bm_find_next variants for use while you hold drbd_bm_lock() */
1611
1648
extern unsigned long _drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo);
1616
1653
/* for receive_bitmap */
1617
1654
extern void drbd_bm_merge_lel(struct drbd_conf *mdev, size_t offset,
1618
1655
size_t number, unsigned long *buffer);
1619
/* for _drbd_send_bitmap and drbd_bm_write_sect */
1656
/* for _drbd_send_bitmap */
1620
1657
extern void drbd_bm_get_lel(struct drbd_conf *mdev, size_t offset,
1621
1658
size_t number, unsigned long *buffer);
1623
extern void drbd_bm_lock(struct drbd_conf *mdev, char *why);
1660
extern void drbd_bm_lock(struct drbd_conf *mdev, char *why, enum bm_flag flags);
1624
1661
extern void drbd_bm_unlock(struct drbd_conf *mdev);
1626
extern int drbd_bm_count_bits(struct drbd_conf *mdev, const unsigned long s, const unsigned long e);
1627
1662
/* drbd_main.c */
1629
1664
/* needs to be included here,
1650
1685
extern int proc_details;
1653
extern int drbd_make_request_26(struct request_queue *q, struct bio *bio);
1688
extern int drbd_make_request(struct request_queue *q, struct bio *bio);
1654
1689
extern int drbd_read_remote(struct drbd_conf *mdev, struct drbd_request *req);
1655
1690
extern int drbd_merge_bvec(struct request_queue *q,
1656
1691
#ifdef HAVE_bvec_merge_data
1668
1703
extern char *ppsize(char *buf, unsigned long long size);
1669
1704
extern sector_t drbd_new_dev_size(struct drbd_conf *, struct drbd_backing_dev *, int);
1670
1705
enum determine_dev_size { dev_size_error = -1, unchanged = 0, shrunk = 1, grew = 2 };
1671
extern enum determine_dev_size drbd_determin_dev_size(struct drbd_conf *, enum dds_flags) __must_hold(local);
1706
extern enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *, enum dds_flags) __must_hold(local);
1672
1707
extern void resync_after_online_grow(struct drbd_conf *);
1673
extern void drbd_setup_queue_param(struct drbd_conf *mdev, unsigned int) __must_hold(local);
1674
extern int drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role,
1708
extern void drbd_reconsider_max_bio_size(struct drbd_conf *mdev);
1709
extern enum drbd_state_rv drbd_set_role(struct drbd_conf *mdev,
1710
enum drbd_role new_role,
1676
1712
extern enum drbd_disk_state drbd_try_outdate_peer(struct drbd_conf *mdev);
1677
1713
extern void drbd_try_outdate_peer_async(struct drbd_conf *mdev);
1678
1714
extern int drbd_khelper(struct drbd_conf *mdev, char *cmd);
1688
1724
extern int drbd_md_sync_page_io(struct drbd_conf *mdev,
1689
1725
struct drbd_backing_dev *bdev, sector_t sector, int rw);
1690
1726
extern void drbd_ov_oos_found(struct drbd_conf*, sector_t, int);
1727
extern void drbd_rs_controller_reset(struct drbd_conf *mdev);
1692
1729
static inline void ov_oos_print(struct drbd_conf *mdev)
1711
1748
extern int w_e_end_ov_reply(struct drbd_conf *, struct drbd_work *, int);
1712
1749
extern int w_e_end_ov_req(struct drbd_conf *, struct drbd_work *, int);
1713
1750
extern int w_ov_finished(struct drbd_conf *, struct drbd_work *, int);
1714
extern int w_resync_inactive(struct drbd_conf *, struct drbd_work *, int);
1751
extern int w_resync_timer(struct drbd_conf *, struct drbd_work *, int);
1715
1752
extern int w_resume_next_sg(struct drbd_conf *, struct drbd_work *, int);
1716
1753
extern int w_send_write_hint(struct drbd_conf *, struct drbd_work *, int);
1717
1754
extern int w_make_resync_request(struct drbd_conf *, struct drbd_work *, int);
1721
1758
extern int w_prev_work_done(struct drbd_conf *, struct drbd_work *, int);
1722
1759
extern int w_e_reissue(struct drbd_conf *, struct drbd_work *, int);
1723
1760
extern int w_restart_disk_io(struct drbd_conf *, struct drbd_work *, int);
1761
extern int w_send_oos(struct drbd_conf *, struct drbd_work *, int);
1762
extern int w_start_resync(struct drbd_conf *, struct drbd_work *, int);
1725
1764
extern void resync_timer_fn(unsigned long data);
1765
extern void start_resync_timer_fn(unsigned long data);
1727
1767
/* drbd_receiver.c */
1728
extern int drbd_rs_should_slow_down(struct drbd_conf *mdev);
1768
extern int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector);
1729
1769
extern int drbd_submit_ee(struct drbd_conf *mdev, struct drbd_epoch_entry *e,
1730
1770
const unsigned rw, const int fault_type);
1731
1771
extern int drbd_release_ee(struct drbd_conf *mdev, struct list_head *list);
1808
1848
extern void drbd_rs_failed_io(struct drbd_conf *mdev,
1809
1849
sector_t sector, int size);
1810
1850
extern int drbd_al_read_log(struct drbd_conf *mdev, struct drbd_backing_dev *);
1851
extern void drbd_advance_rs_marks(struct drbd_conf *mdev, unsigned long still_to_go);
1811
1852
extern void __drbd_set_in_sync(struct drbd_conf *mdev, sector_t sector,
1812
1853
int size, const char *file, const unsigned int line);
1813
1854
#define drbd_set_in_sync(mdev, sector, size) \
1814
1855
__drbd_set_in_sync(mdev, sector, size, __FILE__, __LINE__)
1815
extern void __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector,
1856
extern int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector,
1816
1857
int size, const char *file, const unsigned int line);
1817
1858
#define drbd_set_out_of_sync(mdev, sector, size) \
1818
1859
__drbd_set_out_of_sync(mdev, sector, size, __FILE__, __LINE__)
1819
1860
extern void drbd_al_apply_to_bm(struct drbd_conf *mdev);
1820
extern void drbd_al_to_on_disk_bm(struct drbd_conf *mdev);
1821
1861
extern void drbd_al_shrink(struct drbd_conf *mdev);
1947
1987
wake_up(&mdev->misc_wait);
1950
static inline int _drbd_set_state(struct drbd_conf *mdev,
1951
union drbd_state ns, enum chg_state_flags flags,
1952
struct completion *done)
1990
static inline enum drbd_state_rv
1991
_drbd_set_state(struct drbd_conf *mdev, union drbd_state ns,
1992
enum chg_state_flags flags, struct completion *done)
1994
enum drbd_state_rv rv;
1956
1996
read_lock(&global_state_lock);
1957
1997
rv = __drbd_set_state(mdev, ns, flags, done);
1985
2025
if (!forcedetach) {
1986
2026
if (DRBD_ratelimit(5*HZ, 5))
1987
2027
dev_err(DEV, "Local IO failed in %s.\n", where);
2028
if (mdev->state.disk > D_INCONSISTENT)
2029
_drbd_set_state(_NS(mdev, disk, D_INCONSISTENT), CS_HARD, NULL);
1990
2032
/* NOTE fall through to detach case if forcedetach set */
2176
2218
static inline void drbd_thread_stop(struct drbd_thread *thi)
2178
_drbd_thread_stop(thi, FALSE, TRUE);
2220
_drbd_thread_stop(thi, false, true);
2181
2223
static inline void drbd_thread_stop_nowait(struct drbd_thread *thi)
2183
_drbd_thread_stop(thi, FALSE, FALSE);
2225
_drbd_thread_stop(thi, false, false);
2186
2228
static inline void drbd_thread_restart_nowait(struct drbd_thread *thi)
2188
_drbd_thread_stop(thi, TRUE, FALSE);
2230
_drbd_thread_stop(thi, true, false);
2191
2233
/* counts how many answer packets packets we expect from our peer,
2340
2386
static inline void drbd_get_syncer_progress(struct drbd_conf *mdev,
2341
2387
unsigned long *bits_left, unsigned int *per_mil_done)
2344
* this is to break it at compile time when we change that
2345
* (we may feel 4TB maximum storage per drbd is not enough)
2389
/* this is to break it at compile time when we change that, in case we
2390
* want to support more than (1<<32) bits on a 32bit arch. */
2347
2391
typecheck(unsigned long, mdev->rs_total);
2349
2393
/* note: both rs_total and rs_left are in bits, i.e. in
2350
2394
* units of BM_BLOCK_SIZE.
2351
2395
* for the percentage, we don't care. */
2353
*bits_left = drbd_bm_total_weight(mdev) - mdev->rs_failed;
2397
if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T)
2398
*bits_left = mdev->ov_left;
2400
*bits_left = drbd_bm_total_weight(mdev) - mdev->rs_failed;
2354
2401
/* >> 10 to prevent overflow,
2355
2402
* +1 to prevent division by zero */
2356
2403
if (*bits_left > mdev->rs_total) {
2365
2412
*bits_left, mdev->rs_total, mdev->rs_failed);
2366
2413
*per_mil_done = 0;
2368
/* make sure the calculation happens in long context */
2369
unsigned long tmp = 1000UL -
2370
(*bits_left >> 10)*1000UL
2371
/ ((mdev->rs_total >> 10) + 1UL);
2415
/* Make sure the division happens in long context.
2416
* We allow up to one petabyte storage right now,
2417
* at a granularity of 4k per bit that is 2**38 bits.
2418
* After shift right and multiplication by 1000,
2419
* this should still fit easily into a 32bit long,
2420
* so we don't need a 64bit division on 32bit arch.
2421
* Note: currently we don't support such large bitmaps on 32bit
2422
* arch anyways, but no harm done to be prepared for it here.
2424
unsigned int shift = mdev->rs_total > UINT_MAX ? 16 : 10;
2425
unsigned long left = *bits_left >> shift;
2426
unsigned long total = 1UL + (mdev->rs_total >> shift);
2427
unsigned long tmp = 1000UL - left * 1000UL/total;
2372
2428
*per_mil_done = tmp;
2455
2518
return s.susp || s.susp_nod || s.susp_fen;
2458
static inline int __inc_ap_bio_cond(struct drbd_conf *mdev)
2521
static inline bool may_inc_ap_bio(struct drbd_conf *mdev)
2460
2523
int mxb = drbd_get_max_buffers(mdev);
2462
2525
if (is_susp(mdev->state))
2464
2527
if (test_bit(SUSPEND_IO, &mdev->flags))
2467
2530
/* to avoid potential deadlock or bitmap corruption,
2468
2531
* in various places, we only allow new application io
2469
2532
* to start during "stable" states. */
2471
2534
/* no new io accepted when attaching or detaching the disk */
2472
if (!drbd_state_is_stable(mdev->state))
2535
if (!drbd_state_is_stable(mdev))
2475
2538
/* since some older kernels don't have atomic_add_unless,
2476
2539
* and we are within the spinlock anyways, we have this workaround. */
2477
2540
if (atomic_read(&mdev->ap_bio_cnt) > mxb)
2479
2542
if (test_bit(BITMAP_IO, &mdev->flags))
2484
/* I'd like to use wait_event_lock_irq,
2485
* but I'm not sure when it got introduced,
2486
* and not sure when it has 3 or 4 arguments */
2547
static inline bool inc_ap_bio_cond(struct drbd_conf *mdev, int count)
2551
spin_lock_irq(&mdev->req_lock);
2552
rv = may_inc_ap_bio(mdev);
2554
atomic_add(count, &mdev->ap_bio_cnt);
2555
spin_unlock_irq(&mdev->req_lock);
2487
2560
static inline void inc_ap_bio(struct drbd_conf *mdev, int count)
2489
/* compare with after_state_ch,
2490
* os.conn != C_WF_BITMAP_S && ns.conn == C_WF_BITMAP_S */
2493
2562
/* we wait here
2494
2563
* as long as the device is suspended
2495
2564
* until the bitmap is no longer on the fly during connection
2496
* handshake as long as we would exeed the max_buffer limit.
2565
* handshake as long as we would exceed the max_buffer limit.
2498
2567
* to avoid races with the reconnect code,
2499
2568
* we need to atomic_inc within the spinlock. */
2501
spin_lock_irq(&mdev->req_lock);
2502
while (!__inc_ap_bio_cond(mdev)) {
2503
prepare_to_wait(&mdev->misc_wait, &wait, TASK_UNINTERRUPTIBLE);
2504
spin_unlock_irq(&mdev->req_lock);
2506
finish_wait(&mdev->misc_wait, &wait);
2507
spin_lock_irq(&mdev->req_lock);
2509
atomic_add(count, &mdev->ap_bio_cnt);
2510
spin_unlock_irq(&mdev->req_lock);
2570
wait_event(mdev->misc_wait, inc_ap_bio_cond(mdev, count));
2513
2573
static inline void dec_ap_bio(struct drbd_conf *mdev)
2576
2638
return QUEUE_ORDERED_NONE;
2580
* FIXME investigate what makes most sense:
2581
* a) blk_run_queue(q);
2583
* b) struct backing_dev_info *bdi;
2584
* b1) bdi = &q->backing_dev_info;
2585
* b2) bdi = mdev->ldev->backing_bdev->bd_inode->i_mapping->backing_dev_info;
2586
* blk_run_backing_dev(bdi,NULL);
2588
* c) generic_unplug(q) ? __generic_unplug(q) ?
2590
* d) q->unplug_fn(q), which is what all the drivers/md/ stuff uses...
2641
#ifdef blk_queue_plugged
2593
2642
static inline void drbd_blk_run_queue(struct request_queue *q)
2595
2644
if (q && q->unplug_fn)
2611
2668
if (test_bit(MD_NO_BARRIER, &mdev->flags))
2614
r = blkdev_issue_flush(mdev->ldev->md_bdev, GFP_KERNEL, NULL,
2671
r = blkdev_issue_flush(mdev->ldev->md_bdev, GFP_KERNEL, NULL);
2617
2673
set_bit(MD_NO_BARRIER, &mdev->flags);
2618
2674
dev_err(DEV, "meta data flush failed with status %d, disabling md-flushes\n", r);