package main import ( "log" "sync" "github.com/ceph/go-ceph/rados" ) func main() { pool := "test-data" cephConf := "/etc/ceph/ceph.conf" snapName := "dak-test" log.Printf("This code will attempt to get and stat all objects in Ceph pool %v", pool) // Connect to ceph conn, err := rados.NewConn() if err != nil { log.Fatal("Failed to create rados connection. Error: ", err) } err = conn.ReadConfigFile(cephConf) if err != nil { log.Fatal("Failed to read ceph config. Error: ", err) } err = conn.Connect() if err != nil { log.Fatal("Failed to conect to ceph. Error: ", err) } // Create the snapshot for the pool ioctx, err := conn.OpenIOContext(pool) if err != nil { log.Fatalf("could not open ioctx to the pool: %v. Error: %v", pool, err) return } err = ioctx.CreateSnap(snapName) if err != nil { log.Fatalf("could not create a snap of pool: %v. Error: %v", pool, err) return } sid, err := ioctx.LookupSnap(snapName) if err != nil { log.Fatalf("could not find snap: %v. Error: %v", snapName, err) return } // set io context to the snapshot ioctx.SetReadSnap(sid) defer ioctx.Destroy() // create a channel to send objects to and read objects from objListChan := make(chan struct { i uint64 oid string }, 100) var wg sync.WaitGroup wg.Add(1) // Stat ojbects as they get sent to the channel go func() { defer wg.Done() // Stat all the objects in the chan for obj := range objListChan { log.Println("Statting obj: ",obj.oid) _, err := ioctx.Stat(obj.oid) if err != nil { log.Printf("could not stat object: %s in pool: %s. Error: %v ", obj.oid, pool, err) } } }() // List all objects and send to the channel var i uint64 // NOTE: this list-objects function will include objects not in this snapshot... // when this happens the object will not be able to be statted. log.Println("Listing Objects") err = ioctx.ListObjects(func(oid string) { objListChan <- struct { i uint64 oid string }{i: i, oid: oid} i++ }) if err != nil { log.Fatalf("could not list objects in %s pool: %v", pool, err) } close(objListChan) wg.Wait() log.Printf("Done listing objects") }