Skip to content

Commit 5d1a033

Browse files
committed
feat: 🎸 add debug logging
1 parent a226d87 commit 5d1a033

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/nfs/v4/server/Nfsv4CompoundProcCtx.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Nfsv4CompoundProcCtx {
3737

3838
public async exec(): Promise<msg.Nfsv4CompoundResponse> {
3939
const {req, connection} = this;
40-
const {ops} = connection;
40+
const {ops, debug, logger} = connection;
4141
const {argarray, tag} = req;
4242
const length = argarray.length;
4343
let status: Nfsv4Stat = Nfsv4Stat.NFS4_OK;
@@ -95,8 +95,10 @@ export class Nfsv4CompoundProcCtx {
9595
else if (op instanceof msg.Nfsv4IllegalRequest) (fn = ops.ILLEGAL), (Response = msg.Nfsv4IllegalResponse);
9696
if (!fn || !Response) return new msg.Nfsv4CompoundResponse(Nfsv4Stat.NFS4ERR_OP_ILLEGAL, tag, resarray);
9797
EXEC_OP: try {
98+
if (debug) logger.log(fn.name, opReq);
9899
const opResponse = await fn.call(ops, opReq, this);
99100
if (!(opResponse instanceof Response)) throw new Error('Unexpected response, fn = ' + fn.name);
101+
if (debug) logger.log(fn.name, opResponse);
100102
status = opResponse.status;
101103
resarray.push(opResponse);
102104
} catch (err) {
@@ -106,7 +108,7 @@ export class Nfsv4CompoundProcCtx {
106108
resarray.push(err);
107109
break EXEC_OP;
108110
} else {
109-
this.connection.logger.error('Operation [' + fn.name + '] threw response with NFS4_OK');
111+
logger.error('Operation [' + fn.name + '] threw response with NFS4_OK');
110112
err = Nfsv4Stat.NFS4ERR_SERVERFAULT;
111113
}
112114
}
@@ -117,11 +119,11 @@ export class Nfsv4CompoundProcCtx {
117119
break FIND_STATUS_CODE;
118120
}
119121
status = Nfsv4Stat.NFS4ERR_SERVERFAULT;
120-
this.connection.logger.error('Invalid status [code = ' + err + ', fn = ' + fn.name + ']');
122+
logger.error('Invalid status [code = ' + err + ', fn = ' + fn.name + ']');
121123
break FIND_STATUS_CODE;
122124
}
123125
status = Nfsv4Stat.NFS4ERR_SERVERFAULT;
124-
this.connection.logger.error(fn.name, err);
126+
logger.error(fn.name, err);
125127
}
126128
const opResponse = new Response(status);
127129
resarray.push(opResponse);

src/nfs/v4/server/Nfsv4Connection.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,36 +109,38 @@ export class Nfsv4Connection {
109109
}
110110

111111
protected onRpcCallMessage(procedure: RpcCallMessage): void {
112-
const {debug, writer, rmEncoder} = this;
112+
const {debug, logger, writer, rmEncoder} = this;
113113
const {xid, proc} = procedure;
114114
switch (proc) {
115115
case Nfsv4Proc.COMPOUND: {
116+
if (debug) logger.log('COMPOUND', procedure);
116117
if (!(procedure.params instanceof Reader)) return;
117118
const compound = this.nfsDecoder.decodeCompoundRequest(procedure.params);
118119
if (compound instanceof msg.Nfsv4CompoundRequest) {
119120
new Nfsv4CompoundProcCtx(this, compound)
120121
.exec()
121122
.then((procResponse) => {
123+
if (debug) logger.log('COMPOUND', procResponse);
122124
this.nfsEncoder.writeAcceptedCompoundReply(xid, EMPTY_AUTH, procResponse);
123125
this.write(writer.flush());
124126
})
125127
.catch((err) => {
126-
this.logger.error('NFS COMPOUND error:', err);
128+
logger.error('NFS COMPOUND error:', err);
127129
this.nfsEncoder.writeRejectedReply(xid, Nfsv4Stat.NFS4ERR_SERVERFAULT);
128130
});
129131
} else this.closeWithError(RpcAcceptStat.GARBAGE_ARGS);
130132
break;
131133
}
132134
case Nfsv4Proc.NULL: {
133-
if (debug) this.logger.log('NULL procedure');
135+
if (debug) logger.log('NULL', procedure);
134136
const state = rmEncoder.startRecord();
135137
this.rpcEncoder.writeAcceptedReply(xid, EMPTY_AUTH, RpcAcceptStat.SUCCESS);
136138
rmEncoder.endRecord(state);
137139
this.write(writer.flush());
138140
break;
139141
}
140142
default: {
141-
if (this.debug) this.logger.error(`Unknown procedure: ${proc}`);
143+
if (debug) logger.error(`Unknown procedure: ${proc}`);
142144
}
143145
}
144146
}

0 commit comments

Comments
 (0)