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

Re: database locking woes part 2



On Mon, Jul 29, 2002 at 04:41:43PM -0400, Ian Peters wrote:
> I've come up with another testcase to better demonstrate what I feel to
> be the actual problem with database locking, at least in RPM 4.0.4. 

THanks for looking at these locking issues BTW.

Sanity check:

rpm-4.0.4 has an fcntl lock, exclusive if O_RDWR, or shared if O_RDONLY,
on Packages. This is the scheme that has always been used for rpm.
What is also in rpm-4.0.4 is the ability to enable CDB, and some access(2)
code that tries to figger DB_FOO flags in order to use a DBENV.

> I'll try these programs with RPM 4.1 as soon as I can -- but this
> problem is affecting me now, with deployed versions of RPM,
> unfortunately.

OK, as I still need to commit to a locking scheme for 4.1.

> 
> The programs are called lock-maker and lock-breaker.  lock-maker opens
> the rpm database O_RDWR, which should hold an exclusive lock, and then
> sleeps for a good long time to hold that lock open.  lock-breaker
> attempts to open the rpm database O_RDONLY.  If it fails, it immediately
> tries to open the database again (also O_RDONLY).
> 
> To run the test, compile both programs:
> 
> gcc -o lock-maker lock-maker.c -I/usr/include/rpm -lrpm -lrpmio -lrpmdb -lpopt
> 
> gcc -o lock-breaker lock-breaker.c -I/usr/include/rpm -lrpm -lrpmio -lrpmdb -lpopt
> 
> Now, in one terminal, as root, run lock-maker.
> 
> # ./lock-maker
> Opened rpm database O_RDWR
> 
> Now, to verify that the lock is held, run rpm -qa -- both as root and as
> non-root, just for verification.  (The multiple runs will explain
> themselves in a second.)
> 
> $ rpm -qa
> error: cannot get shared lock on /var/lib/rpm/Packages
> error: cannot open Packages index using db3 - Operation not permitted (1)
> $ rpm -qa
> error: cannot get shared lock on /var/lib/rpm/Packages
> error: cannot open Packages index using db3 - Operation not permitted (1)
> $ su
> Password: 
> # rpm -qa
> error: cannot get shared lock on /var/lib/rpm/Packages
> error: cannot open Packages index using db3 - Operation not permitted (1)
> # rpm -qa
> error: cannot get shared lock on /var/lib/rpm/Packages
> error: cannot open Packages index using db3 - Operation not permitted (1)
> 
> Now, run lock-breaker:
> 
> $ ./lock-breaker
> error: cannot get shared lock on /var/lib/rpm/Packages
> error: cannot open Packages index using db3 - Operation not permitted (1)
> Failed to open rpm database O_RDONLY
> error: cannot get shared lock on /var/lib/rpm/Packages
> Failed to open rpm database O_RDONLY
> $ su
> Password: 
> # ./lock-breaker
> error: cannot get shared lock on /var/lib/rpm/Packages
> error: cannot open Packages index using db3 - Operation not permitted (1)
> Failed to open rpm database O_RDONLY
> Opened rpm database O_RDONLY
> 
> That second open really should not have succeeded.
> 
> Am I totally off-base, or missing something obvious here?

Without (yet) looking at the lock-breaker code, I'd guess that an rpmdbOpen()
return code is screwed.

Running with strace should show the fcntl errno. If success, then fcntl has
weird semantics, if fail, then I've screwed up an rpmdbOpen() return code.

73 de Jeff

-- 
Jeff Johnson	ARS N3NPQ
jbj@redhat.com (jbj@jbj.org)
Chapel Hill, NC





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