On 10/28/06, Menno Lageman <[EMAIL PROTECTED]> wrote:
How about something like the DHCP eventhook mechanism (see
dhcpagent(1M))? This would allow people to get notifications of zone
state changes in a well defined *and* simple way without the need
scraping logs for unstable messages.

zoneadmd just needs to invoke the Zone eventhook with the appropriate
event and some auxilary data for the event (such as zone name etc). The
sysadmin-supplied eventhook script would then do whatever is deemed
appropriate for the site (page someone, send mail, forward to management
console etc.).

Assuming that the code that Dan wrote calls the eventhook rather than
sending syslog messages, I like this approach more.  Compared to
sending syslog messages, it has the advantages that Menno mentions.
Additionally, it would provide a mechanism for customers that need to
perform other things when a zone state changes.  For instance, when a
zone boots there may be a need to do something special to the network
(alter routes, mtu, etc.).  This would be a much simpler hook for that
than hacking the zone SMF method script.

Compared to another program that uses zonecfg_notify_bind() it has the
advantage that zoneadmd knows about requests for administrative
commands (halt, reboot, ...) and can offer some indication as to
whether the end result was the desired result.  That is, if a zone was
running, a reboot was performed and it ended up at installed, zoneadmd
can determine if everything went well or not.  A program listening for
zone state change events will see the same transitions but will not
know that the zone should have ended up in the running state.

FWIW, I wrote a short program to watch for zone state change events.
Wow, that was easy.

==== Begin notify.c ====
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>


/* From libzonecfg.c */
void * zonecfg_notify_bind(int(*func)(const char *zonename, zoneid_t zid,
  const char *newstate, const char *oldstate, hrtime_t when, void *p),
  void *p);
void zonecfg_notify_unbind(void *handle);

static int
notify(const char *zonename, zoneid_t zid, const char *newstate,
       const char *oldstate, hrtime_t when, void *p)
{
       printf("%s %d %s %s\n", zonename, (int) zid, newstate, oldstate);
}

int main(int argc, char *argv[]) {
       void *evtchan;

       if ( (evtchan = zonecfg_notify_bind(notify, NULL)) == NULL ) {
               fprintf(stderr, "Could not bind to notification channel\n");
               exit(1);
       }

       sleep(600);
       zonecfg_notify_unbind(evtchan);

}
==== End notify.c ====

==== Begin Makefile ====
CC      = /opt/SUNWspro/bin/cc
LDFLAGS = -lzonecfg

notify: notify.o
       $(CC) -o $@ notify.o $(LDFLAGS)

clean:
       rm -f *.o notify
==== End Makefile ====

To get it to link, I needed to create a symbolic link at
/usr/lib/libzonecfg.so -> libzonecfg.so.1.  Time to go searching for
linker options that I haven't needed before...  I haven't looked into
it, but for some reason I seem to get some useless events.  Consider
the following reboot:

# ./notify
foo 6 shutting_down running
foo 6 shutting_down shutting_down
foo 6 shutting_down shutting_down
foo 6 shutting_down shutting_down
foo 6 uninitialized shutting_down
foo 7 ready uninitialized
foo 7 ready ready
foo 7 running ready

I'm not sure why the newstate and oldstate would be the same.

In order for an approach using a program like the one above to be
useful there would need to be some way to indicate what the desired
state for the zone is in addition to the the state that it has just
transitioned to.

Mike

--
Mike Gerdts
http://mgerdts.blogspot.com/
_______________________________________________
zones-discuss mailing list
zones-discuss@opensolaris.org

Reply via email to