PDA

View Full Version : FILE_LOCK in file.h


oobayly
September 9th, 2010, 10:57
Whilst attempting to get Thomas Wintergerst's c4b drivers to compile in 8.1-RELEASE (I've succeeded in getting it to work in 7.2-RELEASE) I've come across some problems. Whilst I've managed to get through the 1st batch, I'm having some issues with the following error:


...capidev.c:897: warning: implicit declaration of function 'FILE_LOCK'


A cursory look at the /usr/src/sys/sys/ directory told me that there's no define, however looking on the working system (7.2-RELEASE) and the define is present in file.h:

/* Lock a file. */
#define FILE_LOCK(f) mtx_lock((f)->f_mtxp)
#define FILE_UNLOCK(f) mtx_unlock((f)->f_mtxp)
#define FILE_LOCKED(f) mtx_owned((f)->f_mtxp)
#define FILE_LOCK_ASSERT(f, type) mtx_assert((f)->f_mtxp, (type))

Obviously it's not present in 8.1-RELEASE.

I've been searching on how to get around this, but my Google fu appears to be weak as I can't even find a description of the changes made to file.h. I also checked /usr/src/UPDATING, but again didn't find anything obvious.

Should this be a simple replace job, or will it be far more complicated?

Many thanks,
John

SirDice
September 9th, 2010, 11:25
FILE_LOCK is just a macro for mtx_lock. See mutex.

oobayly
September 9th, 2010, 12:52
Well, I thought that was the case, so I changed the call from FILE_LOCK to mtx_lock:


static int capidev_read
(struct file *fp,
struct uio *pUio,
struct ucred *pCred,
int iFlags,
d_thread_t *pThread)
{

<snip>

-- FILE_LOCK (fp);
++ mtx_lock(fp->f_mtxp) // Removed additional parentheses as they're only
// needed in the macro


As you can see, fp is a file struct (as defined in file.h), but when compiling I get the error:

'struct file' has no member named 'f_mtxp'


But in file.h:

struct file {
LIST_ENTRY(file) f_list;/* (fl) list of active files */
short f_type; /* descriptor type */
void *f_data; /* file descriptor specific data */
u_int f_flag; /* see fcntl.h */
struct mtx *f_mtxp; /* mutex to protect data */

<snip>


I'm currently going back through the includes to make sure that the code isn't using a file struct that is different from that defined in file.h

oobayly
September 9th, 2010, 14:19
Bah, double checked file.h. Turns out I was read the 7.2-RELEASE version. struct file does indeed have no member called f_mtxp

expl
September 9th, 2010, 18:21
I believe that mutex pool is used to lock the descriptor structure.

mtx_pool

oobayly
September 9th, 2010, 22:42
I believe that mutex pool is used to lock the descriptor structure.

mtx_pool

Yup, unfortunately it's not something I'm familiar with. It's turning into quite an exercise as there are some fairly large changes in the source. Whilst I can struggle away to get the driver to compile I don't have much confidence that they'll work as planned, let alone in a stable fashion.

What is interesting is that I decided to have a look through the source tree for uses of FILE_LOCK & FILE_UNLOCK and have seen in many cases the calls have simply been removed. To maintain the locking I'd [probably] have to implement a mutex pool in the driver, again something I lack experience in.