diff mbox series

[v11,09/17] rangeset: add rangeset_empty() function

Message ID 20231202012556.2012281-10-volodymyr_babchuk@epam.com (mailing list archive)
State New, archived
Headers show
Series PCI devices passthrough on Arm, part 3 | expand

Commit Message

Volodymyr Babchuk Dec. 2, 2023, 1:27 a.m. UTC
This function can be used when user wants to remove all rangeset
entries but do not want to destroy rangeset itself.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>

---
Changes in v11:
 - Now the function only empties rangeset, without removing it from
   domain's list

Changes in v10:
 - New in v10. The function is used in "vpci/header: handle p2m range sets per BAR"
---
 xen/common/rangeset.c      | 16 ++++++++++++----
 xen/include/xen/rangeset.h |  3 ++-
 2 files changed, 14 insertions(+), 5 deletions(-)

Comments

Jan Beulich Dec. 4, 2023, 8:36 a.m. UTC | #1
On 02.12.2023 02:27, Volodymyr Babchuk wrote:
> This function can be used when user wants to remove all rangeset
> entries but do not want to destroy rangeset itself.

I have to admit that I'm not happy with the name: We're not consistently
naming all predicate-like helpers is_...() (see e.g. cpumask_empty()).
May I suggest to use something which unambiguously expresses an action to
be taken, e.g. rangeset_purge(), rangeset_reset(), or (less suitable as
some ambiguity would remain, yet it would be in line with e.g.
cpumask_clear()) rangeset_clear()?

Jan
Volodymyr Babchuk Dec. 5, 2023, 12:52 a.m. UTC | #2
Hi Jan,

Jan Beulich <jbeulich@suse.com> writes:

> On 02.12.2023 02:27, Volodymyr Babchuk wrote:
>> This function can be used when user wants to remove all rangeset
>> entries but do not want to destroy rangeset itself.
>
> I have to admit that I'm not happy with the name: We're not consistently
> naming all predicate-like helpers is_...() (see e.g. cpumask_empty()).
> May I suggest to use something which unambiguously expresses an action to
> be taken, e.g. rangeset_purge(), rangeset_reset(), or (less suitable as
> some ambiguity would remain, yet it would be in line with e.g.
> cpumask_clear()) rangeset_clear()?

Naming this is not my best trait, so I am open for any suggestions. From
all proposed variants I like rangeset_purge() most. So if there are no
other objections, I'll rename this function in the next version.
Roger Pau Monné Dec. 21, 2023, 3:45 p.m. UTC | #3
On Mon, Dec 04, 2023 at 09:36:16AM +0100, Jan Beulich wrote:
> On 02.12.2023 02:27, Volodymyr Babchuk wrote:
> > This function can be used when user wants to remove all rangeset
> > entries but do not want to destroy rangeset itself.
> 
> I have to admit that I'm not happy with the name: We're not consistently
> naming all predicate-like helpers is_...() (see e.g. cpumask_empty()).
> May I suggest to use something which unambiguously expresses an action to
> be taken, e.g. rangeset_purge(), rangeset_reset(), or (less suitable as
> some ambiguity would remain, yet it would be in line with e.g.
> cpumask_clear()) rangeset_clear()?

rangeset_purge() would be my preference probably, second option would
be rangeset_clear().

Thanks, Roger.
diff mbox series

Patch

diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c
index 0ccd53caac..d0c525cb50 100644
--- a/xen/common/rangeset.c
+++ b/xen/common/rangeset.c
@@ -448,11 +448,20 @@  struct rangeset *rangeset_new(
     return r;
 }
 
-void rangeset_destroy(
-    struct rangeset *r)
+void rangeset_empty(struct rangeset *r)
 {
     struct range *x;
 
+    if ( r == NULL )
+        return;
+
+    while ( (x = first_range(r)) != NULL )
+        destroy_range(r, x);
+}
+
+void rangeset_destroy(
+    struct rangeset *r)
+{
     if ( r == NULL )
         return;
 
@@ -463,8 +472,7 @@  void rangeset_destroy(
         spin_unlock(&r->domain->rangesets_lock);
     }
 
-    while ( (x = first_range(r)) != NULL )
-        destroy_range(r, x);
+    rangeset_empty(r);
 
     xfree(r);
 }
diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h
index 87bd956962..62cb67b49b 100644
--- a/xen/include/xen/rangeset.h
+++ b/xen/include/xen/rangeset.h
@@ -56,7 +56,7 @@  void rangeset_limit(
 bool __must_check rangeset_is_empty(
     const struct rangeset *r);
 
-/* Add/claim/remove/query a numeric range. */
+/* Add/claim/remove/query/empty a numeric range. */
 int __must_check rangeset_add_range(
     struct rangeset *r, unsigned long s, unsigned long e);
 int __must_check rangeset_claim_range(struct rangeset *r, unsigned long size,
@@ -70,6 +70,7 @@  bool __must_check rangeset_overlaps_range(
 int rangeset_report_ranges(
     struct rangeset *r, unsigned long s, unsigned long e,
     int (*cb)(unsigned long s, unsigned long e, void *data), void *ctxt);
+void rangeset_empty(struct rangeset *r);
 
 /*
  * Note that the consume function can return an error value apart from