From cfa563a4a4b04303d788302fa6827bfdc841582f Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Fri, 19 Apr 2019 11:00:02 -0700 Subject: [PATCH] scoutfs: expand the per_task API This adds some minor functionality to the per_task API for use by the upcoming offline waiting work. Add scoutfs_per_task_add_excl() so that a caller can tell if their task was already put on a per-task list by their caller. Make scoutfs_per_task_del() return a bool to indicate if the entry was found on a list and was in fact deleted, or not. Add scoutfs_per_task_init_entry() for initializing entries that aren't declared on the stack. Signed-off-by: Zach Brown --- kmod/src/per_task.c | 32 +++++++++++++++++++++++++++++++- kmod/src/per_task.h | 5 ++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/kmod/src/per_task.c b/kmod/src/per_task.c index 24b7f412..c0424e4d 100644 --- a/kmod/src/per_task.c +++ b/kmod/src/per_task.c @@ -62,7 +62,27 @@ void scoutfs_per_task_add(struct scoutfs_per_task *pt, spin_unlock(&pt->lock); } -void scoutfs_per_task_del(struct scoutfs_per_task *pt, +/* + * Add the entry to the per-task list if the task didn't already have an + * entry on the list. Returns true if the entry was added, false if it + * wasn't. + */ +bool scoutfs_per_task_add_excl(struct scoutfs_per_task *pt, + struct scoutfs_per_task_entry *ent, void *ptr) +{ + if (!scoutfs_per_task_get(pt)) { + scoutfs_per_task_add(pt, ent, ptr); + return true; + } + + return false; +} + +/* + * Return true if the entry was found on the list and was deleted, + * returns false if the entry wasn't present on a list. + */ +bool scoutfs_per_task_del(struct scoutfs_per_task *pt, struct scoutfs_per_task_entry *ent) { BUG_ON(!list_empty(&ent->head) && ent->task != current); @@ -71,7 +91,10 @@ void scoutfs_per_task_del(struct scoutfs_per_task *pt, spin_lock(&pt->lock); list_del_init(&ent->head); spin_unlock(&pt->lock); + return true; } + + return false; } void scoutfs_per_task_init(struct scoutfs_per_task *pt) @@ -79,3 +102,10 @@ void scoutfs_per_task_init(struct scoutfs_per_task *pt) spin_lock_init(&pt->lock); INIT_LIST_HEAD(&pt->list); } + +void scoutfs_per_task_init_entry(struct scoutfs_per_task_entry *ent) +{ + INIT_LIST_HEAD(&ent->head); + ent->task = NULL; + ent->ptr = NULL; +} diff --git a/kmod/src/per_task.h b/kmod/src/per_task.h index 6a055391..38616616 100644 --- a/kmod/src/per_task.h +++ b/kmod/src/per_task.h @@ -21,8 +21,11 @@ struct scoutfs_per_task_entry { void *scoutfs_per_task_get(struct scoutfs_per_task *pt); void scoutfs_per_task_add(struct scoutfs_per_task *pt, struct scoutfs_per_task_entry *ent, void *ptr); -void scoutfs_per_task_del(struct scoutfs_per_task *pt, +bool scoutfs_per_task_add_excl(struct scoutfs_per_task *pt, + struct scoutfs_per_task_entry *ent, void *ptr); +bool scoutfs_per_task_del(struct scoutfs_per_task *pt, struct scoutfs_per_task_entry *ent); void scoutfs_per_task_init(struct scoutfs_per_task *pt); +void scoutfs_per_task_init_entry(struct scoutfs_per_task_entry *ent); #endif