bug-mailutils
[Top][All Lists]
Advanced

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

Re: [bug-mailutils] Mailbox locking (especially over NFS) questions


From: Sergey Poznyakoff
Subject: Re: [bug-mailutils] Mailbox locking (especially over NFS) questions
Date: Tue, 05 Jul 2005 12:51:21 +0300

Kostas Zorbadelos <address@hidden> wrote:

> I have a series of questions about the handling of locking of
> mailboxes in mailutils.
[...]
> What does the locker_t represent?

It represents a universal object used for locking mailboxes, hiding any
implementation-dependent details.

> I want to lock a mailbox on an NFS mounted filesystem. Does your
> framework use flock(2) or fcntl(2)?

It can use a variety of mechanisms:

* Dotlock-compatible locking (default)
* Kernel locking via fcntl
* Locking via an external program

The actual mechanism to be used by any instance of locker is specified
by locker_set_default_flags(). The actual mechanism to be used by a
particular instance of locker can be specified by 3rd argument to
locker_create. 

>From the user's point of view, it is selected using --locker-.* options
("mailbox" argp capability).

> Can I have an example of code that properly locks an NFS mailbox?

>From the developer's point of view, the way of locking does not depend
on particular storage system (see, however, the comment below):

char *mboxname;
int status;
mailbox_t mbox;
locker_t lock;

mailbox_get_locker (mbox, &lock);

#if 0   
/* This is optional. The best way for an application will be to
   register "mailbox" argp capability and to let the user select the
   preferred locker settings, providing the defaults by calling
   locker_set_default_.*() functions before calling mu_argp_parse().

   If you still prefer the direct method, notice that dotlock is
   considered the safest method for NFS. It is selected if none
   of the following bits is set in lock_flags:
     MU_LOCKER_EXTERNAL,MU_LOCKER_NULL,MU_LOCKER_KERNEL
*/    
locker_set_flags (lock, lock_flags);
locker_set_retries (lock, retries);
 ..etc..
#endif 

status = locker_lock (lock);
if (status)
  {
    mu_error("Cannot lock mailbox `%s': %s",
             mboxname, mu_strerror (status));
    exit (1);
  }   

/* ... Actually access the mailbox ... */

locker_unlock (lock);        

Regards,
Sergey




reply via email to

[Prev in Thread] Current Thread [Next in Thread]