ocfs2/dlm: allocate lvb for dlm_lock_resource which needs it -drop2
PATCH 1/1 ocfs2/dlm: allocate lvb for dlm_lock_resource which needs it -drop2
Changes to drop1:
1) adds unsigned reserve_lvb:1 to dlm_lock_resource indicating lvb should be reserved or not. This flag doesn't make sense to this patch its self, but it helps the coming patch that allocates lvb for dlm_lock which needs it. The 1 bit flag doesn't take extra memory space, so putting it here is fine.
2) adds a new parameter to dlm_new_lockres() indicating if lvb memory should be reserved. Determining method by checking name in v1 is discarded.
3) adds u8 reserve_lvb:1 to dlm_migratable_lockres indicating if the migration target should reserve lvb for the dlm_lock_resouce in case of needing to create a new dlm_lock_resouce.
4) increment dlm_protocol major version because of 3).
trivial changes:
1) moves the real allocation from dlm_init_lockres() to dlm_new_lockres(). since we have the new-added parameter, we know if we should do the allocation in dlm_new_lockres(). And it's better we do allocations at the same space.
2) adds DLM_LKF_VALBLK to dlm_flags in ocfs2_lock_create.
We are missing the flag. But since it's adding a new lockres(no race), so no problem running current codes.
3) adds some asserts on res->lvb.
--- fs/ocfs2/dlm/dlmast.c | 2 ++ fs/ocfs2/dlm/dlmcommon.h | 16 +++++++++++----- fs/ocfs2/dlm/dlmconvert.c | 5 ++++- fs/ocfs2/dlm/dlmdebug.c | 6 ++++-- fs/ocfs2/dlm/dlmdomain.c | 6 +++++- fs/ocfs2/dlm/dlmmaster.c | 16 +++++++++++++--- fs/ocfs2/dlm/dlmrecovery.c | 25 ++++++++++++++++++------- fs/ocfs2/dlm/dlmunlock.c | 2 ++ fs/ocfs2/dlmglue.c | 3 +++ 9 files changed, 62 insertions(+), 19 deletions(-)
fs/ocfs2/dlm/dlmast.c +2 -0
@@ -191,6 +191,8 @@ static void dlm_update_lvb(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,mlog (0 ,"getting lvb from lockres for %s node\n" , lock->ml.node == dlm->node_num ?"master" :"remote" ); +mlog_bug_on_msg (!res->lvb,"lockname: %.*s\n" , + res->lockname.len, res->lockname.name);memcpy (lksb->lvb, res->lvb,DLM_LVB_LEN ); }/* Do nothing for lvb put requests - they should be done in
fs/ocfs2/dlm/dlmcommon.h +11 -5
@@ -324,12 +324,13 @@ struct dlm_lock_resourcestruct dlm_ctxt *dlm; unsigned migration_pending:1; + unsigned reserve_lvb:1;atomic_t asts_reserved;spinlock_t spinlock;wait_queue_head_t wq;u8 owner;//node which owns the lock resource, or unknown u16 state; -char lvb[DLM_LVB_LEN ]; +char *lvb;unsigned int inflight_locks;unsigned long refmap[BITS_TO_LONGS (O2NM_MAX_NODES )]; };
@@ -395,9 +396,12 @@ enum dlm_lockres_list {static inline int dlm_lvb_is_empty (char *lvb) {int i; -for (i=0 ; i<DLM_LVB_LEN ; i++) -if (lvb[i]) -return 0 ; + +if (lvb) { +for (i=0 ; i<DLM_LVB_LEN ; i++) +if (lvb[i]) +return 0 ; + }return 1 ; }
@@ -564,6 +568,7 @@ struct dlm_migratable_lockresu8 lockname_len;u8 num_locks;// locks sent in this structure u8 flags; + u8 reserve_lvb:1;__be32 total_locks;// locks to be sent for this migration cookie __be64 mig_cookie;// cookie for this lockres migration // or zero if not needed
@@ -859,7 +864,8 @@ struct dlm_lock_resource * dlm_get_lock_resource(struct dlm_ctxt *dlm, int flags);struct dlm_lock_resource *dlm_new_lockres (struct dlm_ctxt *dlm,const char *name, -unsigned int namelen); +unsigned int namelen, +unsigned int reserve_lvb);#define dlm_lockres_set_refmap_bit (bit,res) \ __dlm_lockres_set_refmap_bit(bit,res,__FILE__,__LINE__)
fs/ocfs2/dlm/dlmconvert.c +4 -1
@@ -212,8 +212,11 @@ grant:if (lock->ml.node == dlm->node_num)mlog (0 ,"doing in-place convert for nonlocal lock\n" ); lock->ml.type = type; -if (lock->lksb->flags &DLM_LKSB_PUT_LVB ) +if (lock->lksb->flags &DLM_LKSB_PUT_LVB ) { +mlog_bug_on_msg (!res->lvb,"lockname: %*s\n" , res->lockname.len, + res->lockname.name);memcpy (res->lvb, lock->lksb->lvb,DLM_LVB_LEN ); + } status =DLM_NORMAL ; *call_ast =1 ;
fs/ocfs2/dlm/dlmdebug.c +4 -2
@@ -603,9 +603,11 @@ static int dump_lockres(struct dlm_lock_resource *res, char *buf, int len)/* lvb */ out +=snprintf (buf + out, len - out,"LVBX:" ); -for (i =0 ; i <DLM_LVB_LEN ; i++) - out +=snprintf (buf + out, len - out, +if (res->lvb) { +for (i =0 ; i <DLM_LVB_LEN ; i++) + out +=snprintf (buf + out, len - out,"%02x" , (unsigned char )res->lvb[i]); + } out +=snprintf (buf + out, len - out,"\n" );/* granted */
fs/ocfs2/dlm/dlmdomain.c +5 -1
@@ -128,9 +128,13 @@ static DECLARE_WAIT_QUEUE_HEAD(dlm_domain_events);* will have a negotiated version with the same major number and a minor * number equal or smaller. The dlm_ctxt->dlm_locking_proto field should * be used to determine what a running domain is actually using. +* +* history: +* 1.0 base +* 2.0 changes dlm_migratable_lockres struct for DLM_MIG_LOCKRES_MSG */ static const struct dlm_protocol_version dlm_protocol = { - .pv_major =1 , + .pv_major =2 , .pv_minor =0 , };
fs/ocfs2/dlm/dlmmaster.c +13 -3
@@ -545,6 +545,7 @@ static void dlm_lockres_release(struct kref *kref)kmem_cache_free (dlm_lockname_cache, (void *)res->lockname.name); +kfree (res->lvb);kmem_cache_free (dlm_lockres_cache, res); }
@@ -603,13 +604,13 @@ static void dlm_init_lockres(struct dlm_ctxt *dlm,list_add_tail (&res->tracking, &dlm->tracking_list);spin_unlock (&dlm->spinlock); -memset (res->lvb,0 ,DLM_LVB_LEN );memset (res->refmap,0 ,sizeof (res->refmap)); }struct dlm_lock_resource *dlm_new_lockres (struct dlm_ctxt *dlm,const char *name, -unsigned int namelen) +unsigned int namelen, +unsigned int reserve_lvb) {struct dlm_lock_resource *res =NULL ;
@@ -621,6 +622,15 @@ struct dlm_lock_resource *dlm_new_lockres(struct dlm_ctxt *dlm,if (!res->lockname.name) goto error; + res->reserve_lvb = !!reserve_lvb; +if (res->reserve_lvb) { + res->lvb =kzalloc (DLM_LVB_LEN ,GFP_NOFS ); +if (!res->lvb) + goto error; + }else { + res->lvb =NULL ; + } +dlm_init_lockres (dlm, res, name, namelen);return res;
@@ -754,7 +764,7 @@ lookup: alloc_mle =kmem_cache_alloc (dlm_mle_cache,GFP_NOFS );if (!alloc_mle) goto leave; - res =dlm_new_lockres (dlm, lockid, namelen); + res =dlm_new_lockres (dlm, lockid, namelen, flags &LKM_VALBLK );if (!res) goto leave; goto lookup;
fs/ocfs2/dlm/dlmrecovery.c +18 -7
@@ -71,7 +71,7 @@ static inline int dlm_num_locks_in_lockres(struct dlm_lock_resource *res);static void dlm_init_migratable_lockres (struct dlm_migratable_lockres *mres,const char *lockname,int namelen,int total_locks,u64 cookie, -u8 flags,u8 master); +u8 flags,u8 master,u8 reserve_lvb); static int dlm_send_mig_lockres_msg(struct dlm_ctxt *dlm, struct dlm_migratable_lockres *mres, u8 send_to,
@@ -1148,14 +1148,20 @@ static int dlm_send_mig_lockres_msg(struct dlm_ctxt *dlm,/* zero and reinit the message buffer */ dlm_init_migratable_lockres (mres, res->lockname.name, res->lockname.len, mres_total_locks, - mig_cookie, orig_flags, orig_master); + mig_cookie, orig_flags, orig_master, + res->reserve_lvb);return ret; }static void dlm_init_migratable_lockres (struct dlm_migratable_lockres *mres, -const char *lockname,int namelen, -int total_locks,u64 cookie, -u8 flags,u8 master) +const char *lockname, +int namelen, +int total_locks, +u64 cookie, +u8 flags, +u8 master, +u8 reserve_lvb + ) {/* mres here is one full page */ clear_page (mres);
@@ -1166,6 +1172,7 @@ static void dlm_init_migratable_lockres(struct dlm_migratable_lockres *mres, mres->mig_cookie =cpu_to_be64 (cookie); mres->flags = flags; mres->master = master; + mres->reserve_lvb = !!reserve_lvb; } static void dlm_prepare_lvb_for_migration(struct dlm_lock *lock,
@@ -1282,7 +1289,8 @@ int dlm_send_one_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,dlm_init_migratable_lockres (mres, res->lockname.name, res->lockname.len, total_locks, - mig_cookie, flags, res->owner); + mig_cookie, flags, res->owner, + res->reserve_lvb); total_locks =0 ;for (i=DLM_GRANTED_LIST ; i<=DLM_BLOCKED_LIST ; i++) {
@@ -1410,7 +1418,8 @@ int dlm_mig_lockres_handler(struct o2net_msg *msg, u32 len, void *data, }else {/* need to allocate, just like if it was * mastered here normally */ - res =dlm_new_lockres (dlm, mres->lockname, mres->lockname_len); + res =dlm_new_lockres (dlm, mres->lockname, mres->lockname_len, + mres->reserve_lvb);if (!res) goto leave;
@@ -1884,6 +1893,8 @@ static int dlm_process_recovery_data(struct dlm_ctxt *dlm, goto skip_lvb;if (!dlm_lvb_is_empty (mres->lvb)) { +mlog_bug_on_msg (!res->lvb,"lockname: %.*s\n" , + res->lockname.len, res->lockname.name);if (lksb->flags &DLM_LKSB_PUT_LVB ) {/* other node was trying to update * lvb when node died. recreate the
fs/ocfs2/dlm/dlmunlock.c +2 -0
@@ -163,6 +163,8 @@ static enum dlm_status dlmunlock_common(struct dlm_ctxt *dlm,/* By now this has been masked out of cancel requests. */ if (flags &LKM_VALBLK ) {/* make the final update to the lvb */ +mlog_bug_on_msg (!res->lvb,"lockname: %.*s\n" , + res->lockname.len, res->lockname.name);if (master_node)memcpy (res->lvb, lksb->lvb,DLM_LVB_LEN );else
fs/ocfs2/dlmglue.c +3 -0
@@ -1265,6 +1265,9 @@ static int ocfs2_lock_create(struct ocfs2_super *osb,mlog (0 ,"lock %s, level = %d, flags = %u\n" , lockres->l_name, level, dlm_flags); +if (lockres->l_ops->flags &LOCK_TYPE_USES_LVB ) + dlm_flags |=DLM_LKF_VALBLK ; +spin_lock_irqsave (&lockres->l_lock, flags);if ((lockres->l_flags &OCFS2_LOCK_ATTACHED ) || (lockres->l_flags &OCFS2_LOCK_BUSY )) {
Signature · 1 line
1.7.2.2
PATCH 1/1 ocfs2/dlm: allocate lvb for dlm_lock_resource which needs it -drop2
I am taking back this patch.
I would like to add something about lvb updating to it and send it out soon.
regards,
wengang.
Quoted 26 lines · Wengang Wang
Changes to drop1:
1) adds unsigned reserve_lvb:1 todlm_lock_resourceindicating lvb should be reserved or not. This flag doesn't make sense to this patch its self, but it helps the coming patch that allocates lvb fordlm_lockwhich needs it. The 1 bit flag doesn't take extra memory space, so putting it here is fine.2) adds a new parameter to
dlm_new_lockres()indicating if lvb memory should be reserved. Determining method by checking name in v1 is discarded.3) adds u8 reserve_lvb:1 to
dlm_migratable_lockresindicating if the migration target should reserve lvb for thedlm_lock_resoucein case of needing to create a newdlm_lock_resouce.4) increment
dlm_protocolmajor version because of 3).trivial changes:
1) moves the real allocation fromdlm_init_lockres()todlm_new_lockres(). since we have the new-added parameter, we know if we should do the allocation indlm_new_lockres(). And it's better we do allocations at the same space.2) adds
DLM_LKF_VALBLKtodlm_flagsinocfs2_lock_create.
We are missing the flag. But since it's adding a new lockres(no race), so no problem running current codes.3) adds some asserts on
res->lvb.