<commit_before>package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
	"syscall"
	"time"

	"github.com/gorilla/websocket"

	"github.com/lxc/lxd/shared"
	"github.com/lxc/lxd/shared/api"

	"github.com/pborman/uuid"
	log "gopkg.in/inconshreveable/log15.v2"
)

type storageZfs struct {
	dataset string
	storageShared
}

func (s *storageZfs) zfsIsEnabled() bool {
	out, err := exec.LookPath("zfs")
	if err != nil || len(out) == 0 {
		return false
	}

	return true
}

func (s *storageZfs) zfsModuleVersionGet() (string, error) {
	zfsVersion, err := ioutil.ReadFile("/sys/module/zfs/version")
	if err != nil {
		return "", fmt.Errorf("Could not determine ZFS module version.")
	}

	return strings.TrimSpace(string(zfsVersion)), nil
}

// Only initialize the minimal information we need about a given storage type.
func (s *storageZfs) StorageCoreInit() (*storageCore, error) {
	sCore := storageCore{}
	sCore.sType = storageTypeZfs
	typeName, err := storageTypeToString(sCore.sType)
	if err != nil {
		return nil, err
	}
	sCore.sTypeName = typeName

	if !s.zfsIsEnabled() {
		return nil, fmt.Errorf("The \"zfs\" tool is not enabled.")
	}

	sCore.sTypeVersion, err = s.zfsModuleVersionGet()
	if err != nil {
		return nil, err
	}

	err = sCore.initShared()
	if err != nil {
		return nil, err
	}

	s.storageCore = sCore

	return &sCore, nil
}

// Functions dealing with storage pools.
func (s *storageZfs) StoragePoolInit(config map[string]interface{}) (storage, error) {
	_, err := s.StorageCoreInit()
	if err != nil {
		return s, err
	}

	if s.pool.Name == "" {
		if config["zfsPool"] == nil {
			zfsPool := daemonConfig["storage.zfs_pool_name"].Get()
			if zfsPool == "" {
				return s, fmt.Errorf("ZFS isn't enabled")
			}

			s.pool.Name = zfsPool
		} else {
			s.pool.Name = config["zfsPool"].(string)
		}
	}

	vdev := s.pool.Config["source"]
	if vdev != "" {
		if !filepath.IsAbs(vdev) {
			s.dataset = vdev
		}
	}

	return s, nil
}

func (s *storageZfs) StoragePoolCheck() error {
	poolName := s.pool.Name
	if s.dataset != "" {
		poolName = s.dataset
	}

	err := s.zfsPoolCheck(poolName)
	if err != nil {
		source := s.pool.Config["source"]
		if filepath.IsAbs(source) && shared.PathExists(source) {
			_ = loadModule("zfs")

			output, err := exec.Command("zpool", "import", source, poolName).CombinedOutput()
			if err != nil {
				return fmt.Errorf("Unable to import the ZFS pool: %s", output)
			}
		} else {
			return err
		}
	}<commit_msg>storage: remove obsolete zfs check<commit_after>package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
	"syscall"
	"time"

	"github.com/gorilla/websocket"

	"github.com/lxc/lxd/shared"
	"github.com/lxc/lxd/shared/api"

	"github.com/pborman/uuid"
	log "gopkg.in/inconshreveable/log15.v2"
)

type storageZfs struct {
	dataset string
	storageShared
}

func (s *storageZfs) zfsIsEnabled() bool {
	out, err := exec.LookPath("zfs")
	if err != nil || len(out) == 0 {
		return false
	}

	return true
}

func (s *storageZfs) zfsModuleVersionGet() (string, error) {
	zfsVersion, err := ioutil.ReadFile("/sys/module/zfs/version")
	if err != nil {
		return "", fmt.Errorf("Could not determine ZFS module version.")
	}

	return strings.TrimSpace(string(zfsVersion)), nil
}

// Only initialize the minimal information we need about a given storage type.
func (s *storageZfs) StorageCoreInit() (*storageCore, error) {
	sCore := storageCore{}
	sCore.sType = storageTypeZfs
	typeName, err := storageTypeToString(sCore.sType)
	if err != nil {
		return nil, err
	}
	sCore.sTypeName = typeName

	if !s.zfsIsEnabled() {
		return nil, fmt.Errorf("The \"zfs\" tool is not enabled.")
	}

	sCore.sTypeVersion, err = s.zfsModuleVersionGet()
	if err != nil {
		return nil, err
	}

	err = sCore.initShared()
	if err != nil {
		return nil, err
	}

	s.storageCore = sCore

	return &sCore, nil
}

// Functions dealing with storage pools.
func (s *storageZfs) StoragePoolInit(config map[string]interface{}) (storage, error) {
	_, err := s.StorageCoreInit()
	if err != nil {
		return s, err
	}

	// Detect whether we have been given a zfs dataset as source.
	vdev := s.pool.Config["source"]
	if vdev != "" {
		if !filepath.IsAbs(vdev) {
			s.log.Debug(fmt.Sprintf("Treating the source \"%s\" of this storage pool as a ZFS dataset.", vdev))
			s.dataset = vdev
		}
	}

	return s, nil
}

func (s *storageZfs) StoragePoolCheck() error {
	poolName := s.pool.Name
	if s.dataset != "" {
		poolName = s.dataset
	}

	err := s.zfsPoolCheck(poolName)
	if err != nil {
		source := s.pool.Config["source"]
		if filepath.IsAbs(source) && shared.PathExists(source) {
			_ = loadModule("zfs")

			output, err := exec.Command("zpool", "import", source, poolName).CombinedOutput()
			if err != nil {
				return fmt.Errorf("Unable to import the ZFS pool: %s", output)
			}
		} else {
			return err
		}
	}
{'fraction_non_alphanumeric': 0.15035750766087844, 'fraction_numerical': 0.001634320735444331, 'mean_word_length': 3.6145146088595665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5130078', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1828, 'n_words': 453}