Backing Storage for the File-backed Storage Gadget .

本文档详细介绍了如何配置和使用 File-backed Storage Gadget (FSG),使其通过 USB 接口模拟最多 8 个 SCSI 磁盘驱动器(称为逻辑单元或 LUN)。主要内容包括设置支持文件系统的 LUN 的步骤,创建并分区支持文件的方法,以及如何从设备读写数据。

The File-backed Storage Gadget (FSG) provides support for the USB Mass Storage class. It can appear to a host as a set of up to 8 SCSI disk drives (called Logical UNits or LUNs), although most of the time a single LUN is all you will need. The information stored for each LUN must be maintained by the gadget somewhere, either in a normal file or in a block device such as a disk partition or even a ramdisk. This file or block device is called the backing storage for the gadget, and you tell FSG where the backing storage is when you load the gadget driver:

bash# modprobe g_file_storage file=/root/data/backing_file
This command tells FSG to provide a single LUN with backing storage maintained in /root/data/backing_file. If you wanted to have two LUNs, where the second LUN used /dev/hda7 as its backing storage, you would do:
bash# modprobe g_file_storage file=/root/data/backing_file,/dev/hda7

Under Linux 2.6, if you add "removable=y" to the modprobe line then FSG will act like a device with removable media and allow you to specify the backing storage using sysfs attributes. In fact, if you do this then you can omit the "file=..." parameter entirely. The gadget will resemble a ZIP drive with no cartridge inserted until you use sysfs to specify some backing storage.

AN IMPORTANT WARNING! While FSG is running and the gadget is connected to a USB host, that USB host will use the backing storage as a private disk drive. It will not expect to see any changes in the backing storage other than the ones it makes. Extraneous changes are liable to corrupt the filesystem and may even crash the host. Only one system (normally, the USB host) may write to the backing storage, and if one system is writing that data, no other should be reading it. The only safe way to share the backing storage between the host and the gadget's operating system at the same time is to make it read-only on both sides.
Creating a backing storage file

Backing storage requires some preparation before FSG can use it. To start with, if the backing storage is a regular file then the file must be created beforehand, with its full desired size. (FSG won't create a backing storage file and won't change the size of an existing file.) In the example above, if you wanted /root/data/backing_file to represent a 64MB drive then you would have to create it using a command something like this:

bash# dd bs=1M count=64 if=/dev/zero of=/root/data/backing_file
64+0 records in
64+0 records out
This has to be done before you can load g_file_storage, but it only has to be done once. If the backing storage is a block device or disk partition such as /dev/hda7 then you don't have to create it beforehand, because it will already exist.

Partitioning the backing storage

However, creating the backing storage isn't enough. It's like having a raw disk drive; you still need to partition the disk and install a filesystem before you can use it. (Strictly speaking you don't need to partition it. You can treat the entire drive as a single large device, like a floppy disk. This will be confusing, though, and some versions of Windows won't work with an unpartitioned USB drive.) Okay, so how do you partition the backing storage?

Answer: You create a partition table by using the fdisk program. Here's an example showing how to do it. The example assumes you will want to use the gadget with a Windows host. It's a little tricky because fdisk needs help when working with something other than an actual device. Begin by starting up fdisk and telling it the name of your backing storage. You'll get a message something like this:

bash# fdisk /root/data/backing_file
Device contains neither a valid DOS partition table, nor Sun or SGI disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

You must set heads sectors and cylinders.
You can do this from the extra functions menu.

Command (m for help): 
Heads, Sectors, and Cylinders

As you see, fdisk says that it needs you to set the heads, sectors, and cylinders values. (Some versions only say they need you to set the number of cylinders, but they're wrong. You can tell by the way they'll miscalculate the size of the backing file; they're using default values and ignoring the actual file size.) The numbers you use are somewhat arbitrary; the scheme shown here works okay. Give the "x" (eXpert or eXtra) command:

Command (m for help): x
Then set the number of sectors/track. g_file_storage uses a sector size of 512 bytes, so 8 sectors/track will give us 4096 bytes per track. This is good because it matches the size of a memory page (on a 32-bit processor).
Expert command (m for help): s
Number of sectors (1-63): 8
Warning: setting sector offset for DOS compatiblity
Next set the number of heads (or tracks/cylinder). With 4 KB per track, 16 heads will give us a total of 64 KB per cylinder, which is convenient since the size of the backing file is 64 MB.
Expert command (m for help): h
Number of heads (1-256): 16
Finally set the number of cylinders. It's important that the total size you specify matches the actual size of the backing file. Since we've got 64 KB per cylinder and 64 MB total, we need to use 1024 cylinders.
Expert command (m for help): c
Number of cylinders (1-131071): 1024
Now return to the normal menu (the "r" command):
Expert command (m for help): r
Creating a primary partition
Create a new primary partition ("n" for new). Let's make it number 1. The defaults for the starting and ending cylinder are perfect because they will make the partition occupy the entire backing file, so just press Enter when asked for the First and Last cylinder:
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1024, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1024, default 1024): 
Using default value 1024
The new partition is created by default as a Linux partition. Since you want to use the gadget with a Windows host, you should change the partition type (the "t" command) to FAT32 (code "b"):
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (Win95 FAT32)
Print out ("p") the new partition table to be sure everything's correct:
Command (m for help): p

Disk /root/data/backing_file: 16 heads, 8 sectors, 1024 cylinders
Units = cylinders of 128 * 512 bytes

                  Device Boot    Start       End    Blocks   Id  System
/root/data/backing_file1             1      1024     65532    b  Win95 FAT32
Finally write out ("w") the partition table to the backing storage:
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Re-read table failed with error 25: Inappropriate ioctl for device.
Reboot your system to ensure the partition table is updated.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

Adding a filesystem

At this point a new partition has been created but it doesn't yet contain a filesystem. The easiest way to add a filesystem is to load g_file_storage, connect the gadget to a USB host, and use the host to do the work. With a Linux host you can run mkdosfs; with a Windows host you can double-click on the drive's icon in the "My Computer" window.

Accessing the backing storage from the gadget

It is possible to manipulate the data in the backing storage from the gadget (even to add the filesystem). Don't do this while the gadget is connected to a USB host! The key is to use the loop device driver with the "-o" (offset) option for the losetup program.

For this to work, you have to know what the partition's offset is. If you followed the partitioning scheme given above then the offset will always be 4096. If not, you can use fdisk to find the correct offset value:

# fdisk -lu /root/data/backing_file
You must set cylinders.
You can do this from the extra functions menu.

Disk data: 0 MB, 0 bytes
16 heads, 8 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes

                   Device Boot      Start         End      Blocks   Id  System
 /root/data/backing_file1               8        8191        4092    b  Win95 FAT32
Ignore the bogus data at the top and concentrate on the table at the bottom. The number you want is the value in the "Start" column. It gives the offset in sectors; to convert to bytes you must multiply by 512. So we see that the offset is 8 x 512 = 4096 bytes.

You use the losetup program to set up the loop device driver with the proper offset:
# losetup -o 4096 /dev/loop0 /root/data/backing_file
Now /dev/loop0 is mapped to the partition within the backing storage. You can create a filesystem on it:
# mkdosfs /dev/loop0
and then you can mount it:
# mount -t vfat /dev/loop0 /mnt/loop
Now you can transfer files back and forth to your heart's content! When you're done, be sure to unmount and detach the loop device:
# umount /dev/loop0
# losetup -d /dev/loop0
# influxd --help WARN[0000]log.go:228 gosnowflake.(*defaultLogger).Warn DBUS_SESSION_BUS_ADDRESS envvar looks to be not set, this can lead to runaway dbus-daemon processes. To avoid this, set envvar DBUS_SESSION_BUS_ADDRESS=$XDG_RUNTIME_DIR/bus (if it exists) or DBUS_SESSION_BUS_ADDRESS=/dev/null. Start up the daemon configured with flags/env vars/config file. The order of precedence for config options are as follows (1 highest, 3 lowest): 1. flags 2. env vars 3. config file A config file can be provided via the INFLUXD_CONFIG_PATH env var. If a file is not provided via an env var, influxd will look in the current directory for a config.{json|toml|yaml|yml} file. If one does not exist, then it will continue unchanged. Usage: influxd [flags] influxd [command] Available Commands: downgrade Downgrade metadata schema used by influxd to match the expectations of an older release help Help about any command inspect Commands for inspecting on-disk database data recovery Commands used to recover / regenerate operator access to the DB run Start the influxd server upgrade Upgrade a 1.x version of InfluxDB version Print the influxd server version Flags: --assets-path string override default assets by serving from a specific directory (developer mode) --bolt-path string path to boltdb database (default "/root/.influxdbv2/influxd.bolt") --e2e-testing add /debug/flush endpoint to clear stores; used for end-to-end tests --engine-path string path to persistent engine files (default "/root/.influxdbv2/engine") --feature-flags stringToString feature flag overrides (default []) --flux-log-enabled enables detailed logging for flux queries --hardening-enabled enable hardening options (disallow private IPs within flux and templates HTTP requests; disable file URLs in templates) -h, --help help for influxd --http-bind-address string bind address for the REST HTTP API (default ":8086") --http-idle-timeout duration max duration the server should keep established connections alive while waiting for new requests. Set to 0 for no timeout (default 3m0s) --http-read-header-timeout duration max duration the server should spend trying to read HTTP headers for new requests. Set to 0 for no timeout (default 10s) --http-read-timeout duration max duration the server should spend trying to read the entirety of new requests. Set to 0 for no timeout --http-write-timeout duration max duration the server should spend on processing+responding to requests. Set to 0 for no timeout --influxql-max-select-buckets int The maximum number of group by time bucket a SELECT can create. A value of zero will max the maximum number of buckets unlimited. --influxql-max-select-point int The maximum number of points a SELECT can process. A value of 0 will make the maximum point count unlimited. This will only be checked every second so queries will not be aborted immediately when hitting the limit. --influxql-max-select-series int The maximum number of series a SELECT can run. A value of 0 will make the maximum series count unlimited. --instance-id string add an instance id for replications to prevent collisions and allow querying by edge node --log-level Log-Level supported log levels are debug, info, and error (default info) --metrics-disabled Don't expose metrics over HTTP at /metrics --no-tasks disables the task scheduler --overwrite-pid-file overwrite PID file if it already exists instead of exiting --pid-file string write process ID to a file --pprof-disabled Don't expose debugging information over HTTP at /debug/pprof --query-concurrency int32 the number of queries that are allowed to execute concurrently. Set to 0 to allow an unlimited number of concurrent queries (default 1024) --query-initial-memory-bytes int the initial number of bytes allocated for a query when it is started. If this is unset, then query-memory-bytes will be used --query-max-memory-bytes int the maximum amount of memory used for queries. Can only be set when query-concurrency is limited. If this is unset, then this number is query-concurrency * query-memory-bytes --query-memory-bytes int maximum number of bytes a query is allowed to use at any given time. This must be greater or equal to query-initial-memory-bytes --query-queue-size int32 the number of queries that are allowed to be awaiting execution before new queries are rejected. Must be > 0 if query-concurrency is not unlimited (default 1024) --reporting-disabled disable sending telemetry data to https://telemetry.influxdata.com every 8 hours --secret-store string data store for secrets (bolt or vault) (default "bolt") --session-length int ttl in minutes for newly created sessions (default 60) --session-renew-disabled disables automatically extending session ttl on request --sqlite-path string path to sqlite database. if not set, sqlite database will be stored in the bolt-path directory as "influxd.sqlite". --storage-cache-max-memory-size Size The maximum size a shard's cache can reach before it starts rejecting writes. (default 1.0 GiB) --storage-cache-snapshot-memory-size Size The size at which the engine will snapshot the cache and write it to a TSM file, freeing up memory. (default 25 MiB) --storage-cache-snapshot-write-cold-duration Duration The length of time at which the engine will snapshot the cache and write it to a new TSM file if the shard hasn't received writes or deletes. (default 10m0s) --storage-compact-full-write-cold-duration Duration The duration at which the engine will compact all TSM files in a shard if it hasn't received a write or delete. (default 4h0m0s) --storage-compact-throughput-burst Size The rate limit in bytes per second that we will allow TSM compactions to write to disk. (default 48 MiB) --storage-max-concurrent-compactions int The maximum number of concurrent full and level compactions that can run at one time. A value of 0 results in 50% of runtime.GOMAXPROCS(0) used at runtime. Any number greater than 0 limits compactions to that value. This setting does not apply to cache snapshotting. --storage-max-index-log-file-size Size The threshold, in bytes, when an index write-ahead log file will compact into an index file. Lower sizes will cause log files to be compacted more quickly and result in lower heap usage at the expense of write throughput. (default 1.0 MiB) --storage-no-validate-field-size Skip field-size validation on incoming writes. --storage-retention-check-interval Duration The interval of time when retention policy enforcement checks run. (default 30m0s) --storage-series-file-max-concurrent-snapshot-compactions int The maximum number of concurrent snapshot compactions that can be running at one time across all series partitions in a database. --storage-series-id-set-cache-size int The size of the internal cache used in the TSI index to store previously calculated series results. --storage-shard-precreator-advance-period Duration The default period ahead of the endtime of a shard group that its successor group is created. (default 30m0s) --storage-shard-precreator-check-interval Duration The interval of time when the check to pre-create new shards runs. (default 10m0s) --storage-tsm-use-madv-willneed Controls whether we hint to the kernel that we intend to page in mmap'd sections of TSM files. --storage-validate-keys Validates incoming writes to ensure keys only have valid unicode characters. --storage-wal-flush-on-shutdown Flushes and clears the WAL on shutdown --storage-wal-fsync-delay Duration The amount of time that a write will wait before fsyncing. A duration greater than 0 can be used to batch up multiple fsync calls. This is useful for slower disks or when WAL write contention is seen. (default 0s) --storage-wal-max-concurrent-writes int The max number of writes that will attempt to write to the WAL at a time. (default <nprocs> * 2) --storage-wal-max-write-delay storage-wal-max-concurrent-writes The max amount of time a write will wait when the WAL already has storage-wal-max-concurrent-writes active writes. Set to 0 to disable the timeout. (default 10m0s) --storage-write-timeout duration The max amount of time the engine will spend completing a write request before cancelling with a timeout. (default 10s) --store string backing store for REST resources (disk or memory) (default "disk") --strong-passwords enable password strength enforcement --template-file-urls-disabled disable template file URLs --testing-always-allow-setup ensures the /api/v2/setup endpoint always returns true to allow onboarding --tls-cert string TLS certificate for HTTPs --tls-key string TLS key for HTTPs --tls-min-version string Minimum accepted TLS version (default "1.2") --tls-strict-ciphers Restrict accept ciphers to: ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, ECDHE_RSA_WITH_AES_128_GCM_SHA256, ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, ECDHE_RSA_WITH_AES_256_GCM_SHA384, ECDHE_ECDSA_WITH_CHACHA20_POLY1305, ECDHE_RSA_WITH_CHACHA20_POLY1305 --tracing-type string supported tracing types are log, jaeger --ui-disabled Disable the InfluxDB UI --vault-addr string address of the Vault server expressed as a URL and port, for example: https://127.0.0.1:8200/. --vault-cacert string path to a PEM-encoded CA certificate file on the local disk. This file is used to verify the Vault server's SSL certificate. This environment variable takes precedence over VAULT_CAPATH. --vault-capath string path to a directory of PEM-encoded CA certificate files on the local disk. These certificates are used to verify the Vault server's SSL certificate. --vault-client-cert string path to a PEM-encoded client certificate on the local disk. This file is used for TLS communication with the Vault server. --vault-client-key string path to an unencrypted, PEM-encoded private key on disk which corresponds to the matching client certificate. --vault-client-timeout duration timeout variable. The default value is 60s. --vault-max-retries int maximum number of retries when a 5xx error code is encountered. The default is 2, for three total attempts. Set this to 0 or less to disable retrying. --vault-skip-verify do not verify Vault's presented certificate before communicating with it. Setting this variable is not recommended and voids Vault's security model. --vault-tls-server-name string name to use as the SNI host when connecting via TLS. --vault-token string vault authentication token Use "influxd [command] --help" for more information about a command. 翻译并解析
最新发布
11-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值