DRBD fixes and one functional enhancemet
Subsystems (2)
Philipp Reisner
maintainercover DRBD fixes and one functional enhancemet
Hi Jens,
Please consider to apply these patches to your for-3.11/drivers branch.
The first 4 patches are obvious fixes. The last patch adds the capability to change the activity log layout online. (al-stripes and al-stripe-size)
I posted these patches on the 14th for review.
Andreas Gruenbacher (2):
drbd: Do not sleep inside rcu
drbd: Fix rcu_read_lock balance on error path
Philipp Reisner (3):
drbd: Ignore the exit code of a fence-peer handler if it returns too
late
drbd: Constants should be UPPERCASE
drbd: Allow online change of al-stripes and al-stripe-size
Wei Yongjun (1):
drbd: fix error return code in drbd_init()
drivers/block/drbd/drbd_actlog.c | 21 ++++ drivers/block/drbd/drbd_int.h | 15 ++- drivers/block/drbd/drbd_main.c | 61 ++++++------ drivers/block/drbd/drbd_nl.c | 185 ++++++++++++++++++++++++++++-------- drivers/block/drbd/drbd_receiver.c | 12 +-- drivers/block/drbd/drbd_state.c | 4 +- include/linux/drbd.h | 6 +- include/linux/drbd_genl.h | 2 + include/linux/drbd_limits.h | 9 ++ 9 files changed, 236 insertions(+), 79 deletions(-)
Signature · 1 line
1.7.9.5
Philipp Reisner
maintainerPATCH 1/6 drbd: Do not sleep inside rcu
From: Andreas Gruenbacher <[email protected]>
--- drivers/block/drbd/drbd_receiver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_receiver.c +2 -2
@@ -1039,6 +1039,8 @@ randomize:rcu_read_lock ();idr_for_each_entry (&tconn->volumes, mdev, vnr) {kref_get (&mdev->kref); +rcu_read_unlock (); +/* Prevent a race between resync-handshake and * being promoted to Primary. *
@@ -1049,8 +1051,6 @@ randomize:mutex_lock (mdev->state_mutex);mutex_unlock (mdev->state_mutex); -rcu_read_unlock (); -if (discard_my_data)set_bit (DISCARD_MY_DATA , &mdev->flags);else
Signature · 1 line
1.7.9.5
Philipp Reisner
maintainerPATCH 2/6 drbd: fix error return code in drbd_init()
In reply to Philipp ReisnerFrom: Wei Yongjun <[email protected]>
Fix to return a negative error code from the error handling case instead of 0, as returned elsewhere in this function.
--- drivers/block/drbd/drbd_main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/block/drbd/drbd_main.c +1 -3
@@ -2762,8 +2762,6 @@ int __init drbd_init(void)/* * allocate all necessary structs */ - err = -ENOMEM ; -init_waitqueue_head (&drbd_pp_wait); drbd_proc =NULL ;/* play safe for drbd_cleanup */
@@ -2773,6 +2771,7 @@ int __init drbd_init(void)if (err) goto fail; + err = -ENOMEM ; drbd_proc =proc_create_data ("drbd" ,S_IFREG |S_IRUGO ,NULL , &drbd_proc_fops,NULL );if (!drbd_proc) {printk (KERN_ERR "drbd: unable to register proc file\n" );
@@ -2803,7 +2802,6 @@ int __init drbd_init(void) fail:drbd_cleanup ();if (err == -ENOMEM ) -/* currently always the case */ printk (KERN_ERR "drbd: ran out of memory\n" );else printk (KERN_ERR "drbd: initialization failure\n" );
Signature · 1 line
1.7.9.5
Philipp Reisner
maintainerPATCH 3/6 drbd: Fix rcu_read_lock balance on error path
In reply to Philipp ReisnerFrom: Andreas Gruenbacher <[email protected]>
--- drivers/block/drbd/drbd_nl.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/block/drbd/drbd_nl.c +12 -7
@@ -2658,7 +2658,6 @@ int nla_put_status_info(struct sk_buff *skb, struct drbd_conf *mdev, const struct sib_info *sib) {struct state_info *si =NULL ;/* for sizeof(si->member); */ -struct net_conf *nc;struct nlattr *nla;int got_ldev;int err =0 ;
@@ -2688,13 +2687,19 @@ int nla_put_status_info(struct sk_buff *skb, struct drbd_conf *mdev, goto nla_put_failure;rcu_read_lock (); -if (got_ldev) -if (disk_conf_to_skb (skb,rcu_dereference (mdev->ldev->disk_conf), exclude_sensitive)) - goto nla_put_failure; +if (got_ldev) { +struct disk_conf *disk_conf; - nc =rcu_dereference (mdev->tconn->net_conf); -if (nc) - err =net_conf_to_skb (skb, nc, exclude_sensitive); + disk_conf =rcu_dereference (mdev->ldev->disk_conf); + err =disk_conf_to_skb (skb, disk_conf, exclude_sensitive); + } +if (!err) { +struct net_conf *nc; + + nc =rcu_dereference (mdev->tconn->net_conf); +if (nc) + err =net_conf_to_skb (skb, nc, exclude_sensitive); + }rcu_read_unlock ();if (err) goto nla_put_failure;
Signature · 1 line
1.7.9.5
Philipp Reisner
maintainerPATCH 4/6 drbd: Ignore the exit code of a fence-peer handler if it returns too late
In reply to Philipp ReisnerIn case the connection was established and lost again before the a fence-peer handler returns, ignore the exit code of this instance. (And use the exit code of the later started instance)
--- drivers/block/drbd/drbd_int.h | 1 + drivers/block/drbd/drbd_nl.c | 15 +++++++++++++-- drivers/block/drbd/drbd_state.c | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-)
drivers/block/drbd/drbd_int.h +1 -0
@@ -832,6 +832,7 @@ struct drbd_tconn { /* is a resource from the config file */ unsigned susp_nod:1; /* IO suspended because no data */ unsigned susp_fen:1; /* IO suspended because fence peer handler runs */struct mutex cstate_mutex;/* Protects graceful disconnects */ +unsigned int connect_cnt;/* Inc each time a connection is established */ unsigned long flags;struct net_conf *net_conf;/* content protected by rcu */
drivers/block/drbd/drbd_nl.c +13 -2
@@ -417,6 +417,7 @@ static enum drbd_fencing_p highest_fencing_policy(struct drbd_tconn *tconn)bool conn_try_outdate_peer (struct drbd_tconn *tconn) { +unsigned int connect_cnt;union drbd_state mask = { };union drbd_state val = { };enum drbd_fencing_p fp;
@@ -428,6 +429,10 @@ bool conn_try_outdate_peer(struct drbd_tconn *tconn)return false; } +spin_lock_irq (&tconn->req_lock); + connect_cnt = tconn->connect_cnt; +spin_unlock_irq (&tconn->req_lock); + fp =highest_fencing_policy (tconn);switch (fp) {case FP_NOT_AVAIL :
@@ -492,8 +497,14 @@ bool conn_try_outdate_peer(struct drbd_tconn *tconn)here, because we might were able to re-establish the connection in the meantime. */ spin_lock_irq (&tconn->req_lock); -if (tconn->cstate <C_WF_REPORT_PARAMS && !test_bit (STATE_SENT , &tconn->flags)) -_conn_request_state (tconn, mask, val,CS_VERBOSE ); +if (tconn->cstate <C_WF_REPORT_PARAMS && !test_bit (STATE_SENT , &tconn->flags)) { +if (tconn->connect_cnt != connect_cnt) +/* In case the connection was established and droped +while the fence-peer handler was running, ignore it */ +conn_info (tconn,"Ignoring fence-peer exit code\n" ); +else +_conn_request_state (tconn, mask, val,CS_VERBOSE ); + }spin_unlock_irq (&tconn->req_lock);return conn_highest_pdsk (tconn) <=D_OUTDATED ;
drivers/block/drbd/drbd_state.c +3 -1
@@ -1115,8 +1115,10 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns,drbd_thread_restart_nowait (&mdev->tconn->receiver);/* Resume AL writing if we get a connection */ -if (os.conn <C_CONNECTED && ns.conn >=C_CONNECTED ) +if (os.conn <C_CONNECTED && ns.conn >=C_CONNECTED ) {drbd_resume_al (mdev); + mdev->tconn->connect_cnt++; + }/* remember last attach time so request_timer_fn() won't * kill newly established sessions while we are still trying to thaw
Signature · 1 line
1.7.9.5
Philipp Reisner
maintainerPATCH 5/6 drbd: Constants should be UPPERCASE
In reply to Philipp Reisner--- drivers/block/drbd/drbd_int.h | 7 ++++++- drivers/block/drbd/drbd_nl.c | 20 ++++++++++---------- drivers/block/drbd/drbd_receiver.c | 6 +++--- 3 files changed, 19 insertions(+), 14 deletions(-)
drivers/block/drbd/drbd_int.h +6 -1
@@ -1467,7 +1467,12 @@ extern void drbd_suspend_io(struct drbd_conf *mdev);extern void drbd_resume_io (struct drbd_conf *mdev);extern char *ppsize (char *buf,unsigned long long size);extern sector_t drbd_new_dev_size (struct drbd_conf *,struct drbd_backing_dev *,sector_t ,int ); -enum determine_dev_size { dev_size_error =-1 , unchanged =0 , shrunk =1 , grew =2 }; +enum determine_dev_size { +DS_ERROR =-1 , +DS_UNCHANGED =0 , +DS_SHRUNK =1 , +DS_GREW =2 +}; extern enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *, enum dds_flags) __must_hold(local);extern void resync_after_online_grow (struct drbd_conf *);extern void drbd_reconsider_max_bio_size (struct drbd_conf *mdev);
drivers/block/drbd/drbd_nl.c +10 -10
@@ -835,7 +835,7 @@ enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *mdev, enum ddschar ppb[10 ];int md_moved, la_size_changed; -enum determine_dev_size rv = unchanged; +enum determine_dev_size rv =DS_UNCHANGED ;/* race: * application request passes inc_ap_bio,
@@ -878,7 +878,7 @@ enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *mdev, enum dds"Leaving size unchanged at size = %lu KB\n" , (unsigned long)size); } - rv = dev_size_error; + rv =DS_ERROR ; }/* racy, see comments above. */ drbd_set_my_capacity (mdev, size);
@@ -886,7 +886,7 @@ enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *mdev, enum ddsdev_info (DEV ,"size = %s (%llu KB)\n" ,ppsize (ppb, size>>1 ), (unsigned long long )size>>1 ); } -if (rv == dev_size_error) +if (rv ==DS_ERROR ) goto out; la_size_changed = (la_size_sect != mdev->ldev->md.la_size_sect);
@@ -905,16 +905,16 @@ enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *mdev, enum dds err =drbd_bitmap_io (mdev, md_moved ? &drbd_bm_write_all : &drbd_bm_write,"size changed" ,BM_LOCKED_MASK );if (err) { - rv = dev_size_error; + rv =DS_ERROR ; goto out; }drbd_md_mark_dirty (mdev); }if (size > la_size_sect) - rv = grew; + rv =DS_GREW ;if (size < la_size_sect) - rv = shrunk; + rv =DS_SHRUNK ; out:lc_unlock (mdev->act_log);wake_up (&mdev->al_wait);
@@ -1619,10 +1619,10 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)set_bit (USE_DEGR_WFC_T , &mdev->flags); dd =drbd_determine_dev_size (mdev,0 ); -if (dd == dev_size_error) { +if (dd ==DS_ERROR ) { retcode =ERR_NOMEM_BITMAP ; goto force_diskless_dec; - }else if (dd == grew) + }else if (dd ==DS_GREW )set_bit (RESYNC_AFTER_NEG , &mdev->flags); if (drbd_md_test_flag(mdev->ldev, MDF_FULL_SYNC) ||
@@ -2387,13 +2387,13 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) dd =drbd_determine_dev_size (mdev, ddsf);drbd_md_sync (mdev);put_ldev (mdev); -if (dd == dev_size_error) { +if (dd ==DS_ERROR ) { retcode =ERR_NOMEM_BITMAP ; goto fail; }if (mdev->state.conn ==C_CONNECTED ) { -if (dd == grew) +if (dd ==DS_GREW )set_bit (RESIZE_PENDING , &mdev->flags);drbd_send_uuids (mdev);
drivers/block/drbd/drbd_receiver.c +3 -3
@@ -3545,7 +3545,7 @@ static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi) {struct drbd_conf *mdev;struct p_sizes *p = pi->data; -enum determine_dev_size dd = unchanged; +enum determine_dev_size dd =DS_UNCHANGED ;sector_t p_size, p_usize, my_usize;int ldsc =0 ;/* local disk size changed */ enum dds_flags ddsf;
@@ -3619,7 +3619,7 @@ static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi)if (get_ldev (mdev)) { dd =drbd_determine_dev_size (mdev, ddsf);put_ldev (mdev); -if (dd == dev_size_error) +if (dd ==DS_ERROR )return -EIO ;drbd_md_sync (mdev); }else {
@@ -3647,7 +3647,7 @@ static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi)drbd_send_sizes (mdev,0 , ddsf); }if (test_and_clear_bit (RESIZE_PENDING , &mdev->flags) || - (dd == grew && mdev->state.conn ==C_CONNECTED )) { + (dd ==DS_GREW && mdev->state.conn ==C_CONNECTED )) {if (mdev->state.pdsk >=D_INCONSISTENT && mdev->state.disk >=D_INCONSISTENT ) {if (ddsf &DDSF_NO_RESYNC )
Signature · 1 line
1.7.9.5
Philipp Reisner
maintainerPATCH 6/6 drbd: Allow online change of al-stripes and al-stripe-size
In reply to Philipp ReisnerAllow to change the AL layout with an resize operation. For that the reisze command gets two new fields: al_stripes and al_stripe_size.
In order to make the operation crash save:
1) Lock out all IO and MD-IO
2) Write the super block with MDF_PRIMARY_IND clear
3) write the bitmap to the new location (all zeros, since we allow only while connected)
4) Initialize the new AL-area
5) Write the super block with the restored MDF_PRIMARY_IND.
6) Unfreeze all IO
Since the AL-layout has no influence on the protocol, this operation needs to be beforemed on both sides of a resource (if intended).
--- drivers/block/drbd/drbd_actlog.c | 21 ++++++ drivers/block/drbd/drbd_int.h | 7 +- drivers/block/drbd/drbd_main.c | 57 ++++++++------- drivers/block/drbd/drbd_nl.c | 137 +++++++++++++++++++++++++++++------- drivers/block/drbd/drbd_receiver.c | 2 +- include/linux/drbd.h | 6 +- include/linux/drbd_genl.h | 2 + include/linux/drbd_limits.h | 9 +++ 8 files changed, 188 insertions(+), 53 deletions(-)
drivers/block/drbd/drbd_actlog.c +21 -0
@@ -659,6 +659,27 @@ void drbd_al_shrink(struct drbd_conf *mdev)wake_up (&mdev->al_wait); } +int drbd_initialize_al (struct drbd_conf *mdev,void *buffer) +{ +struct al_transaction_on_disk *al = buffer; +struct drbd_md *md = &mdev->ldev->md; +sector_t al_base = md->md_offset + md->al_offset; +int al_size_4k = md->al_stripes * md->al_stripe_size_4k; +int i; + +memset (al,0 ,4096 ); + al->magic =cpu_to_be32 (DRBD_AL_MAGIC ); + al->transaction_type =cpu_to_be16 (AL_TR_INITIALIZED ); + al->crc32c =cpu_to_be32 (crc32c (0 , al,4096 )); + +for (i =0 ; i < al_size_4k; i++) { +int err =drbd_md_sync_page_io (mdev, mdev->ldev, al_base + i *8 ,WRITE ); +if (err) +return err; + } +return 0 ; +} +static int w_update_odbm (struct drbd_work *w,int unused) { struct update_odbm_work *udw = container_of(w, struct update_odbm_work, w);
drivers/block/drbd/drbd_int.h +6 -1
@@ -1133,6 +1133,7 @@ extern void drbd_mdev_cleanup(struct drbd_conf *mdev);void drbd_print_uuids (struct drbd_conf *mdev,const char *text);extern void conn_md_sync (struct drbd_tconn *tconn); +extern void drbd_md_write (struct drbd_conf *mdev,void *buffer);extern void drbd_md_sync (struct drbd_conf *mdev);extern int drbd_md_read (struct drbd_conf *mdev,struct drbd_backing_dev *bdev); extern void drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local);
@@ -1468,12 +1469,15 @@ extern void drbd_resume_io(struct drbd_conf *mdev);extern char *ppsize (char *buf,unsigned long long size);extern sector_t drbd_new_dev_size (struct drbd_conf *,struct drbd_backing_dev *,sector_t ,int );enum determine_dev_size { +DS_ERROR_SHRINK =-3 , +DS_ERROR_SPACE_MD =-2 ,DS_ERROR =-1 ,DS_UNCHANGED =0 ,DS_SHRUNK =1 ,DS_GREW =2 }; -extern enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *, enum dds_flags) __must_hold(local); +extern enum determine_dev_size +drbd_determine_dev_size(struct drbd_conf *, enum dds_flags, struct resize_parms *) __must_hold(local);extern void resync_after_online_grow (struct drbd_conf *);extern void drbd_reconsider_max_bio_size (struct drbd_conf *mdev); extern enum drbd_state_rv drbd_set_role(struct drbd_conf *mdev,
@@ -1639,6 +1643,7 @@ extern int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector,#define drbd_set_out_of_sync (mdev, sector, size) \ __drbd_set_out_of_sync(mdev, sector, size, __FILE__, __LINE__)extern void drbd_al_shrink (struct drbd_conf *mdev); +extern int drbd_initialize_al (struct drbd_conf *,void *);/* drbd_nl.c */ /* state info broadcast */
drivers/block/drbd/drbd_main.c +33 -24
73 lines not on this page · raw message
drivers/block/drbd/drbd_nl.c +111 -26
243 lines not on this page · raw message
drivers/block/drbd/drbd_receiver.c +1 -1
@@ -3617,7 +3617,7 @@ static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi) ddsf =be16_to_cpu (p->dds_flags);if (get_ldev (mdev)) { - dd =drbd_determine_dev_size (mdev, ddsf); + dd =drbd_determine_dev_size (mdev, ddsf,NULL );put_ldev (mdev);if (dd ==DS_ERROR )return -EIO ;
include/linux/drbd.h +5 -1
@@ -177,7 +177,11 @@ enum drbd_ret_code {ERR_NEED_APV_100 =163 ,ERR_NEED_ALLOW_TWO_PRI =164 ,ERR_MD_UNCLEAN =165 , - +ERR_MD_LAYOUT_CONNECTED =166 , +ERR_MD_LAYOUT_TOO_BIG =167 , +ERR_MD_LAYOUT_TOO_SMALL =168 , +ERR_MD_LAYOUT_NO_FIT =169 , +ERR_IMPLICIT_SHRINK =170 ,/* insert new ones above this line */ AFTER_LAST_ERR_CODE };
include/linux/drbd_genl.h +2 -0
@@ -181,6 +181,8 @@ GENL_struct(DRBD_NLA_RESIZE_PARMS, 7, resize_parms, __u64_field(1, DRBD_GENLA_F_MANDATORY, resize_size) __flg_field(2, DRBD_GENLA_F_MANDATORY, resize_force) __flg_field(3, DRBD_GENLA_F_MANDATORY, no_resync) + __u32_field_def(4, 0 /* OPTIONAL */, al_stripes, DRBD_AL_STRIPES_DEF) + __u32_field_def(5, 0 /* OPTIONAL */, al_stripe_size, DRBD_AL_STRIPE_SIZE_DEF) ) GENL_struct(DRBD_NLA_STATE_INFO, 8, state_info,
include/linux/drbd_limits.h +9 -0
@@ -215,4 +215,13 @@#define DRBD_ALWAYS_ASBP_DEF 0#define DRBD_USE_RLE_DEF 1 +#define DRBD_AL_STRIPES_MIN 1 +#define DRBD_AL_STRIPES_MAX 1024 +#define DRBD_AL_STRIPES_DEF 1 +#define DRBD_AL_STRIPES_SCALE '1' + +#define DRBD_AL_STRIPE_SIZE_MIN 4 +#define DRBD_AL_STRIPE_SIZE_MAX 16777216 +#define DRBD_AL_STRIPE_SIZE_DEF 32 +#define DRBD_AL_STRIPE_SIZE_SCALE 'k'/* kilobytes */ #endif
Signature · 1 line
1.7.9.5
Jens Axboe
maintainerQuoted 9 lines · Philipp Reisner
Hi Jens,
Please consider to apply these patches to your for-3.11/drivers branch.
The first 4 patches are obvious fixes. The last patch adds the capability to change the activity log layout online. (al-stripes and al-stripe-size)
I posted these patches on the 14th for review.
Thanks, added for 3.11.
Signature · 1 line
Jens Axboe