0a122b
From 5b9d5a4f0e351dc73b31507b56334f7ef692f20c Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <5b9d5a4f0e351dc73b31507b56334f7ef692f20c.1387298827.git.minovotn@redhat.com>
0a122b
In-Reply-To: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
References: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
From: "Michael S. Tsirkin" <mst@redhat.com>
0a122b
Date: Tue, 17 Dec 2013 15:16:55 +0100
0a122b
Subject: [PATCH 03/56] range: add min/max operations on ranges
0a122b
0a122b
RH-Author: Michael S. Tsirkin <mst@redhat.com>
0a122b
Message-id: <1387293161-4085-4-git-send-email-mst@redhat.com>
0a122b
Patchwork-id: 56308
0a122b
O-Subject: [PATCH qemu-kvm RHEL7.0 v2 03/57] range: add min/max operations on ranges
0a122b
Bugzilla: 1034876
0a122b
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
0a122b
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
0a122b
0a122b
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
0a122b
(cherry picked from commit c5a22c4344f17169bb20e122e9d935c62aedc063)
0a122b
---
0a122b
 include/qemu/range.h | 18 ++++++++++++++++++
0a122b
 1 file changed, 18 insertions(+)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 include/qemu/range.h | 18 ++++++++++++++++++
0a122b
 1 file changed, 18 insertions(+)
0a122b
0a122b
diff --git a/include/qemu/range.h b/include/qemu/range.h
0a122b
index 4a0780d..aae9720 100644
0a122b
--- a/include/qemu/range.h
0a122b
+++ b/include/qemu/range.h
0a122b
@@ -17,6 +17,24 @@ struct Range {
0a122b
     uint64_t end;   /* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */
0a122b
 };
0a122b
 
0a122b
+static inline void range_extend(Range *range, Range *extend_by)
0a122b
+{
0a122b
+    if (!extend_by->begin && !extend_by->end) {
0a122b
+        return;
0a122b
+    }
0a122b
+    if (!range->begin && !range->end) {
0a122b
+        *range = *extend_by;
0a122b
+        return;
0a122b
+    }
0a122b
+    if (range->begin > extend_by->begin) {
0a122b
+        range->begin = extend_by->begin;
0a122b
+    }
0a122b
+    /* Compare last byte in case region ends at ~0x0LL */
0a122b
+    if (range->end - 1 < extend_by->end - 1) {
0a122b
+        range->end = extend_by->end;
0a122b
+    }
0a122b
+}
0a122b
+
0a122b
 /* Get last byte of a range from offset + length.
0a122b
  * Undefined for ranges that wrap around 0. */
0a122b
 static inline uint64_t range_get_last(uint64_t offset, uint64_t len)
0a122b
-- 
0a122b
1.7.11.7
0a122b