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

Building of extended nbd fails on ppc

I tried to build the extended network block device system which can be
found at <http://www.it.uc3m.es/~ptb/nbd/>.

The build process stops at the following line:
(By the way, I'm using kernel-2.4.20-ben10 on an iBook v2.2)

gcc  -o enbd-server enbd-server.o socket.o logging.o alarm.o file.o\
select.o fileserver.o db.o stream.o ioctl.o ipaddrfile.o pidfile.o\
interface.o lockfile.o md5.o lock.o shmem.o hash.o 

lock.o(.text+0x18): In function `lock_try':
: undefined reference to `atomic_dec_and_test'
lock.o(.text+0x18): In function `lock_try':
: relocation truncated to fit: R_PPC_REL24 atomic_dec_and_test
lock.o(.text+0x30): In function `lock_try':
: undefined reference to `atomic_inc'

OK, 'atomic_dec_and_test' can be found in $/include/asm/atomic.h

cat atomic.h:

 * BK Id: SCCS/s.atomic.h 1.16 11/04/01 22:58:20 paulus
 * PowerPC atomic operations

    #ifndef _ASM_PPC_ATOMIC_H_ 
    #define _ASM_PPC_ATOMIC_H_

    typedef struct { volatile int counter; } atomic_t;

    #ifdef __KERNEL__

    #define ATOMIC_INIT(i)  { (i) }

#define atomic_dec_and_test(v)          (atomic_dec_return((v)) == 0)

#endif /* __KERNEL__ */
#endif /* _ASM_PPC_ATOMIC_H_ */

OK, now we look on another architecture:

cat /usr/include/asm/atomic.h [ARCH=i386]:

#ifndef __ARCH_I386_ATOMIC__
#define __ARCH_I386_ATOMIC__

#include <linux/config.h>

 * Atomic operations that C can't guarantee us.  Useful for
 * resource counting etc..

   #ifdef CONFIG_SMP
   #define LOCK "lock ; "
   #define LOCK ""

 * Make sure gcc doesn't try to be clever and move things around
 * on us. We need to use _exactly_ the address the user gave us,
 * not some alias that contains the same information.
typedef struct { volatile int counter; } atomic_t;

 * atomic_dec_and_test - decrement and test
 * @v: pointer of type atomic_t
 * Atomically decrements @v by 1 and
 * returns true if the result is 0, or false for all other
 * cases.  Note that the guaranteed
 * useful range of an atomic_t is only 24 bits.
 static __inline__ int atomic_dec_and_test(atomic_t *v)
	        unsigned char c;

Ah, the missing functions (There are possibly more.) are not available to
userspace tools on ARCH=ppc, but they are available on ARCH=i386.

What is the correct way to solve the problem?
Should something be changed in the linux kernel?
Or is it false to assume, that 'atomic.h' should deliver the needed
functionality on all platforms?


Reply to: