SMP question w.r.t. reading kernel variables

Rick Macklem rmacklem at uoguelph.ca
Sun Apr 17 19:49:57 UTC 2011


Hi,

I should know the answer to this, but... When reading a global kernel
variable, where its modifications are protected by a mutex, is it
necessary to get the mutex lock to just read its value?

For example:
A    if ((mp->mnt_kern_flag & MNTK_UNMOUNTF) != 0)
          return (EPERM);
versus
B    MNT_ILOCK(mp);
     if ((mp->mnt_kern_flag & MNTK_UNMOUNTF) != 0) {
          MNT_IUNLOCK(mp);
          return (EPERM);
     }
     MNT_IUNLOCK(mp);

My hunch is that B is necessary if you need an up-to-date value
for the variable (mp->mnt_kern_flag in this case).

Is that correct?

Thanks in advance for help with this, rick


More information about the freebsd-hackers mailing list