⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kfsops.h

📁 nandflash文件系统源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------- -*- Mode: C++ -*-// $Id: KfsOps.h 216 2008-11-07 07:43:36Z sriramsrao $ //// Created 2006/05/24// Author: Sriram Rao//// Copyright 2008 Quantcast Corp.// Copyright 2006-2008 Kosmix Corp.//// This file is part of Kosmos File System (KFS).//// Licensed under the Apache License, Version 2.0// (the "License"); you may not use this file except in compliance with// the License. You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or// implied. See the License for the specific language governing// permissions and limitations under the License.//////----------------------------------------------------------------------------#ifndef _LIBKFSCLIENT_KFSOPS_H#define _LIBKFSCLIENT_KFSOPS_H#include <algorithm>#include <string>#include <sstream>#include <vector>#include "common/kfstypes.h"#include "KfsAttr.h"#include "common/properties.h"namespace KFS {enum KfsOp_t {    CMD_UNKNOWN,    // Meta-data server RPCs    CMD_GETALLOC,    CMD_GETLAYOUT,    CMD_ALLOCATE,    CMD_TRUNCATE,    CMD_LOOKUP,    CMD_MKDIR,    CMD_RMDIR,    CMD_READDIR,    CMD_READDIRPLUS,    CMD_GETDIRSUMMARY,    CMD_CREATE,    CMD_REMOVE,    CMD_RENAME,    CMD_LEASE_ACQUIRE,    CMD_LEASE_RENEW,    CMD_LEASE_RELINQUISH,    CMD_CHANGE_FILE_REPLICATION,    CMD_DUMP_CHUNKTOSERVERMAP,    CMD_UPSERVERS,    // Chunkserver RPCs    CMD_OPEN,    CMD_CLOSE,    CMD_READ,    CMD_WRITE_ID_ALLOC,    CMD_WRITE_PREPARE,    CMD_WRITE_SYNC,    CMD_SIZE,    CMD_GET_CHUNK_METADATA,    CMD_NCMDS,    CMD_DUMP_CHUNKMAP};struct KfsOp {    KfsOp_t op;    kfsSeq_t   seq;    int32_t   status;    uint32_t  checksum; // a checksum over the data    size_t    contentLength;    size_t    contentBufLen;    char      *contentBuf;    KfsOp (KfsOp_t o, kfsSeq_t s) :        op(o), seq(s), status(0), checksum(0), contentLength(0),        contentBufLen(0), contentBuf(NULL)    {    }    // to allow dynamic-type-casting, make the destructor virtual    virtual ~KfsOp() {        if (contentBuf != NULL)            delete [] contentBuf;    }    void AttachContentBuf(const char *buf, size_t len) {        AttachContentBuf((char *) buf, len);    }    void AttachContentBuf(char *buf, size_t len) {        contentBuf = buf;        contentBufLen = len;    }    void ReleaseContentBuf() {        contentBuf = NULL;        contentBufLen = 0;    }    // Build a request RPC that can be sent to the server    virtual void Request(std::ostringstream &os) = 0;    // Common parsing code: parse the response from string and fill    // that into a properties structure.    void ParseResponseHeaderCommon(std::string &resp, Properties &prop);    // Parse a response header from the server: This does the    // default parsing of OK/Cseq/Status/Content-length.    virtual void ParseResponseHeader(char *buf, int len);    // Return information about op that can printed out for debugging.    virtual std::string Show() const = 0;};struct CreateOp : public KfsOp {    kfsFileId_t parentFid; // input parent file-id    const char *filename;    kfsFileId_t fileId; // result    int numReplicas; // desired degree of replication    bool exclusive; // O_EXCL flag    CreateOp(kfsSeq_t s, kfsFileId_t p, const char *f, int n, bool e) :        KfsOp(CMD_CREATE, s), parentFid(p), filename(f),        numReplicas(n), exclusive(e)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "create: " << filename << " (parentfid = " << parentFid << ")";        return os.str();    }};struct RemoveOp : public KfsOp {    kfsFileId_t parentFid; // input parent file-id    const char *filename;    RemoveOp(kfsSeq_t s, kfsFileId_t p, const char *f) :        KfsOp(CMD_REMOVE, s), parentFid(p), filename(f)    {    }    void Request(std::ostringstream &os);    std::string Show() const {        std::ostringstream os;        os << "remove: " << filename << " (parentfid = " << parentFid << ")";        return os.str();    }};struct MkdirOp : public KfsOp {    kfsFileId_t parentFid; // input parent file-id    const char *dirname;    kfsFileId_t fileId; // result    MkdirOp(kfsSeq_t s, kfsFileId_t p, const char *d) :        KfsOp(CMD_MKDIR, s), parentFid(p), dirname(d)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "mkdir: " << dirname << " (parentfid = " << parentFid << ")";        return os.str();    }};struct RmdirOp : public KfsOp {    kfsFileId_t parentFid; // input parent file-id    const char *dirname;    RmdirOp(kfsSeq_t s, kfsFileId_t p, const char *d) :        KfsOp(CMD_RMDIR, s), parentFid(p), dirname(d)    {    }    void Request(std::ostringstream &os);    // default parsing of OK/Cseq/Status/Content-length will suffice.    std::string Show() const {        std::ostringstream os;        os << "rmdir: " << dirname << " (parentfid = " << parentFid << ")";        return os.str();    }};struct RenameOp : public KfsOp {    kfsFileId_t parentFid; // input parent file-id    const char *oldname;  // old file name/dir    const char *newpath;  // new path to be renamed to    bool overwrite; // set if the rename can overwrite newpath    RenameOp(kfsSeq_t s, kfsFileId_t p, const char *o,             const char *n, bool c) :        KfsOp(CMD_RENAME, s), parentFid(p), oldname(o),        newpath(n), overwrite(c)    {    }    void Request(std::ostringstream &os);    // default parsing of OK/Cseq/Status/Content-length will suffice.    std::string Show() const {        std::ostringstream os;        if (overwrite)            os << "rename_overwrite: ";        else            os << "rename: ";        os << " old=" << oldname << " (parentfid = " << parentFid << ")";        os << " new = " << newpath;        return os.str();    }};struct ReaddirOp : public KfsOp {    kfsFileId_t fid; // fid of the directory    int numEntries; // # of entries in the directory    ReaddirOp(kfsSeq_t s, kfsFileId_t f):        KfsOp(CMD_READDIR, s), fid(f), numEntries(0)    {    }    void Request(std::ostringstream &os);    // This will only extract out the default+num-entries.  The actual    // dir. entries are in the content-length portion of things    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "readdir: fid = " << fid;        return os.str();    }};struct DumpChunkServerMapOp : public KfsOp {	DumpChunkServerMapOp(kfsSeq_t s):		KfsOp(CMD_DUMP_CHUNKTOSERVERMAP, s)	{	}	void Request(std::ostringstream &os);	void ParseResponseHeader(char *buf, int len);	std::string Show() const {		std::ostringstream os;		os << "dumpchunktoservermap";		return os.str();	}};struct UpServersOp : public KfsOp {    UpServersOp(kfsSeq_t s):        KfsOp(CMD_UPSERVERS, s)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "upservers";        return os.str();    }};struct DumpChunkMapOp : public KfsOp {	DumpChunkMapOp(kfsSeq_t s):		KfsOp(CMD_DUMP_CHUNKMAP, s)	{	}	void Request(std::ostringstream &os);	void ParseResponseHeader(char *buf, int len);	std::string Show() const {		std::ostringstream os;		os << "dumpchunkmap";		return os.str();	}};struct ReaddirPlusOp : public KfsOp {    kfsFileId_t fid; // fid of the directory    int numEntries; // # of entries in the directory    ReaddirPlusOp(kfsSeq_t s, kfsFileId_t f):        KfsOp(CMD_READDIRPLUS, s), fid(f), numEntries(0)    {    }    void Request(std::ostringstream &os);    // This will only extract out the default+num-entries.  The actual    // dir. entries are in the content-length portion of things    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "readdirplus: fid = " << fid;        return os.str();    }};struct GetDirSummaryOp : public KfsOp {    kfsFileId_t fid; // fid of the directory    uint64_t numFiles; // output    uint64_t numBytes; // output    GetDirSummaryOp(kfsSeq_t s, kfsFileId_t f):        KfsOp(CMD_GETDIRSUMMARY, s), fid(f), numFiles(0), numBytes(0)    {    }    void Request(std::ostringstream &os);    // This will only extract out the default+num-entries.  The actual    // dir. entries are in the content-length portion of things    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "getdirsummary: fid = " << fid;        return os.str();    }};// Lookup the attributes of a file in a directorystruct LookupOp : public KfsOp {    kfsFileId_t parentFid; // fid of the parent dir    const char *filename; // file in the dir    KfsServerAttr fattr; // result    LookupOp(kfsSeq_t s, kfsFileId_t p, const char *f) :        KfsOp(CMD_LOOKUP, s), parentFid(p), filename(f)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "lookup: " << filename << " (parentfid = " << parentFid << ")";        return os.str();    }};// Lookup the attributes of a file relative to a root dir.struct LookupPathOp : public KfsOp {    kfsFileId_t rootFid; // fid of the root dir    const char *filename; // path relative to root    KfsServerAttr fattr; // result    LookupPathOp(kfsSeq_t s, kfsFileId_t r, const char *f) :        KfsOp(CMD_LOOKUP, s), rootFid(r), filename(f)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "lookup_path: " << filename << " (rootFid = " << rootFid << ")";        return os.str();    }};/// Get the allocation information for a chunk in a file.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -