Skip to contentSkip to conversation

dlm_controld: more plock fixes and cleanups

PATCH New Alexander Aring 1 participant 4 messages Mar 17, 2023

lore
Share & tools
lore
#0 lore raw

cover dlm_controld: more plock fixes and cleanups

Hi,

more patches of fixes and cleanups found by Andreas Gruenbacher.

Changes by me:

Added more cases when waiter struct is allocated by malloc() and flags is not zeroed.

Thanks.

Andreas Gruenbacher (3):
dlm_controld: initialize waiter->flags
dlm_controld: get rid of unnecessary memset
dlm_controld: remove unnecessary list_empty check

 dlm_controld/plock.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/3 dlm_controld: initialize waiter->flags

From: Andreas Gruenbacher <[email protected]>

In function add_waiter(), waiter->flags is left uninitialized. Fix that.

In function add_lock(), the allocated lock is zeroed out and then all fields except po->flags are initialized. That's not wrong, but it seems easier to initialize po->flags instead, like add_waiter() does now.

---
 dlm_controld/plock.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
dlm_controld/plock.c +4 -1
index 24ad777a..f03f3abe 100644
@@ -455,7 +455,6 @@ static int add_lock(struct resource *r, uint32_t nodeid, uint64_t owner,
 	po = malloc(sizeof(struct posix_lock));
 	if (!po)
 		return -ENOMEM;
-	memset(po, 0, sizeof(struct posix_lock));
 
 	po->start = start;
 	po->end = end;
@@ -463,6 +462,7 @@ static int add_lock(struct resource *r, uint32_t nodeid, uint64_t owner,
 	po->owner = owner;
 	po->pid = pid;
 	po->ex = ex;
+	po->flags = 0;
 	list_add_tail(&po->list, &r->locks);
 
 	return 0;
@@ -680,6 +680,7 @@ static int add_waiter(struct lockspace *ls, struct resource *r,
 	if (!w)
 		return -ENOMEM;
 	memcpy(&w->info, in, sizeof(struct dlm_plock_info));
+	w->flags = 0;
 	list_add_tail(&w->list, &r->waiters);
 	return 0;
 }
@@ -1095,6 +1096,7 @@ static void save_pending_plock(struct lockspace *ls, struct resource *r,
 		return;
 	}
 	memcpy(&w->info, in, sizeof(struct dlm_plock_info));
+	w->flags = 0;
 	list_add_tail(&w->list, &r->pending);
 }
 
@@ -1967,6 +1969,7 @@ void receive_plocks_data(struct lockspace *ls, struct dlm_header *hd, int len)
 			w->info.pid	= le32_to_cpu(pp->pid);
 			w->info.nodeid	= le32_to_cpu(pp->nodeid);
 			w->info.ex	= pp->ex;
+			w->flags	= 0;
 			list_add_tail(&w->list, &r->waiters);
 		}
 		pp++;
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/3 dlm_controld: get rid of unnecessary memset

In reply to Alexander Aring

From: Andreas Gruenbacher <[email protected]>

In process_plocks(), we're reading in the entire info object, so there is no need to zero out the buffer first.

---
 dlm_controld/plock.c | 2 --
 1 file changed, 2 deletions(-)
dlm_controld/plock.c +0 -2
index f03f3abe..85d6fdf2 100644
@@ -1523,8 +1523,6 @@ void process_plocks(int ci)
 
 	gettimeofday(&now, NULL);
 
-	memset(&info, 0, sizeof(info));
-
 	rv = do_read(plock_device_fd, &info, sizeof(info));
 	if (rv < 0) {
 		log_debug("process_plocks: read error %d fd %d\n",
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/3 dlm_controld: remove unnecessary list_empty check

In reply to Alexander Aring

From: Andreas Gruenbacher <[email protected]>

All that do_waiters() does is iterate the the waiters list of a resource, so there is no need to check if the waiters list is empty before calling do_waiters().

---
 dlm_controld/plock.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
dlm_controld/plock.c +1 -2
index 85d6fdf2..ad9b0f27 100644
@@ -2055,8 +2055,7 @@ void purge_plocks(struct lockspace *ls, int nodeid, int unmount)
 			send_pending_plocks(ls, r);
 		}
 		
-		if (!list_empty(&r->waiters))
-			do_waiters(ls, r);
+		do_waiters(ls, r);
 
 		if (!opt(plock_ownership_ind) &&
 		    list_empty(&r->locks) && list_empty(&r->waiters)) {
Signature · 1 line
2.31.1