Skip to content

Commit

Permalink
refactor(proto): refactor audit log to request extend
Browse files Browse the repository at this point in the history
Signed-off-by: NaturalSelect <[email protected]>
  • Loading branch information
NaturalSelect authored and Victor1319 committed Oct 18, 2023
1 parent b8de6b4 commit 63623a2
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 51 deletions.
14 changes: 7 additions & 7 deletions metanode/partition_op_dentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
func (mp *metaPartition) TxCreateDentry(req *proto.TxCreateDentryRequest, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, 0)
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, 0)
}()
if req.ParentID == req.Inode {
err = fmt.Errorf("parentId is equal inodeId")
Expand Down Expand Up @@ -84,7 +84,7 @@ func (mp *metaPartition) TxCreateDentry(req *proto.TxCreateDentryRequest, p *Pac
func (mp *metaPartition) CreateDentry(req *CreateDentryReq, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, req.ParentID)
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, req.ParentID)
}()
if req.ParentID == req.Inode {
err = fmt.Errorf("parentId is equal inodeId")
Expand Down Expand Up @@ -130,7 +130,7 @@ func (mp *metaPartition) CreateDentry(req *CreateDentryReq, p *Packet, remoteAdd
func (mp *metaPartition) QuotaCreateDentry(req *proto.QuotaCreateDentryRequest, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, req.ParentID)
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, req.ParentID)
}()
if req.ParentID == req.Inode {
err = fmt.Errorf("parentId is equal inodeId")
Expand Down Expand Up @@ -185,7 +185,7 @@ func (mp *metaPartition) QuotaCreateDentry(req *proto.QuotaCreateDentryRequest,
func (mp *metaPartition) TxDeleteDentry(req *proto.TxDeleteDentryRequest, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.FullPath, err, time.Since(start).Milliseconds(), req.Ino, req.ParentID)
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Ino, req.ParentID)
}()
txInfo := req.TxInfo.GetCopy()
den := &Dentry{
Expand Down Expand Up @@ -260,7 +260,7 @@ func (mp *metaPartition) TxDeleteDentry(req *proto.TxDeleteDentryRequest, p *Pac
func (mp *metaPartition) DeleteDentry(req *DeleteDentryReq, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.FullPath, err, time.Since(start).Milliseconds(), 0, req.ParentID)
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.GetFullPath(), err, time.Since(start).Milliseconds(), 0, req.ParentID)
}()
if req.InodeCreateTime > 0 {
if mp.vol.volDeleteLockTime > 0 && req.InodeCreateTime+mp.vol.volDeleteLockTime*60*60 > time.Now().Unix() {
Expand Down Expand Up @@ -381,7 +381,7 @@ func (mp *metaPartition) DeleteDentryBatch(req *BatchDeleteDentryReq, p *Packet,
func (mp *metaPartition) TxUpdateDentry(req *proto.TxUpdateDentryRequest, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, req.ParentID)
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, req.ParentID)
}()
if req.ParentID == req.Inode {
err = fmt.Errorf("parentId is equal inodeId")
Expand Down Expand Up @@ -450,7 +450,7 @@ func (mp *metaPartition) TxUpdateDentry(req *proto.TxUpdateDentryRequest, p *Pac
func (mp *metaPartition) UpdateDentry(req *UpdateDentryReq, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, req.ParentID)
auditlog.LogDentryOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.Name, req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, req.ParentID)
}()
if req.ParentID == req.Inode {
err = fmt.Errorf("parentId is equal inodeId")
Expand Down
2 changes: 1 addition & 1 deletion metanode/partition_op_extent.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (mp *metaPartition) ExtentsTruncate(req *ExtentsTruncateReq, p *Packet, rem
fileSize := uint64(0)
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, fileSize)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, fileSize)
}()
ino := NewInode(req.Inode, proto.Mode(os.ModePerm))
item := mp.inodeTree.CopyGet(ino)
Expand Down
18 changes: 9 additions & 9 deletions metanode/partition_op_inode.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (mp *metaPartition) CreateInode(req *CreateInoReq, p *Packet, remoteAddr st
)
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), inoID, 0)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), inoID, 0)
}()
inoID, err = mp.nextInodeID()
if err != nil {
Expand Down Expand Up @@ -163,7 +163,7 @@ func (mp *metaPartition) QuotaCreateInode(req *proto.QuotaCreateInodeRequest, p
)
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), inoID, 0)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), inoID, 0)
}()
inoID, err = mp.nextInodeID()
if err != nil {
Expand Down Expand Up @@ -226,7 +226,7 @@ func (mp *metaPartition) QuotaCreateInode(req *proto.QuotaCreateInodeRequest, p
func (mp *metaPartition) TxUnlinkInode(req *proto.TxUnlinkInodeRequest, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, 0)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, 0)
}()
txInfo := req.TxInfo.GetCopy()
var status uint8
Expand Down Expand Up @@ -316,7 +316,7 @@ func (mp *metaPartition) UnlinkInode(req *UnlinkInoReq, p *Packet, remoteAddr st
)
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, 0)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, 0)
}()
makeRspFunc := func() {
status := msg.Status
Expand Down Expand Up @@ -575,7 +575,7 @@ func (mp *metaPartition) InodeGetBatch(req *InodeGetReqBatch, p *Packet) (err er
func (mp *metaPartition) TxCreateInodeLink(req *proto.TxLinkInodeRequest, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, 0)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, 0)
}()
txInfo := req.TxInfo.GetCopy()
ino := NewInode(req.Inode, 0)
Expand Down Expand Up @@ -627,7 +627,7 @@ func (mp *metaPartition) TxCreateInodeLink(req *proto.TxLinkInodeRequest, p *Pac
func (mp *metaPartition) CreateInodeLink(req *LinkInodeReq, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, 0)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, 0)
}()
var r interface{}
var val []byte
Expand Down Expand Up @@ -675,7 +675,7 @@ func (mp *metaPartition) CreateInodeLink(req *LinkInodeReq, p *Packet, remoteAdd
func (mp *metaPartition) EvictInode(req *EvictInodeReq, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, 0)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, 0)
}()
ino := NewInode(req.Inode, 0)
val, err := ino.Marshal()
Expand Down Expand Up @@ -773,7 +773,7 @@ func (mp *metaPartition) GetInodeTreeLen() int {
func (mp *metaPartition) DeleteInode(req *proto.DeleteInodeRequest, p *Packet, remoteAddr string) (err error) {
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), req.Inode, 0)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, 0)
}()
var bytes = make([]byte, 8)
binary.BigEndian.PutUint64(bytes, req.Inode)
Expand Down Expand Up @@ -852,7 +852,7 @@ func (mp *metaPartition) TxCreateInode(req *proto.TxCreateInodeRequest, p *Packe
)
start := time.Now()
defer func() {
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.FullPath, err, time.Since(start).Milliseconds(), inoID, 0)
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), inoID, 0)
}()
inoID, err = mp.nextInodeID()
if err != nil {
Expand Down
47 changes: 30 additions & 17 deletions proto/fs_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ func (d Dentry) String() string {
return fmt.Sprintf("Dentry{Name(%v),Inode(%v),Type(%v)}", d.Name, d.Inode, d.Type)
}

type RequestExtend struct {
FullPaths []string `json:"fullPaths"`
}

// NOTE: batch request may have multi full path
// values, but other request only have one
func (r *RequestExtend) GetFullPath() string {
if len(r.FullPaths) < 1 {
return ""
}
return r.FullPaths[0]
}

// CreateInodeRequest defines the request to create an inode.
type QuotaCreateInodeRequest struct {
VolName string `json:"vol"`
Expand All @@ -192,7 +205,7 @@ type QuotaCreateInodeRequest struct {
Gid uint32 `json:"gid"`
Target []byte `json:"tgt"`
QuotaIds []uint32 `json:"qids"`
FullPath string `json:"fullPath"`
RequestExtend
}

type CreateInodeRequest struct {
Expand All @@ -202,7 +215,7 @@ type CreateInodeRequest struct {
Uid uint32 `json:"uid"`
Gid uint32 `json:"gid"`
Target []byte `json:"tgt"`
FullPath string `json:"fullPath"`
RequestExtend
}

// CreateInodeResponse defines the response to the request of creating an inode.
Expand Down Expand Up @@ -236,7 +249,7 @@ type TxCreateInodeRequest struct {
Target []byte `json:"tgt"`
QuotaIds []uint32 `json:"qids"`
TxInfo *TransactionInfo `json:"tx"`
FullPath string `json:"fullPath"`
RequestExtend
}

// TxCreateInodeResponse defines the response with transaction info to the request of creating an inode.
Expand Down Expand Up @@ -294,7 +307,7 @@ type LinkInodeRequest struct {
Inode uint64 `json:"ino"`
UniqID uint64 `json:"uiq"`
IsRename bool `json:"rename"`
FullPath string `json:"fullPath"`
RequestExtend
}

// LinkInodeResponse defines the response to the request of linking an inode.
Expand All @@ -307,7 +320,7 @@ type TxLinkInodeRequest struct {
PartitionID uint64 `json:"pid"`
Inode uint64 `json:"ino"`
TxInfo *TransactionInfo `json:"tx"`
FullPath string `json:"fullPath"`
RequestExtend
}

func (tx *TxLinkInodeRequest) GetInfo() string {
Expand All @@ -334,7 +347,7 @@ type TxUnlinkInodeRequest struct {
Inode uint64 `json:"ino"`
Evict bool `json:"evict"`
TxInfo *TransactionInfo `json:"tx"`
FullPath string `json:"fullPath"`
RequestExtend
}

func (tx *TxUnlinkInodeRequest) GetInfo() string {
Expand All @@ -354,7 +367,7 @@ type UnlinkInodeRequest struct {
UniqID uint64 `json:"uid"` //for request dedup
VerSeq uint64 `json:"ver"`
DenVerSeq uint64 `json:"denVer"`
FullPath string `json:"fullPath"`
RequestExtend
}

// UnlinkInodeRequest defines the request to unlink an inode.
Expand Down Expand Up @@ -383,7 +396,7 @@ type EvictInodeRequest struct {
VolName string `json:"vol"`
PartitionID uint64 `json:"pid"`
Inode uint64 `json:"ino"`
FullPath string `json:"fullPath"`
RequestExtend
}

// EvictInodeRequest defines the request to evict some inode.
Expand All @@ -404,7 +417,7 @@ type QuotaCreateDentryRequest struct {
Mode uint32 `json:"mode"`
QuotaIds []uint32 `json:"qids"`
VerSeq uint64 `json:"seq"`
FullPath string `json:"fullPath"`
RequestExtend
}

type CreateDentryRequest struct {
Expand All @@ -415,7 +428,7 @@ type CreateDentryRequest struct {
Name string `json:"name"`
Mode uint32 `json:"mode"`
VerSeq uint64 `json:"seq"`
FullPath string `json:"fullPath"`
RequestExtend
}

type TxPack interface {
Expand All @@ -432,7 +445,7 @@ type TxCreateDentryRequest struct {
Mode uint32 `json:"mode"`
QuotaIds []uint32 `json:"qids"`
TxInfo *TransactionInfo `json:"tx"`
FullPath string `json:"fullPath"`
RequestExtend
}

func (tx *TxCreateDentryRequest) GetInfo() string {
Expand All @@ -450,7 +463,7 @@ type UpdateDentryRequest struct {
ParentID uint64 `json:"pino"`
Name string `json:"name"`
Inode uint64 `json:"ino"` // new inode number
FullPath string `json:"fullPath"`
RequestExtend
}

// UpdateDentryResponse defines the response to the request of updating a dentry.
Expand All @@ -466,7 +479,7 @@ type TxUpdateDentryRequest struct {
Inode uint64 `json:"ino"` // new inode number
OldIno uint64 `json:"oldIno"` // new inode number
TxInfo *TransactionInfo `json:"tx"`
FullPath string `json:"fullPath"`
RequestExtend
}

func (tx *TxUpdateDentryRequest) GetInfo() string {
Expand All @@ -484,7 +497,7 @@ type TxDeleteDentryRequest struct {
Name string `json:"name"`
Ino uint64 `json:"ino"`
TxInfo *TransactionInfo `json:"tx"`
FullPath string `json:"fullPath"`
RequestExtend
}

func (tx *TxDeleteDentryRequest) GetInfo() string {
Expand All @@ -503,7 +516,7 @@ type DeleteDentryRequest struct {
Name string `json:"name"`
InodeCreateTime int64 `json:"inodeCreateTime"`
Verseq uint64 `json:"ver"`
FullPath string `json:"fullPath"`
RequestExtend
}

type BatchDeleteDentryRequest struct {
Expand Down Expand Up @@ -697,7 +710,7 @@ type TruncateRequest struct {
PartitionID uint64 `json:"pid"`
Inode uint64 `json:"ino"`
Size uint64 `json:"sz"`
FullPath string `json:"fullPath"`
RequestExtend
}

type EmptyExtentKeyRequest struct {
Expand Down Expand Up @@ -747,7 +760,7 @@ type DeleteInodeRequest struct {
VolName string `json:"vol"`
PartitionId uint64 `json:"pid"`
Inode uint64 `json:"ino"`
FullPath string `json:"fullPath"`
RequestExtend
}

// DeleteInodeRequest defines the request to delete an inode.
Expand Down
Loading

0 comments on commit 63623a2

Please sign in to comment.