2005/11/8, Fawad Lateef <fawadlateef@xxxxxxxxx>: > On 11/9/05, Aritz Bastida <aritzbastida@xxxxxxxxx> wrote: > > > > Well, I hope my questions are clear, and someone can help me. I know, > > I could just use test_bit() and forget about this. But, however, the > > networking code uses flags the other way, for example in > > dev_change_flags() [net/core/dev.c]. > > > > It acquires the rtnl semaphore (in function dev_ioctl) before changing > > anything in dev->flags, so there is no more than one writer at a > > certain time. But in dev_get_flags() [net/core/dev.c] it reads the > > flags, without acquiring any lock for that purpose. > > > > What I found in net/core/dev.c is dev_get_flags or dev_change_flags > are both called from dev_ifsioc which is called from dev_ioctl 2 times > with lock held, one time with read_lock on dev_base_lock and second > time with rtnl lock held ! > > > -- > Fawad Lateef > rtnl lock is a semaphore for synchronizing writers, so just one thread could call dev_change_flags() at a certain time. dev_base_lock is for protecting access to the dev_base list (which contains the current active network device, if I'm not mistaken. Note that if you are going to GET the flags via a ioctl(), the code in dev_ioctl() would do: read_lock(&dev_base_lock); While, if you are going to SET the flags via a ioctl(), the code in dev_ioctl() would acquire the rtnl semaphore, but wouldnt instead do: write_lock(&dev_base_lock); So the rtnl semaphore doesnt protect the writer against readers of the flags variables, but against writers that are calling dev_change_flags. Aritz Bastida PS: Sorry, i just answered to you. I send it again for the mailing list - : send the line "unsubscribe linux-net" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html