On (09/10/08 19:08), Andy Whitcroft didst pronounce:
> On Mon, Oct 06, 2008 at 03:37:29PM +0100, Mel Gorman wrote:
> > On (03/10/08 18:37), Andy Whitcroft didst pronounce:
> > > Add a very basic framework for hpoolcfg, the administrator pool 
> > > configuration
> > > helper.
> > > 
> > > Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]>
> > > ---
> > >  Makefile   |    8 ++++-
> > >  hpoolcfg.c |   96 
> > > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  2 files changed, 103 insertions(+), 1 deletions(-)
> > >  create mode 100644 hpoolcfg.c
> > > 
> > > diff --git a/Makefile b/Makefile
> > > index f8cd696..43dff05 100644
> > > --- a/Makefile
> > > +++ b/Makefile
> > > @@ -4,7 +4,7 @@ EXEDIR = /bin
> > >  LIBOBJS = hugeutils.o version.o init.o morecore.o debug.o alloc.o shm.o 
> > > kernel-features.o
> > >  INSTALL_OBJ_LIBS = libhugetlbfs.so libhugetlbfs.a
> > >  BIN_OBJ_DIR=obj
> > > -INSTALL_BIN = hugectl hugeedit
> > > +INSTALL_BIN = hugectl hugeedit hpoolcfg
> > >  INSTALL_HEADERS = hugetlbfs.h
> > >  LDSCRIPT_TYPES = B BDT
> > >  LDSCRIPT_DIST_ELF = elf32ppclinux elf64ppc elf_i386 elf_x86_64
> > > @@ -256,6 +256,12 @@ $(BIN_OBJ_DIR)/hugeedit: $(BIN_OBJ_DIR)/hugeedit.o
> > >   mkdir -p $(BIN_OBJ_DIR)
> > >   $(CC) $(CPPFLAGS) $(CFLAGS) $(LIBPATHS) -o $@ $^
> > >  
> > > +HPOOLCFG_OBJ=hpoolcfg.o hugeutils.o debug.o
> > > +$(BIN_OBJ_DIR)/hpoolcfg: $(foreach 
> > > file,$(HPOOLCFG_OBJ),$(BIN_OBJ_DIR)/$(file))
> > > + @$(VECHO) LDHOST $@
> > > + mkdir -p $(BIN_OBJ_DIR)
> > > + $(CC) $(CPPFLAGS) $(CFLAGS) $(LIBPATHS) -o $@ $^
> > > +
> > >  clean:
> > >   @$(VECHO) CLEAN
> > >   rm -f *~ *.o *.so *.a *.d *.i core a.out $(VERSION)
> > > diff --git a/hpoolcfg.c b/hpoolcfg.c
> > > new file mode 100644
> > > index 0000000..887b8ed
> > > --- /dev/null
> > > +++ b/hpoolcfg.c
> > > @@ -0,0 +1,96 @@
> > > +/***************************************************************************
> > > + *   User front end for using huge pages Copyright (C) 2008, IBM         
> > >   *
> > > + *                                                                       
> > >   *
> > > + *   This program is free software; you can redistribute it and/or 
> > > modify  *
> > > + *   it under the terms of the Lesser GNU General Public License as      
> > >   *
> > > + *   published by the Free Software Foundation; either version 2.1 of 
> > > the  *
> > > + *   License, or at your option) any later version.                      
> > >   *
> > > + *                                                                       
> > >   *
> > > + *   This program is distributed in the hope that it will be useful,     
> > >   *
> > > + *   but WITHOUT ANY WARRANTY; without even the implied warranty of      
> > >   *
> > > + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       
> > >   *
> > > + *   GNU Lesser General Public License for more details.                 
> > >   *
> > > + *                                                                       
> > >   *
> > > + *   You should have received a copy of the Lesser GNU General Public    
> > >   *
> > > + *   License along with this program; if not, write to the               
> > >   *
> > > + *   Free Software Foundation, Inc.,                                     
> > >   *
> > > + *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           
> > >   *
> > > + 
> > > ***************************************************************************/
> > > +
> > 
> > Might as well match the style used in other C files. hmm, it's already
> > different in hugectl. Sod it, never mind.
> > 
> > > +/*
> > > + * hpoolcfg is designed to make an administrators life simpler, to 
> > > automated
> > 
> > s/automated/automate/ ?
> 
> Yep.
> 
> > > + * and simplify basic system configuration as it relates to hugepages.  
> > > It
> > > + * is designed to help with pool and mount configuration.
> > > + */
> > > +
> > > +#include <stdlib.h>
> > > +#include <stdio.h>
> > > +#include <errno.h>
> > > +#include <string.h>
> > > +#include <limits.h>
> > > +
> > > +#define _GNU_SOURCE /* for getopt_long */
> > > +#include <unistd.h>
> > > +#include <getopt.h>
> > > +
> > > +#define REPORT_UTIL "hpoolcfg"
> > > +#include "libhugetlbfs_internal.h"
> > > +
> > > +extern int errno;
> > 
> > Does including errno.h already provide this?
> 
> Should do yes.  Yes it does.
> 
> > > +extern int optind;
> > > +extern char *optarg;
> > > +
> > > +#define OPTION(opts, text)       fprintf(stderr, " %-25s  %s\n", opts, 
> > > text)
> > > +#define CONT(text)               fprintf(stderr, " %-25s  %s\n", "", 
> > > text)
> > > +
> > > +void print_usage()
> > > +{
> > > + fprintf(stderr, "hugectl [options] target\n");
> > > + fprintf(stderr, "options:\n");
> > > +
> > > + OPTION("--help, -h", "Prints this message");
> > > +}
> > > +
> > > +int opt_dry_run = 0;
> > > +
> > > +int main(int argc, char** argv)
> > > +{
> > > + char opts[] = "+h";
> > > + int ret = 0, index = 0;
> > > + struct option long_opts[] = {
> > > +         {"help",       no_argument, NULL, 'h'},
> > > +
> > > +         {0},
> > > + };
> > > +
> > > + __lh_hugetlbfs_setup_debug();
> > > +
> > > + while (ret != -1) {
> > > +         ret = getopt_long(argc, argv, opts, long_opts, &index);
> > > +         switch (ret) {
> > > +         case -1:
> > > +                 break;
> > > +
> > > +         case '?':
> > > +                 print_usage();
> > > +                 exit(EXIT_FAILURE);
> > > +
> > 
> > Why is -? considered a failure and -h a success?
> 
> That is correct to my mind, -h asks for a list of options and it
> producing them is what its meant to do so its successful, '?' implies
> you passed something bad and it printing the usage is to tell you off
> so it is a failure.
> 

Ok, that's fair enough and sounds reasonable.

> > > +         case 'h':
> > > +                 print_usage();
> > > +                 exit(EXIT_SUCCESS);
> > > +
> > > +         default:
> > > +                 WARNING("unparsed option %08x\n", ret);
> > > +                 ret = -1;
> > > +                 break;
> > > +         }
> > > + }
> > > + index = optind;
> > > +
> > > + if ((argc - index) != 0) {
> > > +         print_usage();
> > > +         exit(EXIT_FAILURE);
> > > + }
> > > +
> > > + exit(EXIT_SUCCESS);
> > > +}
> 
> -apw
> 

-- 
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to