-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed RBDDiffV2 format and added a ceph-import-diff example
- Loading branch information
1 parent
4b83669
commit 614e33c
Showing
4 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/binary" | ||
"github.com/svenwiltink/sparsecat" | ||
"github.com/svenwiltink/sparsecat/format" | ||
"io" | ||
"log" | ||
"os" | ||
) | ||
|
||
const ( | ||
RBDImageHeader = "rbd image v2\n" | ||
RBDImageEndTag = "E" | ||
|
||
RBDImageDiffsV2Header = "rbd image diffs v2\n" | ||
RBDImageDiffV2Header = "rbd diff v2\n" | ||
) | ||
|
||
func main() { | ||
log.SetFlags(log.Llongfile) | ||
if len(os.Args) != 2 { | ||
log.Fatalln(os.Args[0], " <file to import>") | ||
} | ||
|
||
file, err := os.Open(os.Args[1]) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer file.Close() | ||
|
||
_, err = os.Stdout.WriteString(RBDImageHeader) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, err = os.Stdout.WriteString(RBDImageEndTag) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, err = os.Stdout.WriteString(RBDImageDiffsV2Header) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var buf [8]byte | ||
binary.LittleEndian.PutUint64(buf[:], 1) | ||
|
||
_, err = os.Stdout.Write(buf[:]) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, err = os.Stdout.WriteString(RBDImageDiffV2Header) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
encoder := sparsecat.NewEncoder(file) | ||
encoder.Format = format.RbdDiffv2 | ||
encoder.MaxSectionSize = 16_000_000 | ||
|
||
_, err = io.Copy(os.Stdout, encoder) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters