Ejemplo n.º 1
0
Archivo: data.py Proyecto: nukamu/gxp4
    def flush(self, fd, listlen, datalen):
        MogamiLog.debug("fd=%d, listlen=%d, datalen=%d" %
                        (fd, listlen, datalen))

        (write_list, buf) = self.c_channel.flush_recv_data(listlen, datalen)
        if len(write_list) != 0:
            write_len = 0
            for wd in write_list:
                try:
                    ans = 0
                    os.lseek(fd, wd[0], os.SEEK_SET)
                    ret = os.write(fd, buf[write_len:write_len + wd[1]])
                    write_len += ret
                    if ret != wd[1]:
                        MogamiLog.error("write length error !!")
                        break
                    MogamiLog.debug("write from offset %d (result %d)" %
                                    (wd[0], ret))
                except OSError, e:
                    ans = e.errno
                    break
                #except Exception, e:
                #    ans = -1
                #    break

            self.c_channel.flush_answer(ans, write_len)
Ejemplo n.º 2
0
Archivo: meta.py Proyecto: nukamu/gxp4
    def release(self, path, fsize):
        """release handler.

        @param fd file discripter
        @param writelen size of data to be written
        """
        try:
            self.meta_rep.release(path, fsize)
        except Exception, e:
            MogamiLog.error("OSError in release (%s)" % (e))
Ejemplo n.º 3
0
Archivo: data.py Proyecto: nukamu/gxp4
 def truncate(self, path, length):
     MogamiLog.debug("path = %s. length = %d" % (path, length))
     try:
         f = open(path, "r+")
         f.truncate(length)
         f.close()
         ans = 0
     except Exception, e:
         MogamiLog.error("have an error (%s)" % (e))
         ans = e.errno
Ejemplo n.º 4
0
 def recv_msg(self, ):
     """receive packed message.
     """
     res_buf = cStringIO.StringIO()
     buf = ""
     while buf[-3:] != "end":
         buf = self.recvall(conf.bufsize)
         if len(buf) != conf.bufsize:
             MogamiLog.error("recv_msg error")
             return None
         res_buf.write(buf[:-3])
     ret = cPickle.loads(res_buf.getvalue())
     return ret
Ejemplo n.º 5
0
Archivo: meta.py Proyecto: nukamu/gxp4
    def remove_data_server(self, ip):
        """remove a data server from Mogami system

        @param ip ip address of node to remove
        @return 0 with success, -1 with error
        """
        try:
            self.data_list.remove(ip)
            del self.data_rootpath[ip]
            return True
        except Exception, e:
            MogamiLog.error("cannot find %s from data servers" % (ip))
            return False
Ejemplo n.º 6
0
    def send_msg(self, data):
        """send packed message.

        @param data data to send
        """
        buf = cPickle.dumps(data)
        while conf.bufsize - 3 < len(buf):
            ret = self.sendall(buf[:conf.bufsize - 3] + "---")
            if ret == None:
                MogamiLog.error("send_msg error")
                break
            buf = buf[conf.bufsize - 3:]
        buf = buf + "-" * (conf.bufsize - len(buf) - 3) + "end"
        self.sendall(buf)
Ejemplo n.º 7
0
Archivo: data.py Proyecto: nukamu/gxp4
    def read(self, fd, blnum):
        MogamiLog.debug("fd = %d, bl_num = %d" % (fd, blnum))

        sendbuf = ""
        try:
            os.lseek(fd, blnum * conf.blsize, os.SEEK_SET)
            buf = cStringIO.StringIO()
            readlen = 0
            while readlen < conf.blsize - 1:
                os.lseek(fd, blnum * 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()
            ans = 0
        except Exception, e:
            MogamiLog.error("read have an error (%s)" % (e))
            ans = e.errno
Ejemplo n.º 8
0
    def recvall(self, length):
        """recv all data.

        This function may return less data than required.
        (when connection closed)
        @param length length of data to receive
        """
        buf = cStringIO.StringIO()
        recvlen = 0
        while recvlen < length:
            try:
                recvdata = self.sock.recv(length - recvlen)
            except Exception, e:
                MogamiLog.error("** Connection closed suddenly **")
                self.sock.close()
                break
            if recvdata == "":
                self.sock.close()
                break
            buf.write(recvdata)
            recvlen += len(recvdata)
Ejemplo n.º 9
0
    def run(self, ):
        while True:
            req = self.c_channel.recv_request()
            if req == None:  # failed to receive data
                MogamiLog.debug("Connection closed by failing recv data")
                self.c_channel.finalize()
                break
            elif req[0] == channel.REQ_CLOSE:  # close request
                MogamiLog.debug("Connection closed by close request")
                self.c_channel.finalize()
                break

            if req[0] in self.func_dict:
                MogamiLog.debug('** %s **' % (self.func_dict[req[0]]))
                method = getattr(self, self.func_dict[req[0]])
                req_args = list(req)
                req_args.pop(0)
                method(*req_args)

            else:  # doesn't match any expected request
                MogamiLog.error('** This is unexpected header **')
                self.c_channel.finalize()
                break
Ejemplo n.º 10
0
    def recvall_with_time(self, length):
        """receive data and measure time to receive

        This function seems to be called only in prefetching.
        @param length length of data to receive
        """
        buf = cStringIO.StringIO()
        recvlen = 0
        recv_time = 0
        while recvlen < length:
            try:
                start_t = time.time()
                recvdata = self.sock.recv(length - recvlen)
                end_t = time.time()
            except Exception, e:
                MogamiLog.error("** Connection closed suddenly **")
                self.sock.close()
                break
            if recvdata == "":
                self.sock.close()
                break
            buf.write(recvdata)
            recvlen += len(recvdata)
            recv_time += end_t - start_t
Ejemplo n.º 11
0
Archivo: data.py Proyecto: nukamu/gxp4
    def prefetch(self, fd, blnum_list):
        for blnum in blnum_list:
            try:
                sendbuf = ""
                start_t = time.time()
                MogamiLog.debug("fd = %d, blnum = %d" % (fd, blnum))
                os.lseek(fd, blnum * conf.blsize, os.SEEK_SET)

                buf = cStringIO.StringIO()
                readlen = 0
                while readlen < conf.blsize - 1:
                    os.lseek(fd, blnum * 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()
                end_t = time.time()

                # send data read from file (only in case w/o error)
                self.c_channel.data_send(0, blnum, len(sendbuf), sendbuf)
            except Exception, e:
                MogamiLog.error("Prefetch Error!! with %d-th block" % (blnum))
Ejemplo n.º 12
0
Archivo: meta.py Proyecto: nukamu/gxp4
        try:
            (dest, dest_path) = self.meta_rep.unlink(path)
            if async is True:
                ans = 0
                if dest != None:
                    self.sysinfo.add_delfile(dest, dest_path)
            else:
                c_channel = channel.MogamiChanneltoData(dest)
                ans = c_channel.delfile_req([dest_path, ])
                c_channel.close_req()
                c_channel.finalize()
        except os.error, e:
            ans = e.errno
        except Exception, e:
            ans = e.errno
            MogamiLog.error("cannot remove file contents of %s" % path)

        self.c_channel.unlink_answer(ans)

    def rename(self, oldpath, newpath):
        MogamiLog.debug(oldpath + ' -> ' + newpath)
        try:
            self.meta_rep.rename(oldpath, newpath)
            ans = 0
        except os.error, e:
            ans = e.errno
        self.c_channel.rename_answer(ans)

    def chmod(self, path, mode):
        MogamiLog.debug("path = %s w/ mode %s" % (path, oct(mode)))
        try:
Ejemplo n.º 13
0
Archivo: fs.py Proyecto: nukamu/gxp4
        def __init__(self, path, flag, *mode):
            """Initializer called when opened.

            @param path file path
            @param flag flags with open(2)
            @param *mode file open mode (may not be specified)
            """
            MogamiLog.debug("** open ** path = %s, flag = %s, mode = %s" %
                            (path, str(flag), str(mode)))
            if conf.ap is True:
                start_t = time.time()

            # parse argurments
            self.path = path
            self.flag = flag
            self.mode = mode

            dest = None
            self.local = False

            if conf.local_request is True:
                try:
                    if local_ch.connected == False:
                        local_ch.connect('127.0.0.1')
                    (ans, data_path, fsize) = local_ch.filereq_req(path)
                    if ans == 0:  # exists on local
                        dest = 'self'
                        self.local = True
                        self.created = False
                        self.fsize = fsize
                except Exception:
                    pass

            if dest == None:
                # request for metadata server
                (ans, dest, data_path, self.fsize,
                 self.created) = m_channel.open_req(path, flag, *mode)
                if dest == 'self':
                    if local_ch.connected == False:
                        local_ch.connect('127.0.0.1')
                    local_ch.fileadd_req(self.path, data_path)
                        
                if ans != 0:  # error on metadata server
                    e = IOError()
                    e.errno = ans
                    raise e

            if dest == 'self':
                self.local = True
                self.mogami_file = filemanager.MogamiLocalFile(
                    self.fsize, local_ch, path, data_path, flag, *mode)
            else:
                self.local = False
                self.mogami_file = filemanager.MogamiRemoteFile(
                    self.fsize, dest, path, data_path, flag, *mode)
                ans = self.mogami_file.create_connections(channels)
                if ans != 0:
                    MogamiLog.error("open error !!")
                    e = IOError()
                    e.errno = ans
                    raise e

            # register file size to file size dictionary
            file_size_dict[path] = self.fsize

            if conf.ap is True:
                """Get Id list to know pid.
                list = {gid: pid: uid}
                And then get the command from pid.
                """
                try:
                    id_list = self.GetContext()
                    pid = id_list['pid']
                    f = open(os.path.join("/proc", str(pid), "cmdline"), 'r')
                    cmd_args = f.read().rsplit('\x00')[:-1]
                except Exception, e:
                    # with any error, pass this proccess
                    cmd_args = None
                    pid = -1
                self.access_pattern = filemanager.MogamiAccessPattern(
                    path, cmd_args, pid)
                end_t = time.time()
                self.took_time = end_t - start_t