├── NOTICE ├── offsets_32bit.go ├── offsets.go ├── offsets_32bit_pad.go ├── cmd └── tcmufile │ └── tcmufile.go ├── DCO ├── map └── test.c ├── CONTRIBUTING.md ├── code-of-conduct.md ├── poll.go ├── README.md ├── struct_access.go ├── scsi └── scsi_defs.go ├── device.go ├── cmd_handler.go ├── scsi_handler.go └── LICENSE /NOTICE: -------------------------------------------------------------------------------- 1 | CoreOS Project 2 | Copyright 2015 CoreOS, Inc 3 | 4 | This product includes software developed at CoreOS, Inc. 5 | (http://www.coreos.com/). 6 | -------------------------------------------------------------------------------- /offsets_32bit.go: -------------------------------------------------------------------------------- 1 | // +build 386 2 | 3 | package tcmu 4 | 5 | // This file works for the build tags above. To port to other architectures, 6 | // check the offsets from C using the included test.c. 7 | // Go should handle the endianness. 8 | 9 | const ( 10 | offLenOp = 0 11 | offCmdId = 4 12 | offKFlags = 6 13 | offUFlags = 7 14 | entReqRespOff = 8 15 | offReqIovCnt = entReqRespOff + 0 16 | offReqIovBidiCnt = entReqRespOff + 4 17 | offReqIovDifCnt = entReqRespOff + 8 18 | offReqCdbOff = entReqRespOff + 12 19 | 20 | iovSize = 8 21 | offReqIov0Base = entReqRespOff + 36 22 | offReqIov0Len = entReqRespOff + 40 23 | 24 | offRespSCSIStatus = entReqRespOff + 0 25 | offRespSense = entReqRespOff + 8 26 | ) 27 | -------------------------------------------------------------------------------- /offsets.go: -------------------------------------------------------------------------------- 1 | // +build arm64 amd64 2 | 3 | package tcmu 4 | 5 | // This file works for the build tags above. To port to other architectures, 6 | // check the offsets from C using the included test.c. 7 | // Go should handle the endianness . 8 | 9 | const ( 10 | offLenOp = 0 11 | offCmdId = 4 12 | offKFlags = 6 13 | offUFlags = 7 14 | entReqRespOff = 8 15 | offReqIovCnt = entReqRespOff + 0 16 | offReqIovBidiCnt = entReqRespOff + 4 17 | offReqIovDifCnt = entReqRespOff + 8 18 | offReqCdbOff = entReqRespOff + 16 19 | 20 | iovSize = 16 21 | offReqIov0Base = entReqRespOff + 40 22 | offReqIov0Len = entReqRespOff + 48 23 | 24 | offRespSCSIStatus = entReqRespOff + 0 25 | offRespSense = entReqRespOff + 8 26 | ) 27 | -------------------------------------------------------------------------------- /offsets_32bit_pad.go: -------------------------------------------------------------------------------- 1 | // +build arm 2 | 3 | package tcmu 4 | 5 | // This file works for the build tags above. To port to other architectures, 6 | // check the offsets from C using the included test.c. 7 | // Go should handle the endianness . 8 | 9 | const ( 10 | offLenOp = 0 11 | offCmdId = 4 12 | offKFlags = 6 13 | offUFlags = 7 14 | entReqRespOff = 8 15 | offReqIovCnt = entReqRespOff + 0 16 | offReqIovBidiCnt = entReqRespOff + 4 17 | offReqIovDifCnt = entReqRespOff + 8 18 | offReqCdbOff = entReqRespOff + 16 19 | 20 | iovSize = 8 21 | offReqIov0Base = entReqRespOff + 40 22 | offReqIov0Len = entReqRespOff + 44 23 | 24 | offRespSCSIStatus = entReqRespOff + 0 25 | offRespSense = entReqRespOff + 8 26 | ) 27 | -------------------------------------------------------------------------------- /cmd/tcmufile/tcmufile.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/signal" 7 | 8 | "github.com/coreos/go-tcmu" 9 | "github.com/sirupsen/logrus" 10 | ) 11 | 12 | func main() { 13 | logrus.SetLevel(logrus.DebugLevel) 14 | if len(os.Args) != 2 { 15 | die("not enough arguments") 16 | } 17 | filename := os.Args[1] 18 | f, err := os.OpenFile(filename, os.O_RDWR, 0700) 19 | if err != nil { 20 | die("couldn't open: %v", err) 21 | } 22 | defer f.Close() 23 | fi, _ := f.Stat() 24 | handler := tcmu.BasicSCSIHandler(f) 25 | handler.VolumeName = fi.Name() 26 | handler.DataSizes.VolumeSize = fi.Size() 27 | d, err := tcmu.OpenTCMUDevice("/dev/tcmufile", handler) 28 | if err != nil { 29 | die("couldn't tcmu: %v", err) 30 | } 31 | defer d.Close() 32 | fmt.Printf("go-tcmu attached to %s/%s\n", "/dev/tcmufile", fi.Name()) 33 | 34 | mainClose := make(chan bool) 35 | signalChan := make(chan os.Signal, 1) 36 | signal.Notify(signalChan, os.Interrupt) 37 | 38 | go func() { 39 | for _ = range signalChan { 40 | fmt.Println("\nReceived an interrupt, stopping services...") 41 | close(mainClose) 42 | } 43 | }() 44 | <-mainClose 45 | } 46 | 47 | func die(why string, args ...interface{}) { 48 | fmt.Fprintf(os.Stderr, why+"\n", args...) 49 | os.Exit(1) 50 | } 51 | -------------------------------------------------------------------------------- /DCO: -------------------------------------------------------------------------------- 1 | Developer Certificate of Origin 2 | Version 1.1 3 | 4 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 5 | 660 York Street, Suite 102, 6 | San Francisco, CA 94110 USA 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this 9 | license document, but changing it is not allowed. 10 | 11 | 12 | Developer's Certificate of Origin 1.1 13 | 14 | By making a contribution to this project, I certify that: 15 | 16 | (a) The contribution was created in whole or in part by me and I 17 | have the right to submit it under the open source license 18 | indicated in the file; or 19 | 20 | (b) The contribution is based upon previous work that, to the best 21 | of my knowledge, is covered under an appropriate open source 22 | license and I have the right under that license to submit that 23 | work with modifications, whether created in whole or in part 24 | by me, under the same open source license (unless I am 25 | permitted to submit under a different license), as indicated 26 | in the file; or 27 | 28 | (c) The contribution was provided directly to me by some other 29 | person who certified (a), (b) or (c) and I have not modified 30 | it. 31 | 32 | (d) I understand and agree that this project and the contribution 33 | are public and that a record of the contribution (including all 34 | personal information I submit with it, including my sign-off) is 35 | maintained indefinitely and may be redistributed consistent with 36 | this project or the open source license(s) involved. 37 | -------------------------------------------------------------------------------- /map/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) { 9 | char buf[128]; 10 | memset(buf, 0x0, 128); 11 | struct tcmu_cmd_entry* cmd = (struct tcmu_cmd_entry*)buf; 12 | printf("%d\n", sizeof(struct tcmu_cmd_entry)); 13 | cmd->hdr.len_op = 0x1; 14 | cmd->hdr.cmd_id = 0x2; 15 | cmd->hdr.kflags = 0x3; 16 | cmd->hdr.uflags = 0x4; 17 | cmd->req.iov_cnt = 0x5; 18 | cmd->req.iov_bidi_cnt = 0x6; 19 | cmd->req.iov_dif_cnt = 0x7; 20 | cmd->req.cdb_off = 0x8; 21 | cmd->req.__pad1 = 0xf; 22 | cmd->req.__pad2 = 0xf; 23 | cmd->req.iov[0].iov_base = (void*)0x23; 24 | cmd->req.iov[0].iov_len = 0x24; 25 | int i; 26 | for (i=0;i<128;i++) { 27 | printf("0x%02x ", buf[i]); 28 | if (i%16==15) 29 | printf("\n"); 30 | } 31 | printf("sizeof iov %d\n", sizeof(cmd->req.iov[0])); 32 | printf("sizeof iov_base %d\n", sizeof(cmd->req.iov[0].iov_base)); 33 | printf("sizeof iov_len %d\n", sizeof(cmd->req.iov[0].iov_len)); 34 | memset(buf, 0x0, 128); 35 | cmd->rsp.scsi_status = 0x2; 36 | cmd->rsp.sense_buffer[0] = 0x6; 37 | cmd->rsp.sense_buffer[1] = 0x7; 38 | for (i=0;i<128;i++) { 39 | printf("0x%02x ", buf[i]); 40 | if (i%16==15) 41 | printf("\n"); 42 | } 43 | memset(buf, 0x0, 128); 44 | printf("\n"); 45 | printf("\n"); 46 | struct tcmu_mailbox* mb = (struct tcmu_mailbox*)buf; 47 | mb->cmd_head = 0x07; 48 | mb->cmd_tail = 0x08; 49 | for (i=0;i<128;i++) { 50 | printf("0x%02x ", buf[i]); 51 | if (i%16==15) 52 | printf("\n"); 53 | } 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | CoreOS projects are [Apache 2.0 licensed](LICENSE) and accept contributions via 4 | GitHub pull requests. This document outlines some of the conventions on 5 | development workflow, commit message formatting, contact points and other 6 | resources to make it easier to get your contribution accepted. 7 | 8 | # Certificate of Origin 9 | 10 | By contributing to this project you agree to the Developer Certificate of 11 | Origin (DCO). This document was created by the Linux Kernel community and is a 12 | simple statement that you, as a contributor, have the legal right to make the 13 | contribution. See the [DCO](DCO) file for details. 14 | 15 | # Email and Chat 16 | 17 | The project currently uses the general CoreOS email list and IRC channel: 18 | - Email: [coreos-dev](https://groups.google.com/forum/#!forum/coreos-dev) 19 | - IRC: #[coreos](irc://irc.freenode.org:6667/#coreos) IRC channel on freenode.org 20 | 21 | Please avoid emailing maintainers found in the MAINTAINERS file directly. They 22 | are very busy and read the mailing lists. 23 | 24 | ## Getting Started 25 | 26 | - Fork the repository on GitHub 27 | - Read the [README](README.md) for build and test instructions 28 | - Play with the project, submit bugs, submit patches! 29 | 30 | ## Contribution Flow 31 | 32 | This is a rough outline of what a contributor's workflow looks like: 33 | 34 | - Create a topic branch from where you want to base your work (usually master). 35 | - Make commits of logical units. 36 | - Make sure your commit messages are in the proper format (see below). 37 | - Push your changes to a topic branch in your fork of the repository. 38 | - Make sure the tests pass, and add any new tests as appropriate. 39 | - Submit a pull request to the original repository. 40 | 41 | Thanks for your contributions! 42 | 43 | ### Coding Style 44 | 45 | CoreOS projects written in Go follow a set of style guidelines that we've documented 46 | [here](https://github.com/coreos/docs/tree/master/golang). Please follow them when 47 | working on your contributions. 48 | 49 | ### Format of the Commit Message 50 | 51 | We follow a rough convention for commit messages that is designed to answer two 52 | questions: what changed and why. The subject line should feature the what and 53 | the body of the commit should describe the why. 54 | 55 | ``` 56 | scripts: add the test-cluster command 57 | 58 | this uses tmux to setup a test cluster that you can easily kill and 59 | start for debugging. 60 | 61 | Fixes #38 62 | ``` 63 | 64 | The format can be described more formally as follows: 65 | 66 | ``` 67 | : 68 | 69 | 70 | 71 |