don't use pool to allocate buffers

This commit is contained in:
chessman
2019-06-28 17:55:51 +03:00
parent d90dab2b1d
commit 791e74fea5
3 changed files with 5 additions and 41 deletions

View File

@@ -27,7 +27,6 @@ import (
"github.com/gostor/gotgt/pkg/config"
"github.com/gostor/gotgt/pkg/scsi"
"github.com/gostor/gotgt/pkg/util"
"github.com/gostor/gotgt/pkg/util/pool"
log "github.com/sirupsen/logrus"
)
@@ -258,7 +257,7 @@ func (s *ISCSITargetDriver) rxHandler(conn *iscsiConnection) {
return
}
dl := ((cmd.DataLen + DataPadding - 1) / DataPadding) * DataPadding
cmd.RawData = pool.NewBuffer(dl)
cmd.RawData = make([]byte, int(dl))
length := 0
for length < dl {
l, err := conn.readData(cmd.RawData[length:])
@@ -583,7 +582,7 @@ func (s *ISCSITargetDriver) scsiCommandHandler(conn *iscsiConnection) (err error
}
scmd.OutSDBBuffer = &api.SCSIDataBuffer{
Length: uint32(blen),
Buffer: pool.NewBuffer(blen),
Buffer: make([]byte, blen),
}
}
log.Debugf("SCSI write, R2T count: %d, unsol Count: %d, offset: %d", task.r2tCount, task.unsolCount, task.offset)
@@ -611,7 +610,7 @@ func (s *ISCSITargetDriver) scsiCommandHandler(conn *iscsiConnection) (err error
} else if scmd.InSDBBuffer == nil {
scmd.InSDBBuffer = &api.SCSIDataBuffer{
Length: uint32(req.ExpectedDataLen),
Buffer: pool.NewBuffer(int(req.ExpectedDataLen)),
Buffer: make([]byte, int(req.ExpectedDataLen)),
}
}
task.offset = 0

View File

@@ -23,7 +23,6 @@ import (
"github.com/gostor/gotgt/pkg/api"
"github.com/gostor/gotgt/pkg/util"
"github.com/gostor/gotgt/pkg/util/pool"
log "github.com/sirupsen/logrus"
)
@@ -110,7 +109,7 @@ func bsPerformCommand(bs api.BackingStore, cmd *api.SCSICommand) (err error, key
// TODO
break
case api.READ_6, api.READ_10, api.READ_12, api.READ_16:
rbuf = pool.NewBuffer(int(tl))
rbuf = make([]byte, int(tl))
rbuf, err = bs.Read(int64(offset), tl)
if err != nil && err != io.EOF {
key = MEDIUM_ERROR
@@ -179,7 +178,7 @@ write:
}
verify:
if doVerify {
rbuf = pool.NewBuffer(int(tl))
rbuf = make([]byte, int(tl))
rbuf, err = bs.Read(int64(offset), tl)
if err != nil {
key = MEDIUM_ERROR

View File

@@ -1,34 +0,0 @@
/*
Copyright 2017 The GoStor Authors All rights reserved.
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.
*/
// Package pool provides memory pool for buffer.
package pool
import "sync"
var bytePool sync.Pool = sync.Pool{}
func NewBuffer(size int) []byte {
bytePool.New = func() interface{} {
return make([]byte, size)
}
return bytePool.Get().([]byte)
}
func ReleaseBuffer(b []byte) {
bytePool.Put(b)
}