[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Linux-cluster] Re: Simple dlm demo program, and a bug...



On Wednesday 13 October 2004 11:50, Patrick Caulfield wrote:
> On Wed, Oct 13, 2004 at 11:40:07AM -0400, Daniel Phillips wrote:
> > On Wednesday 13 October 2004 11:10, you wrote:
> > > >  struct dlm_lksb *lksb;
> > >
> > > This should point to something.
> >
> > Thanks Patrick, just a little too bleary-eyed to see that right
> > away... OK, here is the little libdlm demo that grabs and releases
> > a lock, without the benefit of the dumbed-down pthreads interface,
> > including forking off a thread to run the dispatch function.  This
> > should make things a little easier for the next innocent victim to
> > head into this part of the woods.
>
> I think I'll put it in the doc directory I think, it might stand more
> chance of being found. But then given how out-of-date the doc file
> was...maybe not!

Except my error macro was considerably less than exemplary (i.e.,
doesn't work).  Fixed below, and a title added.

> > I'd like to encourage you to divide up libdlm as you suggested,
> > there's no way of getting rid of libpthread otherwise, not to
> > mention that real men only write reentrant code ;-)
>
> Yes. I'll add it to my TODO list, it shouldn't really take too long.

#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <libdlm.h>

/*
 * Simple libdlm locking demo
 *
 * Daniel Phillips, phillips redhat com
 *
 * (c) 2004, Redhat Software Inc.
 */

#define error(string, args...) do { printf(string, ##args); exit(1); } while (0)

void my_ast(void *arg)
{
 printf("ast got arg %p\n", arg);
}

int main(void)
{
 int fd, child;
 struct dlm_lksb lksb;

 if ((fd = dlm_get_fd()) < 0)
  error("dlm error %i, %s\n", errno, strerror(errno));

 switch (child = fork()) {
 case -1:
  error("fork error %i, %s\n", errno, strerror(errno));
 case 0:
      while (1)
   dlm_dispatch(fd);
 }

 if (dlm_lock(LKM_PWMODE, &lksb, LKF_NOQUEUE, "foo", 3,
  0, my_ast, (void *)&fd, NULL, NULL) < 0)
  error("dlm error %i, %s\n", errno, strerror(errno));
 sleep(1);

 if (dlm_unlock(lksb.sb_lkid, 0, &lksb, NULL) < 0)
  error("dlm error %i, %s\n", errno, strerror(errno));
 sleep(1);

 kill(child, SIGTERM);
 return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]