| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | drbd_int.h |
|---|
| 3 | 4 | |
|---|
| .. | .. |
|---|
| 7 | 8 | Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>. |
|---|
| 8 | 9 | Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>. |
|---|
| 9 | 10 | |
|---|
| 10 | | - drbd is free software; you can redistribute it and/or modify |
|---|
| 11 | | - it under the terms of the GNU General Public License as published by |
|---|
| 12 | | - the Free Software Foundation; either version 2, or (at your option) |
|---|
| 13 | | - any later version. |
|---|
| 14 | | - |
|---|
| 15 | | - drbd is distributed in the hope that it will be useful, |
|---|
| 16 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | | - GNU General Public License for more details. |
|---|
| 19 | | - |
|---|
| 20 | | - You should have received a copy of the GNU General Public License |
|---|
| 21 | | - along with drbd; see the file COPYING. If not, write to |
|---|
| 22 | | - the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 23 | 11 | |
|---|
| 24 | 12 | */ |
|---|
| 25 | 13 | |
|---|
| .. | .. |
|---|
| 429 | 417 | __EE_CALL_AL_COMPLETE_IO, |
|---|
| 430 | 418 | __EE_MAY_SET_IN_SYNC, |
|---|
| 431 | 419 | |
|---|
| 432 | | - /* is this a TRIM aka REQ_DISCARD? */ |
|---|
| 433 | | - __EE_IS_TRIM, |
|---|
| 420 | + /* is this a TRIM aka REQ_OP_DISCARD? */ |
|---|
| 421 | + __EE_TRIM, |
|---|
| 422 | + /* explicit zero-out requested, or |
|---|
| 423 | + * our lower level cannot handle trim, |
|---|
| 424 | + * and we want to fall back to zeroout instead */ |
|---|
| 425 | + __EE_ZEROOUT, |
|---|
| 434 | 426 | |
|---|
| 435 | 427 | /* In case a barrier failed, |
|---|
| 436 | 428 | * we need to resubmit without the barrier flag. */ |
|---|
| .. | .. |
|---|
| 472 | 464 | }; |
|---|
| 473 | 465 | #define EE_CALL_AL_COMPLETE_IO (1<<__EE_CALL_AL_COMPLETE_IO) |
|---|
| 474 | 466 | #define EE_MAY_SET_IN_SYNC (1<<__EE_MAY_SET_IN_SYNC) |
|---|
| 475 | | -#define EE_IS_TRIM (1<<__EE_IS_TRIM) |
|---|
| 467 | +#define EE_TRIM (1<<__EE_TRIM) |
|---|
| 468 | +#define EE_ZEROOUT (1<<__EE_ZEROOUT) |
|---|
| 476 | 469 | #define EE_RESUBMITTED (1<<__EE_RESUBMITTED) |
|---|
| 477 | 470 | #define EE_WAS_ERROR (1<<__EE_WAS_ERROR) |
|---|
| 478 | 471 | #define EE_HAS_DIGEST (1<<__EE_HAS_DIGEST) |
|---|
| .. | .. |
|---|
| 627 | 620 | unsigned int head_index; |
|---|
| 628 | 621 | unsigned int size; |
|---|
| 629 | 622 | int total; /* sum of all values */ |
|---|
| 630 | | - int values[0]; |
|---|
| 623 | + int values[]; |
|---|
| 631 | 624 | }; |
|---|
| 632 | | -extern struct fifo_buffer *fifo_alloc(int fifo_size); |
|---|
| 625 | +extern struct fifo_buffer *fifo_alloc(unsigned int fifo_size); |
|---|
| 633 | 626 | |
|---|
| 634 | 627 | /* flag bits per connection */ |
|---|
| 635 | 628 | enum { |
|---|
| .. | .. |
|---|
| 724 | 717 | struct list_head transfer_log; /* all requests not yet fully processed */ |
|---|
| 725 | 718 | |
|---|
| 726 | 719 | struct crypto_shash *cram_hmac_tfm; |
|---|
| 727 | | - struct crypto_ahash *integrity_tfm; /* checksums we compute, updates protected by connection->data->mutex */ |
|---|
| 728 | | - struct crypto_ahash *peer_integrity_tfm; /* checksums we verify, only accessed from receiver thread */ |
|---|
| 729 | | - struct crypto_ahash *csums_tfm; |
|---|
| 730 | | - struct crypto_ahash *verify_tfm; |
|---|
| 720 | + struct crypto_shash *integrity_tfm; /* checksums we compute, updates protected by connection->data->mutex */ |
|---|
| 721 | + struct crypto_shash *peer_integrity_tfm; /* checksums we verify, only accessed from receiver thread */ |
|---|
| 722 | + struct crypto_shash *csums_tfm; |
|---|
| 723 | + struct crypto_shash *verify_tfm; |
|---|
| 731 | 724 | void *int_dig_in; |
|---|
| 732 | 725 | void *int_dig_vv; |
|---|
| 733 | 726 | |
|---|
| .. | .. |
|---|
| 848 | 841 | |
|---|
| 849 | 842 | sector_t p_size; /* partner's disk size */ |
|---|
| 850 | 843 | struct request_queue *rq_queue; |
|---|
| 851 | | - struct block_device *this_bdev; |
|---|
| 852 | 844 | struct gendisk *vdisk; |
|---|
| 853 | 845 | |
|---|
| 854 | 846 | unsigned long last_reattach_jif; |
|---|
| .. | .. |
|---|
| 1312 | 1304 | |
|---|
| 1313 | 1305 | #define DRBD_MAX_SECTORS_FIXED_BM \ |
|---|
| 1314 | 1306 | ((MD_128MB_SECT - MD_32kB_SECT - MD_4kB_SECT) * (1LL<<(BM_EXT_SHIFT-9))) |
|---|
| 1315 | | -#if !defined(CONFIG_LBDAF) && BITS_PER_LONG == 32 |
|---|
| 1316 | | -#define DRBD_MAX_SECTORS DRBD_MAX_SECTORS_32 |
|---|
| 1317 | | -#define DRBD_MAX_SECTORS_FLEX DRBD_MAX_SECTORS_32 |
|---|
| 1318 | | -#else |
|---|
| 1319 | 1307 | #define DRBD_MAX_SECTORS DRBD_MAX_SECTORS_FIXED_BM |
|---|
| 1320 | 1308 | /* 16 TB in units of sectors */ |
|---|
| 1321 | 1309 | #if BITS_PER_LONG == 32 |
|---|
| .. | .. |
|---|
| 1327 | 1315 | /* we allow up to 1 PiB now on 64bit architecture with "flexible" meta data */ |
|---|
| 1328 | 1316 | #define DRBD_MAX_SECTORS_FLEX (1UL << 51) |
|---|
| 1329 | 1317 | /* corresponds to (1UL << 38) bits right now. */ |
|---|
| 1330 | | -#endif |
|---|
| 1331 | 1318 | #endif |
|---|
| 1332 | 1319 | |
|---|
| 1333 | 1320 | /* Estimate max bio size as 256 * PAGE_SIZE, |
|---|
| .. | .. |
|---|
| 1463 | 1450 | /* drbd_req */ |
|---|
| 1464 | 1451 | extern void do_submit(struct work_struct *ws); |
|---|
| 1465 | 1452 | extern void __drbd_make_request(struct drbd_device *, struct bio *, unsigned long); |
|---|
| 1466 | | -extern blk_qc_t drbd_make_request(struct request_queue *q, struct bio *bio); |
|---|
| 1453 | +extern blk_qc_t drbd_submit_bio(struct bio *bio); |
|---|
| 1467 | 1454 | extern int drbd_read_remote(struct drbd_device *device, struct drbd_request *req); |
|---|
| 1468 | 1455 | extern int is_valid_ar_handle(struct drbd_request *, sector_t); |
|---|
| 1469 | 1456 | |
|---|
| .. | .. |
|---|
| 1531 | 1518 | } |
|---|
| 1532 | 1519 | |
|---|
| 1533 | 1520 | |
|---|
| 1534 | | -extern void drbd_csum_bio(struct crypto_ahash *, struct bio *, void *); |
|---|
| 1535 | | -extern void drbd_csum_ee(struct crypto_ahash *, struct drbd_peer_request *, void *); |
|---|
| 1521 | +extern void drbd_csum_bio(struct crypto_shash *, struct bio *, void *); |
|---|
| 1522 | +extern void drbd_csum_ee(struct crypto_shash *, struct drbd_peer_request *, |
|---|
| 1523 | + void *); |
|---|
| 1536 | 1524 | /* worker callbacks */ |
|---|
| 1537 | 1525 | extern int w_e_end_data_req(struct drbd_work *, int); |
|---|
| 1538 | 1526 | extern int w_e_end_rsdata_req(struct drbd_work *, int); |
|---|
| .. | .. |
|---|
| 1555 | 1543 | extern void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req); |
|---|
| 1556 | 1544 | |
|---|
| 1557 | 1545 | /* drbd_receiver.c */ |
|---|
| 1546 | +extern int drbd_issue_discard_or_zero_out(struct drbd_device *device, |
|---|
| 1547 | + sector_t start, unsigned int nr_sectors, int flags); |
|---|
| 1558 | 1548 | extern int drbd_receiver(struct drbd_thread *thi); |
|---|
| 1559 | 1549 | extern int drbd_ack_receiver(struct drbd_thread *thi); |
|---|
| 1560 | 1550 | extern void drbd_send_ping_wf(struct work_struct *ws); |
|---|
| .. | .. |
|---|
| 1579 | 1569 | extern void _drbd_clear_done_ee(struct drbd_device *device, struct list_head *to_be_freed); |
|---|
| 1580 | 1570 | extern int drbd_connected(struct drbd_peer_device *); |
|---|
| 1581 | 1571 | |
|---|
| 1582 | | -static inline void drbd_tcp_cork(struct socket *sock) |
|---|
| 1583 | | -{ |
|---|
| 1584 | | - int val = 1; |
|---|
| 1585 | | - (void) kernel_setsockopt(sock, SOL_TCP, TCP_CORK, |
|---|
| 1586 | | - (char*)&val, sizeof(val)); |
|---|
| 1587 | | -} |
|---|
| 1588 | | - |
|---|
| 1589 | | -static inline void drbd_tcp_uncork(struct socket *sock) |
|---|
| 1590 | | -{ |
|---|
| 1591 | | - int val = 0; |
|---|
| 1592 | | - (void) kernel_setsockopt(sock, SOL_TCP, TCP_CORK, |
|---|
| 1593 | | - (char*)&val, sizeof(val)); |
|---|
| 1594 | | -} |
|---|
| 1595 | | - |
|---|
| 1596 | | -static inline void drbd_tcp_nodelay(struct socket *sock) |
|---|
| 1597 | | -{ |
|---|
| 1598 | | - int val = 1; |
|---|
| 1599 | | - (void) kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY, |
|---|
| 1600 | | - (char*)&val, sizeof(val)); |
|---|
| 1601 | | -} |
|---|
| 1602 | | - |
|---|
| 1603 | | -static inline void drbd_tcp_quickack(struct socket *sock) |
|---|
| 1604 | | -{ |
|---|
| 1605 | | - int val = 2; |
|---|
| 1606 | | - (void) kernel_setsockopt(sock, SOL_TCP, TCP_QUICKACK, |
|---|
| 1607 | | - (char*)&val, sizeof(val)); |
|---|
| 1608 | | -} |
|---|
| 1609 | | - |
|---|
| 1610 | 1572 | /* sets the number of 512 byte sectors of our virtual device */ |
|---|
| 1611 | | -static inline void drbd_set_my_capacity(struct drbd_device *device, |
|---|
| 1612 | | - sector_t size) |
|---|
| 1613 | | -{ |
|---|
| 1614 | | - /* set_capacity(device->this_bdev->bd_disk, size); */ |
|---|
| 1615 | | - set_capacity(device->vdisk, size); |
|---|
| 1616 | | - device->this_bdev->bd_inode->i_size = (loff_t)size << 9; |
|---|
| 1617 | | -} |
|---|
| 1573 | +void drbd_set_my_capacity(struct drbd_device *device, sector_t size); |
|---|
| 1618 | 1574 | |
|---|
| 1619 | 1575 | /* |
|---|
| 1620 | 1576 | * used to submit our private bio |
|---|
| 1621 | 1577 | */ |
|---|
| 1622 | | -static inline void drbd_generic_make_request(struct drbd_device *device, |
|---|
| 1578 | +static inline void drbd_submit_bio_noacct(struct drbd_device *device, |
|---|
| 1623 | 1579 | int fault_type, struct bio *bio) |
|---|
| 1624 | 1580 | { |
|---|
| 1625 | 1581 | __release(local); |
|---|
| 1626 | 1582 | if (!bio->bi_disk) { |
|---|
| 1627 | | - drbd_err(device, "drbd_generic_make_request: bio->bi_disk == NULL\n"); |
|---|
| 1583 | + drbd_err(device, "drbd_submit_bio_noacct: bio->bi_disk == NULL\n"); |
|---|
| 1628 | 1584 | bio->bi_status = BLK_STS_IOERR; |
|---|
| 1629 | 1585 | bio_endio(bio); |
|---|
| 1630 | 1586 | return; |
|---|
| .. | .. |
|---|
| 1633 | 1589 | if (drbd_insert_fault(device, fault_type)) |
|---|
| 1634 | 1590 | bio_io_error(bio); |
|---|
| 1635 | 1591 | else |
|---|
| 1636 | | - generic_make_request(bio); |
|---|
| 1592 | + submit_bio_noacct(bio); |
|---|
| 1637 | 1593 | } |
|---|
| 1638 | 1594 | |
|---|
| 1639 | 1595 | void drbd_bump_write_ordering(struct drbd_resource *resource, struct drbd_backing_dev *bdev, |
|---|
| .. | .. |
|---|
| 1688 | 1644 | }; |
|---|
| 1689 | 1645 | void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib); |
|---|
| 1690 | 1646 | |
|---|
| 1691 | | -extern void notify_resource_state(struct sk_buff *, |
|---|
| 1647 | +extern int notify_resource_state(struct sk_buff *, |
|---|
| 1692 | 1648 | unsigned int, |
|---|
| 1693 | 1649 | struct drbd_resource *, |
|---|
| 1694 | 1650 | struct resource_info *, |
|---|
| 1695 | 1651 | enum drbd_notification_type); |
|---|
| 1696 | | -extern void notify_device_state(struct sk_buff *, |
|---|
| 1652 | +extern int notify_device_state(struct sk_buff *, |
|---|
| 1697 | 1653 | unsigned int, |
|---|
| 1698 | 1654 | struct drbd_device *, |
|---|
| 1699 | 1655 | struct device_info *, |
|---|
| 1700 | 1656 | enum drbd_notification_type); |
|---|
| 1701 | | -extern void notify_connection_state(struct sk_buff *, |
|---|
| 1657 | +extern int notify_connection_state(struct sk_buff *, |
|---|
| 1702 | 1658 | unsigned int, |
|---|
| 1703 | 1659 | struct drbd_connection *, |
|---|
| 1704 | 1660 | struct connection_info *, |
|---|
| 1705 | 1661 | enum drbd_notification_type); |
|---|
| 1706 | | -extern void notify_peer_device_state(struct sk_buff *, |
|---|
| 1662 | +extern int notify_peer_device_state(struct sk_buff *, |
|---|
| 1707 | 1663 | unsigned int, |
|---|
| 1708 | 1664 | struct drbd_peer_device *, |
|---|
| 1709 | 1665 | struct peer_device_info *, |
|---|
| .. | .. |
|---|
| 1776 | 1732 | _drbd_set_state(_NS(device, disk, D_INCONSISTENT), CS_HARD, NULL); |
|---|
| 1777 | 1733 | break; |
|---|
| 1778 | 1734 | } |
|---|
| 1779 | | - /* NOTE fall through for DRBD_META_IO_ERROR or DRBD_FORCE_DETACH */ |
|---|
| 1735 | + fallthrough; /* for DRBD_META_IO_ERROR or DRBD_FORCE_DETACH */ |
|---|
| 1780 | 1736 | case EP_DETACH: |
|---|
| 1781 | 1737 | case EP_CALL_HELPER: |
|---|
| 1782 | 1738 | /* Remember whether we saw a READ or WRITE error. |
|---|
| .. | .. |
|---|
| 1975 | 1931 | { |
|---|
| 1976 | 1932 | struct task_struct *task = connection->ack_receiver.task; |
|---|
| 1977 | 1933 | if (task && get_t_state(&connection->ack_receiver) == RUNNING) |
|---|
| 1978 | | - force_sig(SIGXCPU, task); |
|---|
| 1934 | + send_sig(SIGXCPU, task, 1); |
|---|
| 1979 | 1935 | } |
|---|
| 1980 | 1936 | |
|---|
| 1981 | 1937 | static inline void request_ping(struct drbd_connection *connection) |
|---|