예제 #1
0
    def fsinit(self):
        class FakeUmnt:
            """
            To avoid multiple calls to mountclient.Umnt, set self.mcl = FakeUmnt()
            """
            def Umnt(self, path):
                pass

        if self.server:
            self.host, self.path = self.server.split(':', 1)
        else:
            raise RuntimeError, "No server specified"

        if self.dirhandle:
            self.mcl = FakeUmnt()
            dh = self.dirhandle.translate(None, ':')
            self.rootdh = ''.join(
                chr(int(dh[i:i + 2], 16)) for i in range(0, len(dh), 2))
        else:
            port, proto = splitport(self.mountport)
            proto = proto or "udp"
            try:
                if proto == "udp":
                    self.mcl = FallbackUDPMountClient(self.host, port)
                elif proto == "tcp":
                    self.mcl = FallbackTCPMountClient(self.host, port)
                else:
                    raise RuntimeError, "Invalid mount transport: %s" % proto
            except socket.error as e:
                raise RuntimeError, "Problem mounting to %s:%s/%s: %s\n" % (
                    self.host, repr(port), proto, os.strerror(e.errno))

            status, dirhandle, auth_flavors = self.mcl.Mnt(self.path)
            if status != 0:
                raise IOError(status, os.strerror(status), self.path)
            if self.hide:
                self.mcl.Umnt(self.path)
                self.mcl = FakeUmnt()
            self.rootdh = dirhandle

        port, proto = splitport(self.nfsport)
        proto = proto or "udp"
        try:
            if proto == "udp":
                self.ncl = EvilFallbackUDPNFSClient(self.host,
                                                    port,
                                                    fakename=self.fakename)
            elif proto == "tcp":
                self.ncl = EvilFallbackTCPNFSClient(self.host,
                                                    port,
                                                    fakename=self.fakename)
            else:
                raise RuntimeError, "Invalid NFS transport: %s" % proto
        except socket.error as e:
            raise RuntimeError, "Problem establishing NFS to %s:%s/%s: %s\n" % (
                self.host, repr(port), proto, os.strerror(e.errno))

        self.ncl.fuid = self.ncl.fgid = 0

        rest = self.ncl.Fsinfo(self.rootdh)
        if rest[0]:
            self.rootattr = rest[0]
        else:
            self.rootattr = self.ncl.Getattr(self.rootdh)
        self.ncl.fuid = self.rootattr[3]
        self.ncl.fgid = self.rootattr[4]
        self.rtsize = min(rest[2] or 4096, NFSSVC_MAXBLKSIZE)
        self.wtsize = min(rest[5] or 4096, NFSSVC_MAXBLKSIZE)
        self.handles = LRU(self.cache)

        if self.getroot:
            try:
                handle, attr = self.gethandle("/..")
                while handle != self.rootdh:
                    self.rootdh = handle
                    self.rootattr = attr
                    handle, attr = self.gethandle("/..")
            except NFSError as e:
                if e.value != NFSError.NFS3ERR_NOENT:
                    raise