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 <zab@versity.com>
This commit is contained in:
Zach Brown
2019-04-19 11:00:02 -07:00
committed by Zach Brown
parent 3a6392aee6
commit cfa563a4a4
2 changed files with 35 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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