Skip to contentSkip to conversation

Added function prototypes to libxl_utils.h and function definitions to libxl_utils.c for the logical 'or'-ing and logical 'and'-ing of two bitmaps

PATCH In review Linda Jacobson 2 participants 4 messages Apr 10, 2015 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Added function prototypes to libxl_utils.h and function definitions to libxl_utils.c for the logical 'or'-ing and logical 'and'-ing of two bitmaps

Linda Jacobson

---
 tools/libxl/libxl_utils.c   | 51 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_utils.h   |  6 ++++++
 tools/libxl/libxlu_disk_l.c |  8 ++-----
 tools/libxl/libxlu_disk_l.h |  6 +-----
 4 files changed, 60 insertions(+), 11 deletions(-)
tools/libxl/libxl_utils.c +51 -0
index 9053b27..5b1fab8 100644
@@ -691,6 +691,57 @@ void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit)
     bitmap->map[bit / 8] &= ~(1 << (bit & 7));
 }
 
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2)
+{
+    uint32_t size;
+    int rc;
+    int bit;
+
+    GC_INIT(ctx);
+/* if bitmaps aren't the same size, or should be size of larger bit map
+*/
+    size = max(map1->size, map2->size);
+    rc = libxl_bitmap_alloc(ctx, or_map, size);
+    if (rc)
+        goto out;
+    for (bit = 0; bit < (size * 8); bit++)
+    {
+        if (libxl_bitmap_test(map1, bit))
+            libxl_bitmap_set(or_map, bit);
+        else if (libxl_bitmap_test(map2, bit))
+            libxl_bitmap_set(or_map, bit);
+    }
+out:
+    GC_FREE;
+    return rc;
+} 
+
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2)
+{
+    uint32_t size;
+    int rc;
+    int bit;
+
+    GC_INIT(ctx);
+/* if bitmaps aren't same size, 'and' should be size of smaller bit map
+*/ 
+    size = min(map1->size, map2->size);
+    rc = libxl_bitmap_alloc(ctx, and_map, size);
+    if (rc)
+        goto out;
+    for (bit = 0; bit < (size * 8); bit++)
+    {
+        if (libxl_bitmap_test (map1, bit) && 
+            libxl_bitmap_test (map2, bit) )
+            libxl_bitmap_set (and_map, bit);
+    }
+out:
+    GC_FREE;
+    return rc;
+ } 
+
 int libxl_bitmap_count_set(const libxl_bitmap *bitmap)
 {
     int i, nr_set_bits = 0;
tools/libxl/libxl_utils.h +6 -0
index 68b5580..1ba2b44 100644
@@ -91,6 +91,12 @@ void libxl_bitmap_set(libxl_bitmap *bitmap, int bit);
 void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit);
 int libxl_bitmap_count_set(const libxl_bitmap *bitmap);
 char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *bitmap);
+/* or, and and xor functions for two bitmaps
+ */
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *new_bitmap,
+                    libxl_bitmap *bitmap1, libxl_bitmap *bitmap2); 
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *new_bitmap,
+                     libxl_bitmap *bitmap1, libxl_bitmap *bitmap2);
 static inline void libxl_bitmap_set_any(libxl_bitmap *bitmap)
 {
     memset(bitmap->map, -1, bitmap->size);
tools/libxl/libxlu_disk_l.c +2 -6
index beea7f9..2c6e8e3 100644
@@ -1011,10 +1011,6 @@ int xlu__disk_yyget_lineno (yyscan_t yyscanner );
 
 void xlu__disk_yyset_lineno (int line_number ,yyscan_t yyscanner );
 
-int xlu__disk_yyget_column  (yyscan_t yyscanner );
-
-void xlu__disk_yyset_column (int column_no ,yyscan_t yyscanner );
-
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  */
@@ -1159,7 +1155,7 @@ YY_DECL
 
  /*----- the scanner rules which do the parsing -----*/
 
-#line 1163 "libxlu_disk_l.c"
+#line 1159 "libxlu_disk_l.c"
 
 	if ( !yyg->yy_init )
 		{
@@ -1502,7 +1498,7 @@ YY_RULE_SETUP
 #line 259 "libxlu_disk_l.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
 	YY_BREAK
-#line 1506 "libxlu_disk_l.c"
+#line 1502 "libxlu_disk_l.c"
 			case YY_STATE_EOF(INITIAL):
 			case YY_STATE_EOF(LEXERR):
 				yyterminate();
tools/libxl/libxlu_disk_l.h +1 -5
index f615582..08f60e5 100644
@@ -280,10 +280,6 @@ int xlu__disk_yyget_lineno (yyscan_t yyscanner );
 
 void xlu__disk_yyset_lineno (int line_number ,yyscan_t yyscanner );
 
-int xlu__disk_yyget_column  (yyscan_t yyscanner );
-
-void xlu__disk_yyset_column (int column_no ,yyscan_t yyscanner );
-
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  */
@@ -350,6 +346,6 @@ extern int xlu__disk_yylex (yyscan_t yyscanner);
 
 #line 259 "libxlu_disk_l.l"
 
-#line 354 "libxlu_disk_l.h"
+#line 350 "libxlu_disk_l.h"
 #undef xlu__disk_yyIN_HEADER
 #endif /* xlu__disk_yyHEADER_H */
Signature · 1 line
1.9.1
#1 lore raw

Please edit the subject line to be more concise. Something like:
libxl: provide libxl_bitmap_{and,or}

Quoted 1 line · Linda Jacobson

Linda Jacobson

You need to properly sign off this patch. See

http://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches

Quoted 6 lines
---
 tools/libxl/libxl_utils.c   | 51 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_utils.h   |  6 ++++++
 tools/libxl/libxlu_disk_l.c |  8 ++-----
 tools/libxl/libxlu_disk_l.h |  6 +-----

The changes to libxlu_disk_* are not necessary. Presumably this is due to you have different version of bison / flex installed.

I guess you used "git commit -a" to commit all the changes, right?

To avoid committing unrelated changes, you can use

   $ git add libxl_utils.c
   $ git add libxl_utils.h
   $ git commit -s

to only commit changes to libxl_utils.{c,h}.

(the "-s" for git commit will nicely generate a Signed-off-by line for you, provided you have configured your name and email properly in git)

Quoted 10 lines
 4 files changed, 60 insertions(+), 11 deletions(-)
tools/libxl/libxl_utils.c +0 -0
index 9053b27..5b1fab8 100644
@@ -691,6 +691,57 @@ void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit)
     bitmap->map[bit / 8] &= ~(1 << (bit & 7));
 }
 

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 703

Quoted 10 lines
tools/libxl/libxl_utils.c +10 -0
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2)
+{
+    uint32_t size;
+    int rc;
+    int bit;
+
+    GC_INIT(ctx);
+/* if bitmaps aren't the same size, or should be size of larger bit map
+*/

The indentation of this comment needs to be fixed.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 707

Quoted 4 lines
tools/libxl/libxl_utils.c +4 -0
+    size = max(map1->size, map2->size);
+    rc = libxl_bitmap_alloc(ctx, or_map, size);
+    if (rc)
+        goto out;

Add a blank line here.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 709

Quoted 2 lines
tools/libxl/libxl_utils.c +2 -0
+    for (bit = 0; bit < (size * 8); bit++)
+    {

Please move the `{' to the end of last line.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 714

Quoted 5 lines
tools/libxl/libxl_utils.c +5 -0
+        if (libxl_bitmap_test(map1, bit))
+            libxl_bitmap_set(or_map, bit);
+        else if (libxl_bitmap_test(map2, bit))
+            libxl_bitmap_set(or_map, bit);
+    }

Add a blank line here.

Quoted 5 lines
tools/libxl/libxl_utils.c +5 -0
+out:
+    GC_FREE;
+    return rc;
+} 
+

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 729

Quoted 10 lines
tools/libxl/libxl_utils.c +10 -0
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2)
+{
+    uint32_t size;
+    int rc;
+    int bit;
+
+    GC_INIT(ctx);
+/* if bitmaps aren't same size, 'and' should be size of smaller bit map
+*/ 

Fix indentation please.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 733

Quoted 4 lines
tools/libxl/libxl_utils.c +4 -0
+    size = min(map1->size, map2->size);
+    rc = libxl_bitmap_alloc(ctx, and_map, size);
+    if (rc)
+        goto out;

Add blank line.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 735

Quoted 2 lines
tools/libxl/libxl_utils.c +2 -0
+    for (bit = 0; bit < (size * 8); bit++)
+    {

Move `{' up.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 737

Quoted 2 lines
tools/libxl/libxl_utils.c +2 -0
+        if (libxl_bitmap_test (map1, bit) && 
+            libxl_bitmap_test (map2, bit) )
                                            ^
                                            extraneous space

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 739

Quoted 2 lines
tools/libxl/libxl_utils.c +2 -0
+            libxl_bitmap_set (and_map, bit);
+    }

Add a blank line.

Quoted 13 lines
tools/libxl/libxl_utils.c +5 -0
+out:
+    GC_FREE;
+    return rc;
+ } 
+
 int libxl_bitmap_count_set(const libxl_bitmap *bitmap)
 {
     int i, nr_set_bits = 0;
tools/libxl/libxl_utils.h +0 -0
index 68b5580..1ba2b44 100644

tools/libxl/libxl_utils.h void libxl_bitmap_set(libxl_bitmap *bitmap, int bit); · line 96

Quoted 6 lines
tools/libxl/libxl_utils.h +3 -0
@@ -91,6 +91,12 @@ void libxl_bitmap_set(libxl_bitmap *bitmap, int bit);
 void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit);
 int libxl_bitmap_count_set(const libxl_bitmap *bitmap);
 char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *bitmap);
+/* or, and and xor functions for two bitmaps
+ */
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *new_bitmap,

or_bitmap

Use the same name you used in actual function.

tools/libxl/libxl_utils.h void libxl_bitmap_set(libxl_bitmap *bitmap, int bit); · line 98

Quoted 2 lines
tools/libxl/libxl_utils.h +2 -0
+                    libxl_bitmap *bitmap1, libxl_bitmap *bitmap2); 
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *new_bitmap,

and_bitmap

Quoted 6 lines
tools/libxl/libxl_utils.h +1 -0
+                     libxl_bitmap *bitmap1, libxl_bitmap *bitmap2);
 
 
 static inline void libxl_bitmap_set_any(libxl_bitmap *bitmap)
 {
     memset(bitmap->map, -1, bitmap->size);

The rest (changes to libxlu_disk_l.*) should not be committed.

Wei.

Quoted 58 lines
tools/libxl/libxlu_disk_l.c +2 -6
index beea7f9..2c6e8e3 100644
@@ -1011,10 +1011,6 @@ int xlu__disk_yyget_lineno (yyscan_t yyscanner );
 
 void xlu__disk_yyset_lineno (int line_number ,yyscan_t yyscanner );
 
-int xlu__disk_yyget_column  (yyscan_t yyscanner );
-
-void xlu__disk_yyset_column (int column_no ,yyscan_t yyscanner );
-
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  */
@@ -1159,7 +1155,7 @@ YY_DECL
 
  /*----- the scanner rules which do the parsing -----*/
 
-#line 1163 "libxlu_disk_l.c"
+#line 1159 "libxlu_disk_l.c"
 
 	if ( !yyg->yy_init )
 		{
@@ -1502,7 +1498,7 @@ YY_RULE_SETUP
 #line 259 "libxlu_disk_l.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
 	YY_BREAK
-#line 1506 "libxlu_disk_l.c"
+#line 1502 "libxlu_disk_l.c"
 			case YY_STATE_EOF(INITIAL):
 			case YY_STATE_EOF(LEXERR):
 				yyterminate();
tools/libxl/libxlu_disk_l.h +1 -5
index f615582..08f60e5 100644
@@ -280,10 +280,6 @@ int xlu__disk_yyget_lineno (yyscan_t yyscanner );
 
 void xlu__disk_yyset_lineno (int line_number ,yyscan_t yyscanner );
 
-int xlu__disk_yyget_column  (yyscan_t yyscanner );
-
-void xlu__disk_yyset_column (int column_no ,yyscan_t yyscanner );
-
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  */
@@ -350,6 +346,6 @@ extern int xlu__disk_yylex (yyscan_t yyscanner);
 
 #line 259 "libxlu_disk_l.l"
 
-#line 354 "libxlu_disk_l.h"
+#line 350 "libxlu_disk_l.h"
 #undef xlu__disk_yyIN_HEADER
 #endif /* xlu__disk_yyHEADER_H */
Signature · 1 line
1.9.1
#4 lore raw
In reply to a message not in the archive

Now really CC xen-devel. :-/

Quoted 52 lines · Wei Liu

CC xen-devel. Please use reply-all in the future.

Quoted 28 lines · Linda

a few questions below, and I'll make all the changes you suggest.

Quoted 25 lines · Wei Liu

Please edit the subject line to be more concise. Something like:
libxl: provide libxl_bitmap_{and,or}

Quoted 1 line · Linda Jacobson

Linda Jacobson

You need to properly sign off this patch. See

http://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches

Quoted 5 lines
---
 tools/libxl/libxl_utils.c   | 51 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_utils.h   |  6 ++++++
 tools/libxl/libxlu_disk_l.c |  8 ++-----
 tools/libxl/libxlu_disk_l.h |  6 +-----

The changes to libxlu_disk_* are not necessary. Presumably this is due to you have different version of bison / flex installed.

I guess you used "git commit -a" to commit all the changes, right?

To avoid committing unrelated changes, you can use

   $ git add libxl_utils.c
   $ git add libxl_utils.h
   $ git commit -s
Quoted 6 lines
Quoted 4 lines

to only commit changes to libxl_utils.{c,h}.

(the "-s" for git commit will nicely generate a Signed-off-by line for you, provided you have configured your name and email properly in git)

I hope I configured my name and email properly - I used git user.name (Linda Jacobson) and git user.email ([email protected]). Is that correct? I think

I think so.

Quoted 3 lines

that the -s is the way I did it last time, because it did give me a signature.

Yes, that's what we want.

Quoted 1 line

So how do I uncommit the things I accidentally committed?

git reset HEAD^ can reset your commit (provided the first commit in your tree is this commit).

Wei.

author
#5 lore raw
Quoted 52 lines · Wei Liu

Now really CC xen-devel. :-/

Quoted 49 lines · Wei Liu

CC xen-devel. Please use reply-all in the future.

Quoted 28 lines · Linda

a few questions below, and I'll make all the changes you suggest.

Quoted 25 lines · Wei Liu

Please edit the subject line to be more concise. Something like:

   libxl: provide libxl_bitmap_{and,or}
Quoted 1 line · Linda Jacobson

Linda Jacobson

You need to properly sign off this patch. See

http://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches

Quoted 5 lines
---
  tools/libxl/libxl_utils.c   | 51 +++++++++++++++++++++++++++++++++++++++++++++
  tools/libxl/libxl_utils.h   |  6 ++++++
  tools/libxl/libxlu_disk_l.c |  8 ++-----
  tools/libxl/libxlu_disk_l.h |  6 +-----

The changes to libxlu_disk_* are not necessary. Presumably this is due to you have different version of bison / flex installed.

I guess you used "git commit -a" to commit all the changes, right?

To avoid committing unrelated changes, you can use

    $ git add libxl_utils.c
    $ git add libxl_utils.h
    $ git commit -s
Quoted 6 lines
Quoted 4 lines

to only commit changes to libxl_utils.{c,h}.

(the "-s" for git commit will nicely generate a Signed-off-by line for you, provided you have configured your name and email properly in git)

I hope I configured my name and email properly - I used git user.name (Linda Jacobson) and git user.email ([email protected]). Is that correct? I think

I think so.

Quoted 3 lines

that the -s is the way I did it last time, because it did give me a signature.

Yes, that's what we want.

Quoted 1 line

So how do I uncommit the things I accidentally committed?

git reset HEAD^ can reset your commit (provided the first commit in your tree is this commit).

Wei.

It should be. I've got to go now, but the fixes will be in late today (mid-day here). And thanks, for all your help and guidance.

Linda