[libvirt] [PATCH v2 07/38] iohelper: Remove unused mode

Michal Privoznik posted 38 patches 8 years, 9 months ago
There is a newer version of this series
[libvirt] [PATCH v2 07/38] iohelper: Remove unused mode
Posted by Michal Privoznik 8 years, 9 months ago
After 1eb6647979f8c nobody calls the iohelper with 6 arguments.
Everybody uses the other mode. Well, the only user of iohelper
after the previous commit is virFileWrapperFd really.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/util/iohelper.c | 72 ++++-------------------------------------------------
 1 file changed, 5 insertions(+), 67 deletions(-)

diff --git a/src/util/iohelper.c b/src/util/iohelper.c
index 00f31e7..d7bf5c7 100644
--- a/src/util/iohelper.c
+++ b/src/util/iohelper.c
@@ -44,35 +44,6 @@
 #define VIR_FROM_THIS VIR_FROM_STORAGE
 
 static int
-prepare(const char *path, int oflags, int mode,
-        unsigned long long offset)
-{
-    int fd = -1;
-
-    if (oflags & O_CREAT) {
-        fd = open(path, oflags, mode);
-    } else {
-        fd = open(path, oflags);
-    }
-    if (fd < 0) {
-        virReportSystemError(errno, _("Unable to open %s"), path);
-        goto cleanup;
-    }
-
-    if (offset) {
-        if (lseek(fd, offset, SEEK_SET) < 0) {
-            virReportSystemError(errno, _("Unable to seek %s to %llu"),
-                                 path, offset);
-            VIR_FORCE_CLOSE(fd);
-            goto cleanup;
-        }
-    }
-
- cleanup:
-    return fd;
-}
-
-static int
 runIO(const char *path, int fd, int oflags, unsigned long long length)
 {
     void *base = NULL; /* Location to be freed */
@@ -207,9 +178,7 @@ usage(int status)
     if (status) {
         fprintf(stderr, _("%s: try --help for more details"), program_name);
     } else {
-        printf(_("Usage: %s FILENAME OFLAGS MODE OFFSET LENGTH DELETE\n"
-                 "   or: %s FILENAME LENGTH FD\n"),
-               program_name, program_name);
+        printf(_("Usage: %s FILENAME LENGTH FD\n"), program_name);
     }
     exit(status);
 }
@@ -218,13 +187,9 @@ int
 main(int argc, char **argv)
 {
     const char *path;
-    unsigned long long offset;
     unsigned long long length;
     int oflags = -1;
-    int mode;
-    unsigned int delete = 0;
     int fd = -1;
-    int lengthIndex = 0;
 
     program_name = argv[0];
 
@@ -239,31 +204,13 @@ main(int argc, char **argv)
 
     if (argc > 1 && STREQ(argv[1], "--help"))
         usage(EXIT_SUCCESS);
-    if (argc == 7) { /* FILENAME OFLAGS MODE OFFSET LENGTH DELETE */
-        lengthIndex = 5;
-        if (virStrToLong_i(argv[2], NULL, 10, &oflags) < 0) {
-            fprintf(stderr, _("%s: malformed file flags %s"),
+    if (argc == 4) { /* FILENAME LENGTH FD */
+        if (virStrToLong_ull(argv[2], NULL, 10, &length) < 0) {
+            fprintf(stderr, _("%s: malformed file length %s"),
                     program_name, argv[2]);
             exit(EXIT_FAILURE);
         }
-        if (virStrToLong_i(argv[3], NULL, 10, &mode) < 0) {
-            fprintf(stderr, _("%s: malformed file mode %s"),
-                    program_name, argv[3]);
-            exit(EXIT_FAILURE);
-        }
-        if (virStrToLong_ull(argv[4], NULL, 10, &offset) < 0) {
-            fprintf(stderr, _("%s: malformed file offset %s"),
-                    program_name, argv[4]);
-            exit(EXIT_FAILURE);
-        }
-        if (argc == 7 && virStrToLong_ui(argv[6], NULL, 10, &delete) < 0) {
-            fprintf(stderr, _("%s: malformed delete flag %s"),
-                    program_name, argv[6]);
-            exit(EXIT_FAILURE);
-        }
-        fd = prepare(path, oflags, mode, offset);
-    } else if (argc == 4) { /* FILENAME LENGTH FD */
-        lengthIndex = 2;
+
         if (virStrToLong_i(argv[3], NULL, 10, &fd) < 0) {
             fprintf(stderr, _("%s: malformed fd %s"),
                     program_name, argv[3]);
@@ -287,18 +234,9 @@ main(int argc, char **argv)
         usage(EXIT_FAILURE);
     }
 
-    if (virStrToLong_ull(argv[lengthIndex], NULL, 10, &length) < 0) {
-        fprintf(stderr, _("%s: malformed file length %s"),
-                program_name, argv[lengthIndex]);
-        exit(EXIT_FAILURE);
-    }
-
     if (fd < 0 || runIO(path, fd, oflags, length) < 0)
         goto error;
 
-    if (delete)
-        unlink(path);
-
     return 0;
 
  error:
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 07/38] iohelper: Remove unused mode
Posted by John Ferlan 8 years, 9 months ago

On 04/20/2017 06:01 AM, Michal Privoznik wrote:
> After 1eb6647979f8c nobody calls the iohelper with 6 arguments.
> Everybody uses the other mode. Well, the only user of iohelper
> after the previous commit is virFileWrapperFd really.

Are we talking two commits ago?  Couldn't this then be merged with that
to make it more obvious with the commit message adjustment indicating
now that the commit is the last consumer/caller of iohelper with so many
arguments. It also shows where you've essentially moved the code.

ACK if I've read properly and this moves...

Still a little concerned over the timing of patch 5 w/r/t release
timing, but I suppose we have a few days for something to pop up.

John

FYI: Going to stop here for now - I'll look to look at the rest in the
morning.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 07/38] iohelper: Remove unused mode
Posted by Michal Privoznik 8 years, 9 months ago
On 04/27/2017 09:47 PM, John Ferlan wrote:
> 
> 
> On 04/20/2017 06:01 AM, Michal Privoznik wrote:
>> After 1eb6647979f8c nobody calls the iohelper with 6 arguments.
>> Everybody uses the other mode. Well, the only user of iohelper
>> after the previous commit is virFileWrapperFd really.
> 
> Are we talking two commits ago? 

No.

commit 1eb6647979f8c657958069a28df713deab3052a6
Author:     Eric Blake <eblake@redhat.com>
AuthorDate: Tue Jul 12 09:17:52 2011 -0600


> Couldn't this then be merged with that
> to make it more obvious with the commit message adjustment indicating
> now that the commit is the last consumer/caller of iohelper with so many
> arguments. It also shows where you've essentially moved the code.

This could be moved in front of 06/32 as it is independent of it. Even
without any other patch of the series this one can be pushed in. Nobody
uses this mode in iohelper for nearly 6 years.

> 
> ACK if I've read properly and this moves...

So do you read properly? ;-)

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 07/38] iohelper: Remove unused mode
Posted by John Ferlan 8 years, 9 months ago

On 04/28/2017 07:42 AM, Michal Privoznik wrote:
> On 04/27/2017 09:47 PM, John Ferlan wrote:
>>
>>
>> On 04/20/2017 06:01 AM, Michal Privoznik wrote:
>>> After 1eb6647979f8c nobody calls the iohelper with 6 arguments.
>>> Everybody uses the other mode. Well, the only user of iohelper
>>> after the previous commit is virFileWrapperFd really.
>>
>> Are we talking two commits ago? 
> 
> No.
> 
> commit 1eb6647979f8c657958069a28df713deab3052a6
> Author:     Eric Blake <eblake@redhat.com>
> AuthorDate: Tue Jul 12 09:17:52 2011 -0600
> 
> 
>> Couldn't this then be merged with that
>> to make it more obvious with the commit message adjustment indicating
>> now that the commit is the last consumer/caller of iohelper with so many
>> arguments. It also shows where you've essentially moved the code.
> 
> This could be moved in front of 06/32 as it is independent of it. Even
> without any other patch of the series this one can be pushed in. Nobody
> uses this mode in iohelper for nearly 6 years.
> 
>>
>> ACK if I've read properly and this moves...
> 
> So do you read properly? ;-)
> 
> Michal
> 

Oh - so I guess I was "assuming" that this removal had more to do with
the additions in patch 5. Ordering is a powerful thing! That is I
thought that it was being done in this order because patch 5 removed the
last instance of the the extra parameters. Obviously I didn't go
check/follow that premise 'cause I was too lazy relying on you to let me
know!

John

Be gone old code of lore and take with you your arcane ways.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list