// GetBlockIOData gets cgroup blockio data
766127
func (cg *CgroupV1) GetBlockIOData(pid int, cgPath string) (*rspec.LinuxBlockIO, error) {
	if filepath.IsAbs(cgPath) {
		path := filepath.Join(cg.MountPath, "blkio", cgPath)
		if _, err := os.Stat(path); err != nil {
			if os.IsNotExist(err) {
				return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("In the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
			}
			return nil, err
		}
	}
	lb := &rspec.LinuxBlockIO{}
	names := []string{"weight", "leaf_weight", "weight_device", "leaf_weight_device", "throttle.read_bps_device", "throttle.write_bps_device", "throttle.read_iops_device", "throttle.write_iops_device"}
	for i, name := range names {
		fileName := strings.Join([]string{"blkio", name}, ".")
		filePath := filepath.Join(cg.MountPath, "blkio", cgPath, fileName)
		if !filepath.IsAbs(cgPath) {
			subPath, err := GetSubsystemPath(pid, "blkio")
			if err != nil {
				return nil, err
			}
			if !strings.Contains(subPath, cgPath) {
				return nil, fmt.Errorf("cgroup subsystem %s is not mounted as expected", "blkio")
			}
			filePath = filepath.Join(cg.MountPath, "blkio", subPath, fileName)
		}
		contents, err := ioutil.ReadFile(filePath)
		if err != nil {
			if os.IsNotExist(err) {
				return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("The runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
			}

			return nil, err
		}
		switch i {
		case 0:
			res, err := strconv.ParseUint(strings.TrimSpace(string(contents)), 10, 16)
			if err != nil {
				return nil, err
			}
			weight := uint16(res)
			lb.Weight = &weight
		case 1:
			res, err := strconv.ParseUint(strings.TrimSpace(string(contents)), 10, 16)
			if err != nil {
				return nil, err
			}
			leafWeight := uint16(res)
			lb.LeafWeight = &leafWeight
		case 2:
			parts := strings.Split(strings.TrimSpace(string(contents)), "\n")
			for _, part := range parts {
				elem := strings.Split(part, " ")
				major, minor, err := getDeviceID(elem[0])
				if err != nil {
					return nil, err
				}
				res, err := strconv.ParseUint(elem[1], 10, 16)
				if err != nil {
					return nil, err
				}
				weight := uint16(res)
				lwd := rspec.LinuxWeightDevice{}
				lwd.Major = major
				lwd.Minor = minor
				lwd.Weight = &weight
				lb.WeightDevice = append(lb.WeightDevice, lwd)
			}
		case 3:
			parts := strings.Split(strings.TrimSpace(string(contents)), "\n")
			for _, part := range parts {
				elem := strings.Split(part, " ")
				major, minor, err := getDeviceID(elem[0])
				if err != nil {
					return nil, err
				}
				res, err := strconv.ParseUint(elem[1], 10, 16)
				if err != nil {
					return nil, err
				}
				leafWeight := uint16(res)
				exist := false
				for i, wd := range lb.WeightDevice {
					if wd.Major == major && wd.Minor == minor {
						exist = true
						lb.WeightDevice[i].LeafWeight = &leafWeight
						break
					}
				}
				if !exist {
					lwd := rspec.LinuxWeightDevice{}
					lwd.Major = major
					lwd.Minor = minor
					lwd.LeafWeight = &leafWeight
					lb.WeightDevice = append(lb.WeightDevice, lwd)
				}
			}
		case 4:
			parts := strings.Split(strings.TrimSpace(string(contents)), "\n")
			for _, part := range parts {
				elem := strings.Split(part, " ")
				major, minor, err := getDeviceID(elem[0])
				if err != nil {
					return nil, err
				}
				rate, err := strconv.ParseUint(elem[1], 10, 64)
				if err != nil {
					return nil, err
				}
				ltd := rspec.LinuxThrottleDevice{}
				ltd.Major = major
				ltd.Minor = minor
				ltd.Rate = rate
				lb.ThrottleReadBpsDevice = append(lb.ThrottleReadBpsDevice, ltd)
			}
		case 5:
			parts := strings.Split(strings.TrimSpace(string(contents)), "\n")
			for _, part := range parts {
				elem := strings.Split(part, " ")
				major, minor, err := getDeviceID(elem[0])
				if err != nil {
					return nil, err
				}
				rate, err := strconv.ParseUint(elem[1], 10, 64)
				if err != nil {
					return nil, err
				}
				ltd := rspec.LinuxThrottleDevice{}
				ltd.Major = major
				ltd.Minor = minor
				ltd.Rate = rate
				lb.ThrottleWriteBpsDevice = append(lb.ThrottleWriteBpsDevice, ltd)
			}
		case 6:
			parts := strings.Split(strings.TrimSpace(string(contents)), "\n")
			for _, part := range parts {
				elem := strings.Split(part, " ")
				major, minor, err := getDeviceID(elem[0])
				if err != nil {
					return nil, err
				}
				rate, err := strconv.ParseUint(elem[1], 10, 64)
				if err != nil {
					return nil, err
				}
				ltd := rspec.LinuxThrottleDevice{}
				ltd.Major = major
				ltd.Minor = minor
				ltd.Rate = rate
				lb.ThrottleReadIOPSDevice = append(lb.ThrottleReadIOPSDevice, ltd)
			}
		case 7:
			parts := strings.Split(strings.TrimSpace(string(contents)), "\n")
			for _, part := range parts {
				elem := strings.Split(part, " ")
				major, minor, err := getDeviceID(elem[0])
				if err != nil {
					return nil, err
				}
				rate, err := strconv.ParseUint(elem[1], 10, 64)
				if err != nil {
					return nil, err
				}
				ltd := rspec.LinuxThrottleDevice{}
				ltd.Major = major
				ltd.Minor = minor
				ltd.Rate = rate
				lb.ThrottleWriteIOPSDevice = append(lb.ThrottleWriteIOPSDevice, ltd)
			}
		}
	}

	return lb, nil
}
1149641
func (s *SwarmChunkServer) GetData(ctx context.Context, key []byte) ([]byte, error) {
	chunk, err := s.chunkStore.Get(ctx, storage.Address(key))
	if err != nil {
		return nil, err
	}
	return chunk.Data(), nil
}
487234
func (u *FakeVolumeUtil) GetBlockCapacityByte(fullPath string) (int64, error) {
	return u.getDirEntryCapacity(fullPath, FakeEntryBlock)
}
997830
func (h *Handler) handleGetFragmentBlockData(w http.ResponseWriter, r *http.Request) {
	buf, err := h.api.FragmentBlockData(r.Context(), r.Body)
	if err != nil {
		if _, ok := err.(pilosa.BadRequestError); ok {
			http.Error(w, err.Error(), http.StatusBadRequest)
		} else if errors.Cause(err) == pilosa.ErrFragmentNotFound {
			http.Error(w, err.Error(), http.StatusNotFound)
		} else {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
		return
	}

	// Write response.
	w.Header().Set("Content-Type", "application/protobuf")
	w.Header().Set("Content-Length", strconv.Itoa(len(buf)))
	_, err = w.Write(buf)
	if err != nil {
		h.logger.Printf("writing fragment/block/data response: %v", err)
	}
}
1088610
func (qs *queryServer) GetBlockHeader(ctx context.Context, param *GetBlockParam) (*types.Header, error) {
	header, err := qs.blockchain.GetBlockHeader(param.Height)
	if err != nil {
		return nil, err
	}
	abciHeader := tmtypes.TM2PB.Header(header)
	return &abciHeader, nil
}
49809
func GetData(err error, key DataKey) interface{} {
	cast, ok := err.(*Error)
	if ok {
		return cast.GetData(key)
	}
	return nil
}
866296
func (st *State) GetBlockForType(t BlockType) (Block, bool, error) {
	return getBlockForType(st, t)
}
171551
func (r Virtual_Guest_Block_Device_Template_Group) GetBlockDevices() (resp []datatypes.Virtual_Guest_Block_Device_Template, err error) {
	err = r.Session.DoRequest("SoftLayer_Virtual_Guest_Block_Device_Template_Group", "getBlockDevices", nil, &r.Options, &resp)
	return
}
869086
func ReadBlockMetadata(blockMetadata *common.Metadata, configMetadata *etcdraft.ConfigMetadata) (*etcdraft.BlockMetadata, error) {
	if blockMetadata != nil && len(blockMetadata.Value) != 0 { // we have consenters mapping from block
		m := &etcdraft.BlockMetadata{}
		if err := proto.Unmarshal(blockMetadata.Value, m); err != nil {
			return nil, errors.Wrap(err, "failed to unmarshal block's metadata")
		}
		return m, nil
	}

	m := &etcdraft.BlockMetadata{
		NextConsenterId: 1,
		ConsenterIds:    make([]uint64, len(configMetadata.Consenters)),
	}
	// need to read consenters from the configuration
	for i := range m.ConsenterIds {
		m.ConsenterIds[i] = m.NextConsenterId
		m.NextConsenterId++
	}

	return m, nil
}
1235859
func NewBlockData(height uint64) *BlockData {
	data := types.EventData{
		Tables:      make(map[string]types.EventDataTable),
		BlockHeight: height,
	}

	return &BlockData{
		Data: data,
	}
}
935576
func (p *BlockPrefetchClient) GetBlockData(hash *chainhash.Hash) (*wire.MsgBlock, *dcrjson.GetBlockHeaderVerboseResult, error) {
	p.Lock()

	retargetAndUnlock := func(nextHash string) {
		p.retarget(nextHash)
		p.Unlock()
	}

	// If the block is already fetched, and the current block, return it. Do not
	// retarget.
	if p.current.hash == *hash /*p.haveBlockHash(*hash)*/ {
		p.hits++
		// Return the requested block.
		defer p.Unlock()
		return p.current.msgBlock, p.current.headerResult, nil
	}

	// If the block is already fetched, and next, return it and retarget with a
	// new range starting at this block's height.
	if p.next.hash == *hash /*p.haveBlockHash(*hash)*/ {
		// Grab the result before retarget() changes p.next (via fetcher ->
		// RetrieveAndStoreNext -> storeNext).
		msgBlock, headerResult := p.next.msgBlock, p.next.headerResult
		go retargetAndUnlock(p.next.headerResult.NextHash)
		p.hits++
		// Return the requested block.
		return msgBlock, headerResult, nil
	}

	p.misses++

	// Immediately retrieve msgBlock and header verbose result while fetcher is
	// blocked by the Mutex.
	msgBlock, headerResult, _, err := p.retrieveBlockAndHeaderResult(hash)
	if err != nil {
		p.Unlock()
		return nil, nil, err
	}

	// Leaving the mutex locked, fire off a goroutine to retarget to the next
	// block. The fetcher goroutine and other locking methods will stay blocked
	// until the mutex unlocks, but the msgBlock can be returned right away.
	go retargetAndUnlock(headerResult.NextHash)

	return msgBlock, headerResult, err
}
1043954
func (s *state) getData() *KVState {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	d := &KVState{}
	*d = s.data
	return d
}
165243
func getBlockAPI(c newAPIRoot) (*apiblock.Client, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, err
	}
	return apiblock.NewClient(root), nil
}
360995
func (bt *blockTree) getBlockAtOffset(ctx context.Context,
	topBlock BlockWithPtrs, off Offset, rtype BlockReqType) (
	ptr BlockPointer, parentBlocks []ParentBlockAndChildIndex,
	block BlockWithPtrs, nextBlockStartOff, startOff Offset,
	wasDirty bool, err error) {
	// Find the block matching the offset, if it exists.
	ptr = bt.rootBlockPointer()
	block = topBlock
	nextBlockStartOff = nil
	startOff = topBlock.FirstOffset()

	if !topBlock.IsIndirect() {
		// If it's not an indirect block, we just need to figure out
		// if it's dirty.
		_, wasDirty, err = bt.getter(ctx, bt.kmd, ptr, bt.file, rtype)
		if err != nil {
			return ZeroPtr, nil, nil, nil, nil, false, err
		}
		return ptr, nil, block, nextBlockStartOff, startOff, wasDirty, nil
	}

	// Search until it's not an indirect block.
	for block.IsIndirect() {
		nextIndex := block.NumIndirectPtrs() - 1
		for i := 0; i < block.NumIndirectPtrs(); i++ {
			_, iptrOff := block.IndirectPtr(i)
			if iptrOff.Equals(off) {
				// Small optimization to avoid iterating past the correct ptr.
				nextIndex = i
				break
			} else if off.Less(iptrOff) {
				// Use the previous block.  i can never be 0, because
				// the first ptr always has an offset at the beginning
				// of the range.
				nextIndex = i - 1
				break
			}
		}
		var info BlockInfo
		info, startOff = block.IndirectPtr(nextIndex)
		parentBlocks = append(parentBlocks,
			ParentBlockAndChildIndex{block, nextIndex})
		// There is more to read if we ever took a path through a
		// ptr that wasn't the final ptr in its respective list.
		if nextIndex != block.NumIndirectPtrs()-1 {
			_, nextBlockStartOff = block.IndirectPtr(nextIndex + 1)
		}
		ptr = info.BlockPointer
		block, wasDirty, err = bt.getter(
			ctx, bt.kmd, info.BlockPointer, bt.file, rtype)
		if err != nil {
			return ZeroPtr, nil, nil, nil, nil, false, err
		}
	}

	return ptr, parentBlocks, block, nextBlockStartOff, startOff, wasDirty, nil
}
732165
func GetBlocky() (bool, error) {
	if initVersionError != nil {
		return false, initVersionError
	}
	if initContextError != nil {
		return false, initContextError
	}
	return defaultCtx.GetBlocky()
}
993279
func (b *Block) expandBlockdata() ([]byte, error) {
	switch b.method {
	default:
		panic(fmt.Sprintf("cram: unknown method: %v", b.method))
	case rawMethod:
		return b.blockData, nil
	case gzipMethod:
		gz, err := gzip.NewReader(bytes.NewReader(b.blockData))
		if err != nil {
			return nil, err
		}
		return ioutil.ReadAll(gz)
	case bzip2Method:
		return ioutil.ReadAll(bzip2.NewReader(bytes.NewReader(b.blockData)))
	case lzmaMethod:
		lz, err := lzma.NewReader(bytes.NewReader(b.blockData))
		if err != nil {
			return nil, err
		}
		return ioutil.ReadAll(lz)
	case ransMethod:
		// Unimplemented.
		// BUG(kortschak): The rANS method is not implemented.
		// Data blocks compressed with rANS will be returned
		// compressed and an "unimplemented" error will be
		// returned.
		return b.blockData, errors.New("unimplemented")
	}
}
1167228
func (api *API) FragmentBlockData(ctx context.Context, body io.Reader) ([]byte, error) {
	span, _ := tracing.StartSpanFromContext(ctx, "API.FragmentBlockData")
	defer span.Finish()

	if err := api.validate(apiFragmentBlockData); err != nil {
		return nil, errors.Wrap(err, "validating api method")
	}

	reqBytes, err := ioutil.ReadAll(body)
	if err != nil {
		return nil, NewBadRequestError(errors.Wrap(err, "read body error"))
	}
	var req BlockDataRequest
	if err := api.Serializer.Unmarshal(reqBytes, &req); err != nil {
		return nil, NewBadRequestError(errors.Wrap(err, "unmarshal body error"))
	}

	// Retrieve fragment from holder.
	f := api.holder.fragment(req.Index, req.Field, req.View, req.Shard)
	if f == nil {
		return nil, ErrFragmentNotFound
	}

	var resp = BlockDataResponse{}
	resp.RowIDs, resp.ColumnIDs = f.blockData(int(req.Block))

	// Encode response.
	buf, err := api.Serializer.Marshal(&resp)
	if err != nil {
		return nil, errors.Wrap(err, "merge block response encoding error")
	}

	return buf, nil
}