FreeBSD module inference count problem

From: dragonfly dragonfly (dragonylffly_at_hotmail.com)
Date: 03/31/05

  • Next message: John Baldwin: "Re: FreeBSD module inference count problem"
    To: freebsd-arch@freebsd.org
    Date: Thu, 31 Mar 2005 09:24:51 +0800
    
    

    Hi all,
    Recently I am doing some programming on FreeBSD KLD.
    In my KLD codes,I will start some kernel threads to serve requests,but i
    can not find how to increase the module reference count,something like
    'MOD_INC_USE_COUNT' in Linux.If not do so,if the user
    downloaded the module before all kernel threads exit,
    the system must be panic.I searched the file 'module.h'
    carefully,only find module_reference().But it seemed in
    total kernel source,the function does not be used.Even
    use it,when i use kldstat to see its reference count,it keep __1__!
    When i download the module before the kernel thread wake up,
    system panic as expect.
    my KLD codes like below:
    module_t curmod;
    void do_job(void *arg)
    {
    if (!curmod)
    printf("Module not found\n");
    else
    module_reference(curmod);
    tsleep(curproc,PRIBIO,"foo worker",15*hz);
    printf("Wake up\n");
    if (curmod)
    module_release(curmod);
    kthread_exit(0);
    }
    static int foo_loader(struct module *m, int what, void *arg)
    {
    int err = 0;
    struct proc *newpp;

    switch (what) {
    case MOD_LOAD:
    curmod=m;
    kthread_create(do_job,NULL,&newpp,0,0,"foo worker");
    printf("foo loaded\n");
    break;
    case MOD_UNLOAD:
    case MOD_SHUTDOWN:
    printf("foo unloaded.\n");
    break;
    default:
    err = EOPNOTSUPP;
    break;
    }

    return(err);
    }
    Could you help me?
    Thanks.

    _________________________________________________________________
    与联机的朋友进行交流,请使用 MSN Messenger: http://messenger.msn.com/cn

    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"


  • Next message: John Baldwin: "Re: FreeBSD module inference count problem"

    Relevant Pages