Changeset 131

Show
Ignore:
Timestamp:
04/24/08 19:31:30 (7 months ago)
Author:
ydario
Message:

Check for resource type at mount time, only for nd/ndpm, so ndpm can retry operation. ticket:58.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/samba-3.0/source/ndpsmb/ndpsmb.c

    r127 r131  
    184184        return dst; 
    185185} 
     186 
     187// ------------------------------------------------------------- 
    186188 
    187189/* uppercased type of resource */ 
     
    914916} 
    915917 
     918// ------------------------------------------------------------- 
     919 
     920/* check if the requested resource is available */ 
     921static int checkMountResource( Resource* pRes) 
     922{ 
     923        int rc; 
     924        unsigned long action; 
     925        smb_request req = {0}; 
     926        smb_response resp = {0}; 
     927        Connection Conn = {0}; 
     928 
     929        debug_printf("checkMountResource in tid#%d\n", _gettid()); 
     930 
     931        // open the pipe 
     932        Conn.pRes = pRes; 
     933        Conn.file.fd = -1; 
     934        debug_printf("checkMountResource open pipe\n"); 
     935        rc = openpipe(pRes, &Conn.pipe); 
     936        if (rc) 
     937        { 
     938            debug_printf("checkMountResource open pipe failed rc=%d\n", rc); 
     939            return rc; 
     940        } 
     941 
     942        // init, get client pid 
     943        debug_printf("checkMountResource send INIT for '%s'\n", pRes->srv.share_name); 
     944        req.request = SMBREQ_INIT; 
     945        req.param = (char *)0xFFFFFFFF; 
     946        rc = _DosTransactNPipe(&Conn, &req, sizeof(req), &resp, sizeof(resp), &action); 
     947        if (rc || action < sizeof(resp) || resp.rc) 
     948        { 
     949            debug_printf("checkMountResource INIT failed rc=%d\n", rc); 
     950            // close pipe 
     951            DosClose( Conn.pipe); 
     952            return rc; 
     953        } 
     954        Conn.clientpid = resp.value & 0xFFFF; 
     955 
     956        // allocate shared memory 
     957        rc = DosAllocSharedMem((PPVOID)&Conn.mem, NULL, pRes->memlen, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_GIVEABLE | pRes->objany); 
     958        if (rc) 
     959        { 
     960            debug_printf("checkMountResource DosAllocSharedMem failed rc=%d\n", rc); 
     961            // close pipe 
     962            DosClose( Conn.pipe); 
     963            return rc; 
     964        } 
     965        rc = DosGiveSharedMem( Conn.mem, Conn.clientpid, PAG_READ | PAG_WRITE); 
     966        if (!rc) 
     967        { 
     968            // open connection with samba server, just to check share type 
     969            debug_printf("checkMountResource send CONNECT\n"); 
     970            MemCpy( Conn.mem, &pRes->srv, sizeof(pRes->srv)); 
     971            req.request = SMBREQ_CONNECT; 
     972            req.param = Conn.mem; 
     973            req.paramlen = sizeof( Conn.srv); 
     974            req.length = req.paramlen; 
     975            rc = _DosTransactNPipe( &Conn, &req, sizeof(req), &resp, sizeof(resp), &action); 
     976            if (rc || action < sizeof(resp) || resp.rc) 
     977            { 
     978                debug_printf("checkMountResource SMBREQ_CONNECT failed rc=%d, resp.rc=%d\n", rc, resp.rc); 
     979                rc = (rc == NO_ERROR ? resp.rc : rc); 
     980            } 
     981            // no more data, close connection    
     982            req.request = SMBREQ_DISCONNECT; 
     983            req.param = Conn.mem; 
     984            req.length = 0; 
     985            req.paramlen = 0; 
     986            _DosTransactNPipe( &Conn, &req, sizeof(req), &resp, sizeof(resp), &action); 
     987        } 
     988 
     989        // free memory 
     990        DosFreeMem( Conn.mem); 
     991        // close pipe 
     992        DosClose( Conn.pipe); 
     993 
     994        return rc; 
     995} 
    916996 
    917997int APIENTRY NdpMountResource (HRESOURCE *presource, int type, NDPROPERTYHANDLE properties) 
     
    9201000        unsigned long objany = OBJ_ANY; 
    9211001        Resource *pRes = NULL; 
    922         /* since we support only 1 type of resources we do not need */ 
     1002 
     1003        log("NdpMountResource in\n"); 
     1004 
     1005        /* since samba plugin support only 1 type of resources we do not need */ 
    9231006        /* to check what the found type really is */ 
    9241007        rc = DosAllocMem((void **)&pRes, sizeof(Resource), PAG_COMMIT | PAG_READ | PAG_WRITE | objany); 
     
    9371020                pRes->properties = properties; 
    9381021                pRes->objany = objany; 
     1022                // parse init string 
    9391023                rc = initResource (pRes); 
    940                 if (rc == NO_ERROR) 
    941                 { 
     1024                // try to connect to resource (check type) only if thread!=1, so ndctl startup 
     1025                // is not slowed down by network connections. 
     1026                // ndctl does mounting on main thread (#1) 
     1027                // nd/ndpm do not use main thread 
     1028                if (!rc && _gettid()!=1) 
     1029                    rc = checkMountResource( pRes); 
     1030                if (!rc) 
     1031                { 
     1032                        // store resource data 
    9421033                        *presource = (HRESOURCE)pRes; 
    9431034                } 
     
    9471038                } 
    9481039        } 
    949         log("NdpMountResource %d\n", rc); 
    950         return rc; 
    951 } 
     1040        log("NdpMountResource rc=%d\n", rc); 
     1041        return rc; 
     1042} 
     1043 
     1044// ------------------------------------------------------------- 
    9521045 
    9531046int APIENTRY NdpCreateConnection (HRESOURCE resource, HCONNECTION *pconn) 
     
    10431136} 
    10441137 
     1138// ------------------------------------------------------------- 
    10451139 
    10461140int APIENTRY NdpFreeConnection (HCONNECTION conn)