LVS
lvs-users
Google
 
Web LinuxVirtualServer.org

Re: [PATCH] Re: Status of the ipvsadm 'exact numbers' option

To: lvs-users@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [PATCH] Re: Status of the ipvsadm 'exact numbers' option
From: Horms <horms@xxxxxxxxxxxx>
Date: Wed, 30 Nov 2005 02:04:13 +0000 (UTC)
Roberto Nibali <ratz@xxxxxxxxxxxx> wrote:
>> Anyway, Guy, Sébastien, could you guys please give this patch a whirl
>> since I do not have access to a IPVS enabled kernel?
> 
> DAMN thunderbird (sometimes it behaves like a chick having the runs).
> The patch can be downloaded at:
> 
> http://www.drugphish.ch/patches/ratz/LVS/ipvsadm-1.24-exact-1.diff

Sorry that this is a bit noisy, I've included the whole patch for
the record. Annotations inline.

Please keep in mind that Wensong still handles ipvsadm releases,
so my comments are only my opinions.

> diff -ur ipvsadm-1.24/ipvsadm.c ipvsadm-1.24-ratz/ipvsadm.c
> --- ipvsadm-1.24/ipvsadm.c      2004-01-10 10:39:03.000000000 +0100
> +++ ipvsadm-1.24-ratz/ipvsadm.c 2005-11-25 19:20:46.215532497 +0100
> @@ -161,28 +161,29 @@
>         "zero",
>  };
>  
> -#define OPT_NONE               0x00000
> -#define OPT_NUMERIC            0x00001
> -#define OPT_CONNECTION         0x00002
> -#define OPT_SERVICE            0x00004
> -#define OPT_SCHEDULER          0x00008
> -#define OPT_PERSISTENT         0x00010
> -#define OPT_NETMASK            0x00020
> -#define OPT_SERVER             0x00040
> -#define OPT_FORWARD            0x00080
> -#define OPT_WEIGHT             0x00100
> -#define OPT_UTHRESHOLD         0x00200
> -#define OPT_LTHRESHOLD         0x00400
> -#define OPT_MCAST              0x00800
> -#define OPT_TIMEOUT            0x01000
> -#define OPT_DAEMON             0x02000
> -#define OPT_STATS              0x04000
> -#define OPT_RATE               0x08000
> -#define OPT_THRESHOLDS         0x10000
> -#define OPT_PERSISTENTCONN     0x20000
> -#define OPT_SORT               0x40000
> -#define OPT_SYNCID             0x80000
> -#define NUMBER_OF_OPT          20
> +#define OPT_NONE               0x000000
> +#define OPT_NUMERIC            0x000001
> +#define OPT_CONNECTION         0x000002
> +#define OPT_SERVICE            0x000004
> +#define OPT_SCHEDULER          0x000008
> +#define OPT_PERSISTENT         0x000010
> +#define OPT_NETMASK            0x000020
> +#define OPT_SERVER             0x000040
> +#define OPT_FORWARD            0x000080
> +#define OPT_WEIGHT             0x000100
> +#define OPT_UTHRESHOLD         0x000200
> +#define OPT_LTHRESHOLD         0x000400
> +#define OPT_MCAST              0x000800
> +#define OPT_TIMEOUT            0x001000
> +#define OPT_DAEMON             0x002000
> +#define OPT_STATS              0x004000
> +#define OPT_RATE               0x008000
> +#define OPT_THRESHOLDS         0x010000
> +#define OPT_PERSISTENTCONN     0x020000
> +#define OPT_SORT               0x040000
> +#define OPT_SYNCID             0x080000
> +#define OPT_EXACT              0x100000
> +#define NUMBER_OF_OPT          21

Padding each value out an extra 2 bytes is a bit noisy,
but as the result is cleaner than it otherwise would be,
and its a one off hit for the next 8 options, I guess its ok.

>  static const char* optnames[] = {
>         "numeric",
> @@ -205,6 +206,7 @@
>         "persistent-conn",
>         "sort",
>         "syncid",
> +       "exact",
>  };
>  
>  /*
> @@ -217,21 +219,21 @@
>   */
>  static const char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] =
>  {
> -       /*   -n   -c   svc  -s   -p   -M   -r   fwd  -w   -x   -y   -mc  tot  
> d
> mn  -st  -rt  thr  -pc  srt  sid */
> -/*ADD*/     {'x', 'x', '+', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', ' '},
> -/*EDIT*/    {'x', 'x', '+', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> -/*DEL*/     {'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> -/*FLUSH*/   {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> -/*LIST*/    {' ', '1', '1', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> '1', 
> '1', ' ', ' ', ' ', ' ', ' ', 'x'},
> -/*ADDSRV*/  {'x', 'x', '+', 'x', 'x', 'x', '+', ' ', ' ', ' ', ' ', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> -/*DELSRV*/  {'x', 'x', '+', 'x', 'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> -/*EDITSRV*/ {'x', 'x', '+', 'x', 'x', 'x', '+', ' ', ' ', ' ', ' ', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> -/*TIMEOUT*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> -/*STARTD*/  {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', ' '},
> -/*STOPD*/   {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', ' '},
> -/*RESTORE*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> -/*SAVE*/    {' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> -/*ZERO*/    {'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +       /*   -n   -c   svc  -s   -p   -M   -r   fwd  -w   -x   -y   -mc  tot  
> d
> mn  -st  -rt  thr  -pc  srt  sid  -ex */
> +/*ADD*/     {'x', 'x', '+', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*EDIT*/    {'x', 'x', '+', ' ', ' ', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*DEL*/     {'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*FLUSH*/   {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*LIST*/    {' ', '1', '1', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> '1', 
> '1', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
> +/*ADDSRV*/  {'x', 'x', '+', 'x', 'x', 'x', '+', ' ', ' ', ' ', ' ', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*DELSRV*/  {'x', 'x', '+', 'x', 'x', 'x', '+', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*EDITSRV*/ {'x', 'x', '+', 'x', 'x', 'x', '+', ' ', ' ', ' ', ' ', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*TIMEOUT*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*STARTD*/  {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', ' ', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*STOPD*/   {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*RESTORE*/ {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*SAVE*/    {' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
> +/*ZERO*/    {'x', 'x', ' ', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 
> 'x', 
> 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
>  };

That noise is unavoidable without restructuring :(

>  /* printing format flags */
> @@ -243,6 +245,7 @@
>  #define FMT_THRESHOLDS         0x0010
>  #define FMT_PERSISTENTCONN     0x0020
>  #define FMT_SORT               0x0040
> +#define FMT_EXACT              0x0080
>  
>  #define SERVICE_NONE           0x0000
>  #define SERVICE_ADDR           0x0001
> @@ -388,6 +391,7 @@
>                 {"thresholds", '\0', POPT_ARG_NONE, NULL, '9'},
>                 {"persistent-conn", '\0', POPT_ARG_NONE, NULL, 'P'},
>                 {"sort", '\0', POPT_ARG_NONE, NULL, '0'},
> +               {"exact", 'X', POPT_ARG_NONE, NULL, 'X'},
>                 {NULL, 0, 0, NULL, 0}
>         };
>  
> @@ -590,6 +594,10 @@
>                         set_option(options, OPT_SORT);
>                         *format |= FMT_SORT;
>                         break;
> +               case 'X':
> +                       set_option(options, OPT_EXACT);
> +                       *format |= FMT_EXACT;
> +                       break;
>                 default:
>                         fail(2, "invalid option `%s'",
>                              poptBadOption(context, POPT_BADOPTION_NOALIAS));
> @@ -636,7 +644,7 @@
>               unsigned int *options, unsigned int *format)
>  {
>         int c, parse;
> -       const char *optstring = "AEDCZSRaedlLhvt:u:f:s:M:p::r:gmiw:x:y:cn";
> +       const char *optstring = "AEDCZSRaedlLhvt:u:f:s:M:p::r:gmiw:x:y:cnX";
>         const struct option long_options[] = {
>                 {"add-service", 0, 0, 'A'},
>                 {"edit-service", 0, 0, 'E'},
> @@ -678,6 +686,7 @@
>                 {"thresholds", 0, 0, '9'},
>                 {"persistent-conn", 0, 0, 'P'},
>                 {"sort", 0, 0, '0'},
> +               {"exact", 0, 0, 'X'},
>                 {"help", 0, 0, 'h'},
>                 {0, 0, 0, 0}
>         };
> @@ -902,6 +911,10 @@
>                         set_option(options, OPT_SORT);
>                         *format |= FMT_SORT;
>                         break;
> +               case 'X':
> +                       set_option(options, OPT_EXACT);
> +                       *format |= FMT_EXACT;
> +                       break;
>                 default:
>                         fail(2, "invalid option `%s'", argv[optind-1]);
>                 }
> @@ -1325,6 +1338,8 @@
>                 "  --daemon                            output of daemon 
> informa
> tion\n"
>                 "  --stats                             output of statistics 
> inf
> ormation\n"
>                 "  --rate                              output of rate 
> informati
> on\n"
> +               "  --exact                             print raw numbers 
> rather
>  than human-readable numbers\n"
> +               "                                      used in conjunction 
> with
>  --stats and --rate options only\n"
>                 "  --thresholds                        output of thresholds 
> inf
> ormation\n"
>                 "  --persistent-conn                   output of persistent 
> con
> nection info\n"
>                 "  --sort                              sorting output of 
> servic
> e/server entries\n"
> @@ -1401,10 +1416,10 @@
>                          MINIMUM_IPVS_VERSION_MINOR,
>                          MINIMUM_IPVS_VERSION_PATCH)) {
>                 fprintf(stderr,
> -                       "Warning: IPVS version missmatch: \n"
> +                       "Warning: IPVS version mismatch: \n"
>                         "  Kernel compiled with IPVS version %d.%d.%d\n"
>                         "  ipvsadm " IPVSADM_VERSION_NO
> -                       " requires minimum IPVS version %d.%d.%d\n\n",
> +                       "  requires minimum IPVS version %d.%d.%d\n\n",
>                         NVERSION(ipvs_info.version),
>                         MINIMUM_IPVS_VERSION_MAJOR,
>                         MINIMUM_IPVS_VERSION_MINOR,
> @@ -1554,6 +1569,16 @@
>  }

The fragment above seems to be undelated to the exact pattern match,
can you remove it?

> +static void print_exactnum(unsigned long long i)
> +{
> +       char mytmp[32];
> +       size_t len;
> +
> +       len = snprintf(mytmp, 32, "%llu", i);
> +       printf("%*llu", len <= 8 ? 9 : len + 1, i);
> +}
> +
> +
>  static void print_title(unsigned int format)
>  {
>         if (format & FMT_STATS)
> @@ -1631,18 +1656,34 @@
>                 }
>         } else if (format & FMT_STATS) {
>                 printf("%-33s", svc_name);
> -               print_largenum(se->stats.conns);
> -               print_largenum(se->stats.inpkts);
> -               print_largenum(se->stats.outpkts);
> -               print_largenum(se->stats.inbytes);
> -               print_largenum(se->stats.outbytes);
> +               if (format & FMT_EXACT) {
> +                       print_exactnum(se->stats.conns);
> +                       print_exactnum(se->stats.inpkts);
> +                       print_exactnum(se->stats.outpkts);
> +                       print_exactnum(se->stats.inbytes);
> +                       print_exactnum(se->stats.outbytes);
> +               } else {
> +                       print_largenum(se->stats.conns);
> +                       print_largenum(se->stats.inpkts);
> +                       print_largenum(se->stats.outpkts);
> +                       print_largenum(se->stats.inbytes);
> +                       print_largenum(se->stats.outbytes);
> +               }
>         } else if (format & FMT_RATE) {
>                 printf("%-33s", svc_name);
> -               print_largenum(se->stats.cps);
> -               print_largenum(se->stats.inpps);
> -               print_largenum(se->stats.outpps);
> -               print_largenum(se->stats.inbps);
> -               print_largenum(se->stats.outbps);
> +               if (format & FMT_EXACT) {
> +                       print_exactnum(se->stats.cps);
> +                       print_exactnum(se->stats.inpps);
> +                       print_exactnum(se->stats.outpps);
> +                       print_exactnum(se->stats.inbps);
> +                       print_exactnum(se->stats.outbps);
> +               } else {
> +                       print_largenum(se->stats.cps);
> +                       print_largenum(se->stats.inpps);
> +                       print_largenum(se->stats.outpps);
> +                       print_largenum(se->stats.inbps);
> +                       print_largenum(se->stats.outbps);
> +               }
>         } else {
>                 printf("%s %s", svc_name, se->sched_name);
>                 if (se->flags & IP_VS_SVC_F_PERSISTENT) {
> @@ -1677,19 +1718,32 @@
>                                fwd_switch(e->conn_flags), e->weight);
>                 } else if (format & FMT_STATS) {
>                         printf("  -> %-28s", dname);
> -                       print_largenum(e->stats.conns);
> -                       print_largenum(e->stats.inpkts);
> -                       print_largenum(e->stats.outpkts);
> -                       print_largenum(e->stats.inbytes);
> -                       print_largenum(e->stats.outbytes);
> +                       if (format & FMT_EXACT) {
> +                               print_exactnum(e->stats.conns);
> +                               print_exactnum(e->stats.inpkts);
> +                               print_exactnum(e->stats.outpkts);
> +                               print_exactnum(e->stats.inbytes);
> +                               print_exactnum(e->stats.outbytes);
> +                       } else {
> +                               print_largenum(e->stats.conns);
> +                               print_largenum(e->stats.inpkts);
> +                               print_largenum(e->stats.outpkts);
> +                               print_largenum(e->stats.inbytes);
> +                               print_largenum(e->stats.outbytes);
> +                       }
>                         printf("\n");
>                 } else if (format & FMT_RATE) {
>                         printf("  -> %-28s %8u %8u %8u", dname,
>                                e->stats.cps,
>                                e->stats.inpps,
>                                e->stats.outpps);
> -                       print_largenum(e->stats.inbps);
> -                       print_largenum(e->stats.outbps);
> +                       if (format & FMT_EXACT) {
> +                               print_exactnum(e->stats.inbps);
> +                               print_exactnum(e->stats.outbps);
> +                       } else {
> +                               print_largenum(e->stats.inbps);
> +                               print_largenum(e->stats.outbps);
> +                       }
>                         printf("\n");
>                 } else if (format & FMT_THRESHOLDS) {
>                         printf("  -> %-28s %-10u %-10u %-10u %-10u\n", dname,

Seems fine :)

-- 
Horms


<Prev in Thread] Current Thread [Next in Thread>