Ejemplo n.º 1
0
Archivo: fs.py Proyecto: nukamu/dddfs
        def read(self, length, offset):
            DRDFSLog.debug("** read ** offset %d, length =%d" % (offset, length))
            requestl = self.cal_bl(offset, length)
            # prepare buffer to return
            ret_str = cStringIO.StringIO()
            DRDFSLog.debug("requestl = %s, with offset: %d, length: %d" % (str(requestl), offset, length))
            for req in requestl:
                reqbl = req[0]
                buf = ""  # buffer for block[reqbl]
                last_readbl = reqbl

                if self.bldata[reqbl].state == 2:
                    buf = self.bldata[reqbl].buf
                elif self.bldata[reqbl].state == 1:
                    DRDFSLog.debug("Waiting recv data %d block" % reqbl)
                    while self.bldata[reqbl].state == 1:
                        time.sleep(0.01)
                    buf = self.bldata[reqbl].buf
                else:
                    ret = self.request_block(reqbl)
                    if ret != 0:
                        DRDFSLog.error("read error! (%d)" % ret)
                        return ret
                    while self.bldata[reqbl].state == 1:
                        time.sleep(0.01)
                    with self.r_buflock:
                        buf = self.bldata[reqbl].buf

                # write strings to return and if reach EOF, break
                ret_str.write(buf[req[1] : req[2]])
                if len(buf) < conf.blsize:
                    break  # end of file

            return ret_str.getvalue()
Ejemplo n.º 2
0
        def flush(self, fd, listlen, datalen):
            DRDFSLog.debug("flush: fd=%d, listlen=%d, datalen=%d" % (fd, listlen, datalen))

            buf = self.c_channel._recvall(listlen)
            writelist = cPickle.loads(buf)
            buf = self.c_channel._recvall(datalen)

            write = 0
            for wd in writelist:
                try:
                    os.lseek(fd, wd[0], os.SEEK_SET)
                    res = os.write(fd, buf[write:write+wd[1]])
                    write += res
                    if res != wd[1]:
                        DRDFSLog.error("write length error !!")
                    DRDFSLog.debug("write from offset %d (result %d)" % (wd[0], res))
                except Exception, e:
                    senddata = -e.errno
Ejemplo n.º 3
0
        def flush(self, fd, listlen, datalen):
            DRDFSLog.debug("flush: fd=%d, listlen=%d, datalen=%d" %
                           (fd, listlen, datalen))

            buf = self.c_channel._recvall(listlen)
            writelist = cPickle.loads(buf)
            buf = self.c_channel._recvall(datalen)

            write = 0
            for wd in writelist:
                try:
                    os.lseek(fd, wd[0], os.SEEK_SET)
                    res = os.write(fd, buf[write:write + wd[1]])
                    write += res
                    if res != wd[1]:
                        DRDFSLog.error("write length error !!")
                    DRDFSLog.debug("write from offset %d (result %d)" %
                                   (wd[0], res))
                except Exception, e:
                    senddata = -e.errno
Ejemplo n.º 4
0
        def read(self, fd, bl_num):
            DRDFSLog.debug("fd = %d, bl_num = %d" % (fd, bl_num))
            try:
                os.lseek(fd, bl_num * conf.blsize, os.SEEK_SET)

                buf = cStringIO.StringIO()
                readlen = 0
                while readlen < conf.blsize - 1:
                    os.lseek(fd, bl_num * conf.blsize + readlen, os.SEEK_SET)
                    tmpbuf = os.read(fd, conf.blsize - readlen)
                    if tmpbuf == '':   # end of file
                        break
                    buf.write(tmpbuf)
                    readlen += len(tmpbuf)
                sendbuf = buf.getvalue()
                DRDFSLog.debug("read from file offset %d len %d (result %d)" % 
                               (bl_num * conf.blsize, conf.blsize, len(sendbuf)))
                senddata = [0, bl_num, len(sendbuf)]
            except Exception, e:
                DRDFSLog.error("read have an error (%s)" % (e))
                senddata = [e.errno, 'null', 0, 0]
Ejemplo n.º 5
0
        def read(self, fd, bl_num):
            DRDFSLog.debug("fd = %d, bl_num = %d" % (fd, bl_num))
            try:
                os.lseek(fd, bl_num * conf.blsize, os.SEEK_SET)

                buf = cStringIO.StringIO()
                readlen = 0
                while readlen < conf.blsize - 1:
                    os.lseek(fd, bl_num * conf.blsize + readlen, os.SEEK_SET)
                    tmpbuf = os.read(fd, conf.blsize - readlen)
                    if tmpbuf == '':  # end of file
                        break
                    buf.write(tmpbuf)
                    readlen += len(tmpbuf)
                sendbuf = buf.getvalue()
                DRDFSLog.debug(
                    "read from file offset %d len %d (result %d)" %
                    (bl_num * conf.blsize, conf.blsize, len(sendbuf)))
                senddata = [0, bl_num, len(sendbuf)]
            except Exception, e:
                DRDFSLog.error("read have an error (%s)" % (e))
                senddata = [e.errno, 'null', 0, 0]
Ejemplo n.º 6
0
        def read(self, length, offset):
            DRDFSLog.debug("** read ** offset %d, length =%d" %
                           (offset, length))
            requestl = self.cal_bl(offset, length)
            # prepare buffer to return
            ret_str = cStringIO.StringIO()
            DRDFSLog.debug("requestl = %s, with offset: %d, length: %d" %
                           (str(requestl), offset, length))
            for req in requestl:
                reqbl = req[0]
                buf = ""  # buffer for block[reqbl]
                last_readbl = reqbl

                if self.bldata[reqbl].state == 2:
                    buf = self.bldata[reqbl].buf
                elif self.bldata[reqbl].state == 1:
                    DRDFSLog.debug("Waiting recv data %d block" % reqbl)
                    while self.bldata[reqbl].state == 1:
                        time.sleep(0.01)
                    buf = self.bldata[reqbl].buf
                else:
                    ret = self.request_block(reqbl)
                    if ret != 0:
                        DRDFSLog.error("read error! (%d)" % ret)
                        return ret
                    while self.bldata[reqbl].state == 1:
                        time.sleep(0.01)
                    with self.r_buflock:
                        buf = self.bldata[reqbl].buf

                # write strings to return and if reach EOF, break
                ret_str.write(buf[req[1]:req[2]])
                if len(buf) < conf.blsize:
                    break  # end of file

            return ret_str.getvalue()
Ejemplo n.º 7
0
Archivo: meta.py Proyecto: nukamu/dddfs
                    fd = 0
                    if mode:
                        fd = os.open(self.rootpath + path,
                                     os.O_RDWR | os.O_CREAT, mode[0])
                    else:
                        fd = os.open(self.rootpath + path,
                                     os.O_RDWR | os.O_CREAT)
                except os.error, e:
                    print "!! have fatal error @1!! (%s)" % (e)
                    raise
                try:
                    rand = 0
                    if len(self.datalist) > 0:
                        rand = random.randint(0, len(self.datalist) - 1)
                    else:
                        DRDFSLog.error(
                            "!! There are no data server to create file !!")
                    dist = self.datalist[rand]

                    # make a filename in a random manner
                    filename = ''.join(
                        random.choice(string.letters) for i in xrange(16))
                    DRDFSLog.debug("filename is %s" % (filename, ))
                    buf = dist + ',' + filename + ',' + '0,' + '\n'
                except Exception, e:
                    print "!! have fatal error @2!! (%s)" % (e)
                    raise
                DRDFSLog.debug("fd = " + str(fd))
                try:
                    os.write(fd, buf)
                    os.fsync(fd)
                except os.error, e:
Ejemplo n.º 8
0
                created = True
                try:
                    fd = 0
                    if mode:
                        fd = os.open(self.rootpath + path, os.O_RDWR | os.O_CREAT, mode[0])
                    else:
                        fd = os.open(self.rootpath + path, os.O_RDWR | os.O_CREAT)
                except os.error, e:
                    print "!! have fatal error @1!! (%s)" % (e)
                    raise
                try:
                    rand = 0
                    if len(self.datalist) > 0:
                        rand = random.randint(0, len(self.datalist) - 1)
                    else:
                        DRDFSLog.error("!! There are no data server to create file !!")
                    dist = self.datalist[rand]

                    # make a filename in a random manner
                    filename = ''.join(random.choice(string.letters) for i in xrange(16))
                    DRDFSLog.debug("filename is %s" % (filename,))
                    buf = dist + ',' + filename + ',' + '0,' + '\n'
                except Exception, e:
                    print "!! have fatal error @2!! (%s)" % (e)
                    raise
                DRDFSLog.debug("fd = " + str(fd))
                try:
                    os.write(fd, buf)
                    os.fsync(fd)
                except os.error, e:
                    print "!! have fatal error @3!! (%s)" % (e)