tech-kern archive

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

Re: VOP_CREATE hanging

On Tue Aug 12 2008 at 07:40:05 -0700, Adam Burkepile wrote:
> For my subfile project I am creating a directory and not attaching it  
> to a parent directory, but rather storing the inode number of the  
> directory and retrieving it using VGET. I'm having a problem when I  
> try to create files within this directory however, it seems to just  
> hang. Seems to be when I call VOP_CREATE so I was thinking I might  
> have some argument messed up but I've been at it for awhile and can't  
> seem to find the problem.
> Here is a snipit of code from when I attempt to create the file:
>                 printf("subfile not found, needs to be created\n");
>                         SCARG(uap, sub_path));
>                 sfnd.ni_cnd.cn_nameiop = CREATE;
>                 sfnd.ni_cnd.cn_flags |= LOCKPARENT | LOCKLEAF;
>                 if ((SCARG(uap, flags) & O_EXCL) == 0 && ((SCARG(uap,  
> flags) & O_NOFOLLOW) == 0))
>                         sfnd.ni_cnd.cn_flags |= FOLLOW;
>                 /* lock subfile directory */
>                 if(VOP_ISLOCKED(sdvp) == 0){
>                         printf("sdvp is unlocked, now locking\n");
>                         vn_lock(sdvp, LK_EXCLUSIVE | LK_RETRY);
>                 }

Please don't write code which does locking like this, it's just begging
for trouble.  Your code should always know if it has a node locked or not.

>                 /* set the attr of the new file */
>                 VATTR_NULL(&sfva);
>                 sfva.va_type = VREG;
>                 sfva.va_mode = ((bva.va_mode &~ cwdi->cwdi_cmask) &  
>                 if (SCARG(uap, flags) & O_EXCL)
>                         sfva.va_vaflags |= VA_EXCLUSIVE;
>                 error = VOP_CREATE(sdvp,&sfvp,&(sfnd.ni_cnd),&sfva);
>                 printf("VOP_CREATE error = %d\n",error);
> Any advice on why it is hanging or even why it might be hanging this  
> would be greatly appreciated. I can post more info if that would help.

It is not legal to call VOP_CREATE() without calling namei (ultimately
VOP_LOOKUP()), since this call sets up a lot of state in the file system
to prepare for the actual creation operation.  I can see the problem if
you can't execute VOP_LOOKUP due to how you've attached the names ....

There has been some talk of modifying lookup so as to decouple it from
other operations (e.g. VOP_CREATE), but that's not something you can
depend on in the SoC timeframe.  You'll just have to come up with a
different approach.  Or, if you're working just with ffs, you could hack
lookup into pieces so you can call the parts involved with the necessary
setup for create.

Home | Main Index | Thread Index | Old Index