Compare commits

...
Author SHA1 Message Date
Michal Klos 9a0f281970 feat: ocis + vendored wip reva ocisdev-899 2026-06-22 23:11:07 +02:00
31 changed files with 587 additions and 36 deletions

No files matched your search

+1 -1
View File
@@ -65,7 +65,7 @@ require (
github.com/open-policy-agent/opa v1.17.1
github.com/orcaman/concurrent-map v1.0.0
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
github.com/owncloud/reva/v2 v2.0.0-20260622073440-d60fcb5db155
github.com/owncloud/reva/v2 v2.0.0-20260619111530-bcf7d7d3dab4
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.12
github.com/prometheus/client_golang v1.23.2
+2
View File
@@ -738,6 +738,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og=
github.com/owncloud/reva/v2 v2.0.0-20260619111530-bcf7d7d3dab4 h1:b+gXYJ1sInE9iIJK1RGw6bqyhI1FIJQPUzBbAwQrcrc=
github.com/owncloud/reva/v2 v2.0.0-20260619111530-bcf7d7d3dab4/go.mod h1:gNSgpblFyfCDi1OQfU4VqPIHWtAPR3YPTE1ZaTNnG/U=
github.com/owncloud/reva/v2 v2.0.0-20260622073440-d60fcb5db155 h1:RaT3PLjficoMB6SMoeU1BfcwBULTjbuHbXC+bmW1780=
github.com/owncloud/reva/v2 v2.0.0-20260622073440-d60fcb5db155/go.mod h1:gNSgpblFyfCDi1OQfU4VqPIHWtAPR3YPTE1ZaTNnG/U=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
@@ -31,13 +31,13 @@ import (
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/mitchellh/mapstructure"
"github.com/owncloud/reva/v2/pkg/password"
"github.com/owncloud/reva/v2/pkg/permission"
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
"github.com/owncloud/reva/v2/pkg/sharedconf"
"github.com/owncloud/reva/v2/pkg/storage/utils/grants"
"github.com/owncloud/reva/v2/pkg/utils"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"google.golang.org/grpc"
@@ -352,14 +352,9 @@ func (s *service) RemovePublicShare(ctx context.Context, req *link.RemovePublicS
user := ctxpkg.ContextMustGetUser(ctx)
ps, err := s.sm.GetPublicShare(ctx, user, req.GetRef(), false)
if err != nil {
var st *rpc.Status
switch err.(type) {
case errtypes.IsNotFound:
st = status.NewNotFound(ctx, err.Error())
default:
st = status.NewInternal(ctx, "error loading public share")
}
return &link.RemovePublicShareResponse{Status: st}, nil
return &link.RemovePublicShareResponse{
Status: status.NewInternal(ctx, "error loading public share"),
}, err
}
sRes, err := gatewayClient.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ResourceId: ps.ResourceId}})
@@ -262,14 +262,9 @@ func (s *service) RemoveShare(ctx context.Context, req *collaboration.RemoveShar
user := ctxpkg.ContextMustGetUser(ctx)
share, err := s.sm.GetShare(ctx, req.Ref)
if err != nil {
var st *rpc.Status
switch err.(type) {
case errtypes.IsNotFound:
st = status.NewNotFound(ctx, err.Error())
default:
st = status.NewInternal(ctx, "error getting share")
}
return &collaboration.RemoveShareResponse{Status: st}, nil
return &collaboration.RemoveShareResponse{
Status: status.NewInternal(ctx, "error getting share"),
}, nil
}
gatewayClient, err := s.gatewaySelector.Next()
+14
View File
@@ -309,6 +309,18 @@ type IsTooManyRequests interface {
IsTooManyRequests()
}
// ResourceProcessing is the error to use when a resource is currently being processed (e.g. an upload in progress) and the requested operation cannot proceed.
type ResourceProcessing string
func (e ResourceProcessing) Error() string { return "error: resource is processing: " + string(e) }
func (e ResourceProcessing) IsResourceProcessing() {}
// IsResourceProcessing is the interface to implement to specify that a resource is currently being processed and the requested operation cannot proceed.
type IsResourceProcessing interface {
IsResourceProcessing()
}
// NewErrtypeFromStatus maps a rpc status to an errtype
func NewErrtypeFromStatus(status *rpc.Status) error {
switch status.Code {
@@ -417,6 +429,8 @@ func NewHTTPStatusCodeFromErrtype(err error) int {
return http.StatusPartialContent
case TooEarly:
return http.StatusTooEarly
case ResourceProcessing:
return http.StatusTooEarly
case TooManyRequests:
return http.StatusTooManyRequests
case ChecksumMismatch:
@@ -76,6 +76,14 @@ func (d *driver) InitiateUpload(ctx context.Context, ref *provider.Reference, up
}, nil
}
func (d *driver) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
return errtypes.NotSupported("op not supported")
}
func (d *driver) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
return nil, errtypes.NotSupported("op not supported")
}
func (d *driver) Upload(ctx context.Context, req storage.UploadRequest, _ storage.UploadFinishedFunc) (*provider.ResourceInfo, error) {
shareID, _ := shareInfoFromReference(req.Ref)
u, err := d.GetUpload(ctx, shareID.OpaqueId)
+2
View File
@@ -213,6 +213,8 @@ func NewStatusFromErrType(ctx context.Context, msg string, err error) *rpc.Statu
return NewTooManyRequests(ctx, msg+": "+err.Error())
case errtypes.TooEarly:
return NewTooEarly(ctx, msg+": "+err.Error())
case errtypes.ResourceProcessing:
return NewTooEarly(ctx, msg+": "+err.Error())
}
// map GRPC status codes coming from the auth middleware
+9 -1
View File
@@ -32,12 +32,12 @@ import (
cephfs2 "github.com/ceph/go-ceph/cephfs"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/google/uuid"
"github.com/owncloud/reva/v2/pkg/appctx"
ctx2 "github.com/owncloud/reva/v2/pkg/ctx"
"github.com/owncloud/reva/v2/pkg/errtypes"
"github.com/owncloud/reva/v2/pkg/storage"
"github.com/owncloud/reva/v2/pkg/utils"
"github.com/google/uuid"
"github.com/pkg/errors"
tusd "github.com/tus/tusd/v2/pkg/handler"
)
@@ -147,6 +147,14 @@ func (fs *cephfs) InitiateUpload(ctx context.Context, ref *provider.Reference, u
}, nil
}
func (fs *cephfs) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
return errtypes.NotSupported("op not supported")
}
func (fs *cephfs) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
return nil, errtypes.NotSupported("op not supported")
}
// UseIn tells the tus upload middleware which extensions it supports.
func (fs *cephfs) UseIn(composer *tusd.StoreComposer) {
composer.UseCore(fs)
@@ -84,6 +84,16 @@ func (fs *hellofs) InitiateUpload(ctx context.Context, ref *provider.Reference,
return nil, errtypes.NotSupported("hellofs: initiate upload not supported")
}
// MarkProcessing toggles a processing flag on the resource.
func (fs *hellofs) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
return errtypes.NotSupported("hellofs: mark processing not supported")
}
// CommitUpload writes the staged bytes from source to the resource at ref.
func (fs *hellofs) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
return nil, errtypes.NotSupported("hellofs: commit upload not supported")
}
// grants
// DenyGrant marks a resource as denied for a recipient
+8 -1
View File
@@ -267,6 +267,14 @@ func (d *Driver) Upload(_ context.Context, _ storage.UploadRequest, _ storage.Up
return nil, errtypes.NotSupported("kiteworks: read-only driver")
}
func (d *Driver) MarkProcessing(_ context.Context, _ *provider.Reference, _ bool, _ string) error {
return errtypes.NotSupported("kiteworks: read-only driver")
}
func (d *Driver) CommitUpload(_ context.Context, _ *provider.Reference, _ storage.UploadSource) (*provider.ResourceInfo, error) {
return nil, errtypes.NotSupported("kiteworks: read-only driver")
}
func (d *Driver) RestoreRevision(_ context.Context, _ *provider.Reference, _ string) (*storage.RestoreRevisionResult, error) {
return nil, errtypes.NotSupported("kiteworks: read-only driver")
}
@@ -338,4 +346,3 @@ func (d *Driver) CreateHome(_ context.Context) error {
func (d *Driver) GetHome(_ context.Context) (string, error) {
return "", errtypes.NotSupported("kiteworks: read-only driver")
}
@@ -409,6 +409,16 @@ func (nc *StorageDriver) InitiateUpload(ctx context.Context, ref *provider.Refer
return respMap, err
}
// MarkProcessing as defined in the storage.FS interface
func (nc *StorageDriver) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
return errtypes.NotSupported("nextcloud: mark processing not supported")
}
// CommitUpload as defined in the storage.FS interface
func (nc *StorageDriver) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
return nil, errtypes.NotSupported("nextcloud: commit upload not supported")
}
// Upload as defined in the storage.FS interface
func (nc *StorageDriver) Upload(ctx context.Context, req storage.UploadRequest, _ storage.UploadFinishedFunc) (*provider.ResourceInfo, error) {
err := nc.doUpload(ctx, req.Ref.Path, req.Body)
@@ -53,6 +53,7 @@ func New(root string) (*Blobstore, error) {
}
// Upload stores some data in the blobstore under the given key
// TODO(OCISDEV-901): remove once FinishUploadDecomposed is replaced by the upload coordinator (OCISDEV-900).
func (bs *Blobstore) Upload(node *node.Node, source string) error {
if node.BlobID == "" {
return ErrBlobIDEmpty
@@ -103,6 +104,48 @@ func (bs *Blobstore) Upload(node *node.Node, source string) error {
return nil
}
// UploadFromReader stores data from a reader in the blobstore under the given key.
// It buffers to a temp file on the same filesystem as the destination so that the
// final placement is an atomic os.Rename.
func (bs *Blobstore) UploadFromReader(node *node.Node, r io.Reader, size int64) error {
if node.BlobID == "" {
return ErrBlobIDEmpty
}
dest := bs.Path(node)
if err := os.MkdirAll(filepath.Dir(dest), 0700); err != nil {
return errors.Wrap(err, "Decomposedfs: oCIS blobstore: error creating parent folders for blob")
}
tmp, err := os.CreateTemp(filepath.Dir(dest), "reva-blobstore-upload-*")
if err != nil {
return errors.Wrap(err, "Decomposedfs: oCIS blobstore: error creating temp file for upload")
}
tmpName := tmp.Name()
defer func() {
tmp.Close()
os.Remove(tmpName)
}()
w := bufio.NewWriter(tmp)
if _, err = io.Copy(w, r); err != nil {
return errors.Wrapf(err, "could not write blob to temp file '%s'", tmpName)
}
if err = w.Flush(); err != nil {
return errors.Wrapf(err, "could not flush blob temp file '%s'", tmpName)
}
if err = tmp.Sync(); err != nil {
return errors.Wrapf(err, "could not sync blob temp file '%s'", tmpName)
}
tmp.Close()
if err = os.Rename(tmpName, dest); err != nil {
return errors.Wrapf(err, "could not rename blob temp file to '%s'", dest)
}
return nil
}
// Download retrieves a blob from the blobstore for reading
func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
if node.BlobID == "" {
+9 -1
View File
@@ -31,6 +31,7 @@ import (
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/google/uuid"
"github.com/owncloud/reva/v2/pkg/appctx"
"github.com/owncloud/reva/v2/pkg/conversions"
ctxpkg "github.com/owncloud/reva/v2/pkg/ctx"
@@ -41,7 +42,6 @@ import (
"github.com/owncloud/reva/v2/pkg/storage/utils/chunking"
"github.com/owncloud/reva/v2/pkg/storage/utils/templates"
"github.com/owncloud/reva/v2/pkg/utils"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
tusd "github.com/tus/tusd/v2/pkg/handler"
@@ -169,6 +169,14 @@ func (fs *owncloudsqlfs) InitiateUpload(ctx context.Context, ref *provider.Refer
}, nil
}
func (fs *owncloudsqlfs) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
return errtypes.NotSupported("op not supported")
}
func (fs *owncloudsqlfs) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
return nil, errtypes.NotSupported("op not supported")
}
// UseIn tells the tus upload middleware which extensions it supports.
func (fs *owncloudsqlfs) UseIn(composer *tusd.StoreComposer) {
composer.UseCore(fs)
@@ -40,6 +40,7 @@ func New(root string) (*Blobstore, error) {
}
// Upload stores some data in the blobstore under the given key
// TODO(OCISDEV-901): remove once FinishUploadDecomposed is replaced by the upload coordinator (OCISDEV-900).
func (bs *Blobstore) Upload(node *node.Node, source string) error {
path := node.InternalPath()
@@ -78,6 +79,35 @@ func (bs *Blobstore) Upload(node *node.Node, source string) error {
return nil
}
// UploadFromReader stores data from a reader in the blobstore.
func (bs *Blobstore) UploadFromReader(node *node.Node, r io.Reader, size int64) error {
path := node.InternalPath()
fi, _ := os.Stat(path)
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0700)
if err != nil {
return errors.Wrapf(err, "could not open blob '%s' for writing", path)
}
defer f.Close()
w := bufio.NewWriter(f)
if _, err = io.Copy(w, r); err != nil {
return errors.Wrapf(err, "could not write blob '%s'", path)
}
if err = w.Flush(); err != nil {
return errors.Wrapf(err, "could not flush blob '%s'", path)
}
if err = f.Sync(); err != nil {
return errors.Wrapf(err, "could not sync blob '%s' to disk", path)
}
if fi != nil {
return os.Chtimes(path, fi.ModTime(), fi.ModTime())
}
return nil
}
// Download retrieves a blob from the blobstore for reading
func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
file, err := os.Open(node.InternalPath())
+7
View File
@@ -62,6 +62,7 @@ func init() {
// Blobstore defines an interface for storing blobs in a blobstore
type Blobstore interface {
Upload(node *node.Node, source string) error
UploadFromReader(node *node.Node, r io.Reader, size int64) error
Download(node *node.Node) (io.ReadCloser, error)
Delete(node *node.Node) error
}
@@ -675,10 +676,16 @@ func (t *Tree) Propagate(ctx context.Context, n *node.Node, sizeDiff int64) (err
}
// WriteBlob writes a blob to the blobstore
// TODO(OCISDEV-901): remove WriteBlob once FinishUploadDecomposed is replaced by the upload coordinator (OCISDEV-900).
func (t *Tree) WriteBlob(node *node.Node, source string) error {
return t.blobstore.Upload(node, source)
}
// WriteBlobFromReader writes a blob to the blobstore from a reader
func (t *Tree) WriteBlobFromReader(node *node.Node, r io.Reader, size int64) error {
return t.blobstore.UploadFromReader(node, r, size)
}
// ReadBlob reads a blob from the blobstore
func (t *Tree) ReadBlob(node *node.Node) (io.ReadCloser, error) {
return t.blobstore.Download(node)
+8
View File
@@ -73,3 +73,11 @@ func (fs *s3FS) Upload(ctx context.Context, req storage.UploadRequest, uff stora
func (fs *s3FS) InitiateUpload(ctx context.Context, ref *provider.Reference, uploadLength int64, metadata map[string]string) (map[string]string, error) {
return nil, errtypes.NotSupported("op not supported")
}
func (fs *s3FS) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
return errtypes.NotSupported("op not supported")
}
func (fs *s3FS) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
return nil, errtypes.NotSupported("op not supported")
}
@@ -27,10 +27,10 @@ import (
"path/filepath"
"strings"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/lookup"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/lookup"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/pkg/errors"
)
@@ -77,6 +77,7 @@ func New(endpoint, region, bucket, accessKey, secretKey string, defaultPutOption
}
// Upload stores some data in the blobstore under the given key
// TODO(OCISDEV-901): remove once FinishUploadDecomposed is replaced by the upload coordinator (OCISDEV-900).
func (bs *Blobstore) Upload(node *node.Node, source string) error {
reader, err := os.Open(source)
if err != nil {
@@ -100,6 +101,23 @@ func (bs *Blobstore) Upload(node *node.Node, source string) error {
return nil
}
// UploadFromReader stores data from a reader directly into S3 without local buffering.
func (bs *Blobstore) UploadFromReader(node *node.Node, r io.Reader, size int64) error {
_, err := bs.client.PutObject(context.Background(), bs.bucket, bs.Path(node), r, size, minio.PutObjectOptions{
ContentType: "application/octet-stream",
SendContentMd5: bs.defaultPutOptions.SendContentMd5,
ConcurrentStreamParts: bs.defaultPutOptions.ConcurrentStreamParts,
NumThreads: bs.defaultPutOptions.NumThreads,
PartSize: bs.defaultPutOptions.PartSize,
DisableMultipart: bs.defaultPutOptions.DisableMultipart,
DisableContentSha256: bs.defaultPutOptions.DisableContentSha256,
})
if err != nil {
return errors.Wrapf(err, "could not store object '%s' into bucket '%s'", bs.Path(node), bs.bucket)
}
return nil
}
// Download retrieves a blob from the blobstore for reading
func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
reader, err := bs.client.GetObject(context.Background(), bs.bucket, bs.Path(node), minio.GetObjectOptions{})
+21 -1
View File
@@ -101,7 +101,7 @@ type FS interface {
// CreateDir creates a resource of type container
CreateDir(ctx context.Context, ref *provider.Reference) (*CreateDirResult, error)
// TouchFile sets the mtime of a resource, creating an empty file if it does not exist
// FIXME the markprocessing flag is an implementation detail of decomposedfs, remove it from the function
// FIXME(OCISDEV-900) remove markprocessing bool: coordinator calls MarkProcessing(true) explicitly after TouchFile
// FIXME the mtime should either be a time.Time or a CS3 Timestamp, not a string
TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool, mtime string) (*TouchFileResult, error)
// Delete deletes a resource.
@@ -114,6 +114,10 @@ type FS interface {
InitiateUpload(ctx context.Context, ref *provider.Reference, uploadLength int64, metadata map[string]string) (map[string]string, error)
// Upload creates or updates a resource of type file with a new revision
Upload(ctx context.Context, req UploadRequest, uploadFunc UploadFinishedFunc) (*provider.ResourceInfo, error)
// MarkProcessing toggles a processing flag on the resource.
MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error
// CommitUpload writes the staged bytes from source to the resource at ref.
CommitUpload(ctx context.Context, ref *provider.Reference, source UploadSource) (*provider.ResourceInfo, error)
// Revisions
@@ -207,6 +211,22 @@ type DeleteStorageSpaceResult struct {
FinalMembers map[string]provider.ResourcePermissions
}
// UploadChecksums holds pre-computed checksums for a CommitUpload call.
// All three must be provided; the driver stores them as xattrs without recomputing.
type UploadChecksums struct {
SHA1 []byte
MD5 []byte
Adler32 []byte
}
// UploadSource carries the staged bytes for a CommitUpload call.
type UploadSource struct {
Body io.ReadCloser
Length int64
Metadata map[string]string
Checksums UploadChecksums
}
// UnscopeFunc is a function that unscopes a user
type UnscopeFunc func()
@@ -928,6 +928,11 @@ func (fs *Decomposedfs) Move(ctx context.Context, oldRef, newRef *provider.Refer
return nil, err
}
// check processing on source
if oldNode.IsProcessing(ctx) {
return nil, errtypes.ResourceProcessing(oldRef.String())
}
if err := fs.tp.Move(ctx, oldNode, newNode); err != nil {
return nil, err
}
@@ -1103,7 +1108,7 @@ func (fs *Decomposedfs) Delete(ctx context.Context, ref *provider.Reference) (dr
}
if node.IsProcessing(ctx) {
return nil, errtypes.TooEarly("file is processing")
return nil, errtypes.ResourceProcessing(ref.String())
}
rp, err := fs.p.AssemblePermissions(ctx, node)
@@ -1166,6 +1171,10 @@ func (fs *Decomposedfs) Download(ctx context.Context, ref *provider.Reference, o
return nil, nil, errtypes.NotFound(f)
}
// check processing
if n.IsProcessing(ctx) {
return nil, nil, errtypes.ResourceProcessing(ref.String())
}
ri, err := n.AsResourceInfo(ctx, rp, nil, []string{"size", "mimetype", "etag"}, true)
if err != nil {
return nil, nil, err
@@ -117,7 +117,10 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g
return errtypes.NotFound(f)
}
}
// check processing
if grantNode.IsProcessing(ctx) {
return errtypes.ResourceProcessing(ref.String())
}
return fs.storeGrant(ctx, grantNode, g)
}
@@ -208,7 +211,10 @@ func (fs *Decomposedfs) RemoveGrant(ctx context.Context, ref *provider.Reference
return errtypes.NotFound(f)
}
}
// check processing
if grantNode.IsProcessing(ctx) {
return errtypes.ResourceProcessing(ref.String())
}
if err := grantNode.DeleteGrant(ctx, g, false); err != nil {
return err
}
@@ -277,6 +283,10 @@ func (fs *Decomposedfs) UpdateGrant(ctx context.Context, ref *provider.Reference
}
}
// check processing
if grantNode.IsProcessing(ctx) {
return errtypes.ResourceProcessing(ref.String())
}
return fs.storeGrant(ctx, grantNode, g)
}
@@ -27,13 +27,13 @@ import (
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/google/uuid"
"github.com/owncloud/reva/v2/pkg/appctx"
"github.com/owncloud/reva/v2/pkg/errtypes"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/options"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rogpeppe/go-internal/lockedfile"
"go.opentelemetry.io/otel"
@@ -125,7 +125,9 @@ type Tree interface {
InitNewNode(ctx context.Context, n *Node, fsize uint64) (metadata.UnlockFunc, error)
// TODO(OCISDEV-901): remove WriteBlob once FinishUploadDecomposed is replaced by the upload coordinator (OCISDEV-900).
WriteBlob(node *Node, source string) error
WriteBlobFromReader(node *Node, r io.Reader, size int64) error
ReadBlob(node *Node) (io.ReadCloser, error)
DeleteBlob(node *Node) error
@@ -1337,6 +1339,15 @@ var CheckQuota = func(ctx context.Context, spaceRoot *Node, overwrite bool, oldS
return true, nil
}
// CheckDiskSpace returns an error if the underlying filesystem has insufficient
// free space for newSize bytes. Does not enforce space-level quota.
var CheckDiskSpace = func(_ context.Context, spaceRoot *Node, newSize uint64) error {
if !enoughDiskSpace(spaceRoot.InternalPath(), newSize) {
return errtypes.InsufficientStorage("disk full")
}
return nil
}
func enoughDiskSpace(path string, fileSize uint64) bool {
avalB, err := GetAvailableSize(path)
if err != nil {
@@ -102,6 +102,11 @@ func (n *Node) SetXattrString(ctx context.Context, key, val string) (err error)
return n.lu.MetadataBackend().Set(ctx, n.InternalPath(), key, []byte(val))
}
// ResetXattrsCache clears the in-process xattr cache so the next read fetches from disk.
func (n *Node) ResetXattrsCache() {
n.xattrsCache = nil
}
// RemoveXattr removes an extended attribute from the write-through cache/node
func (n *Node) RemoveXattr(ctx context.Context, key string, acquireLock bool) error {
if n.xattrsCache != nil {
@@ -232,6 +232,11 @@ func (fs *Decomposedfs) RestoreRevision(ctx context.Context, ref *provider.Refer
return nil, err
}
// check processing
if n.IsProcessing(ctx) {
return nil, errtypes.ResourceProcessing(ref.String())
}
// write lock node before copying metadata
f, err := lockedfile.OpenFile(fs.lu.MetadataBackend().LockfilePath(n.InternalPath()), os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
@@ -26,14 +26,14 @@ import (
"strings"
"time"
"github.com/google/renameio/v2"
"github.com/google/uuid"
"github.com/owncloud/reva/v2/pkg/appctx"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/lookup"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/options"
"github.com/google/renameio/v2"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rogpeppe/go-internal/lockedfile"
"github.com/rs/zerolog"
@@ -57,7 +57,9 @@ func init() {
// Blobstore defines an interface for storing blobs in a blobstore
type Blobstore interface {
// TODO(OCISDEV-901): remove Upload once FinishUploadDecomposed is replaced by the upload coordinator (OCISDEV-900).
Upload(node *node.Node, source string) error
UploadFromReader(node *node.Node, r io.Reader, size int64) error
Download(node *node.Node) (io.ReadCloser, error)
Delete(node *node.Node) error
}
@@ -816,10 +818,16 @@ func (t *Tree) Propagate(ctx context.Context, n *node.Node, sizeDiff int64) (err
}
// WriteBlob writes a blob to the blobstore
// TODO(OCISDEV-901): remove once FinishUploadDecomposed is replaced by the upload coordinator (OCISDEV-900).
func (t *Tree) WriteBlob(node *node.Node, source string) error {
return t.blobstore.Upload(node, source)
}
// WriteBlobFromReader writes a blob to the blobstore from a reader
func (t *Tree) WriteBlobFromReader(node *node.Node, r io.Reader, size int64) error {
return t.blobstore.UploadFromReader(node, r, size)
}
// ReadBlob reads a blob from the blobstore
func (t *Tree) ReadBlob(node *node.Node) (io.ReadCloser, error) {
if node.BlobID == "" {
+252 -4
View File
@@ -28,7 +28,10 @@ import (
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/google/uuid"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata"
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes"
"github.com/pkg/errors"
"github.com/rogpeppe/go-internal/lockedfile"
tusd "github.com/tus/tusd/v2/pkg/handler"
"github.com/owncloud/reva/v2/pkg/appctx"
@@ -44,8 +47,7 @@ import (
)
// Upload uploads data to the given resource
// TODO Upload (and InitiateUpload) needs a way to receive the expected checksum.
// Maybe in metadata as 'checksum' => 'sha1 aeosvp45w5xaeoe' = lowercase, space separated?
// TODO(OCISDEV-901): remove Upload once all drivers are migrated to CommitUpload and the coordinator (OCISDEV-900) is in place.
func (fs *Decomposedfs) Upload(ctx context.Context, req storage.UploadRequest, uff storage.UploadFinishedFunc) (*provider.ResourceInfo, error) {
_, span := tracer.Start(ctx, "Upload")
defer span.End()
@@ -129,8 +131,7 @@ func (fs *Decomposedfs) Upload(ctx context.Context, req storage.UploadRequest, u
}
// InitiateUpload returns upload ids corresponding to different protocols it supports
// TODO read optional content for small files in this request
// TODO InitiateUpload (and Upload) needs a way to receive the expected checksum. Maybe in metadata as 'checksum' => 'sha1 aeosvp45w5xaeoe' = lowercase, space separated?
// TODO(OCISDEV-901): remove InitiateUpload once all drivers are migrated to CommitUpload and the coordinator (OCISDEV-900) is in place.
func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Reference, uploadLength int64, metadata map[string]string) (map[string]string, error) {
_, span := tracer.Start(ctx, "InitiateUpload")
defer span.End()
@@ -341,6 +342,253 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere
}, nil
}
// MarkProcessing toggles a processing flag on the resource.
func (fs *Decomposedfs) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
n, err := fs.lu.NodeFromResource(ctx, ref)
if err != nil {
return err
}
if !n.Exists {
return errtypes.NotFound(ref.String())
}
// Early lock, so MarkProcessing is atomic.
unlock, err := fs.lu.MetadataBackend().Lock(n.InternalPath())
if err != nil {
return err
}
defer unlock() //nolint:errcheck
// Evict the node's in-process xattr cache so IsProcessing reads from disk while we hold the lock.
n.ResetXattrsCache()
if !processing {
if !n.IsProcessing(ctx) {
return nil
}
id, _ := n.ProcessingID(ctx)
if id != sessionID {
return nil // owned by a different session, do not clear
}
return n.RemoveXattr(ctx, prefixes.StatusPrefix, false)
}
if n.IsProcessing(ctx) {
return errtypes.ResourceProcessing(ref.String())
}
return n.SetXattrsWithContext(ctx, node.Attributes{
prefixes.StatusPrefix: []byte(node.ProcessingStatus + sessionID),
}, false) // acquireLock=false, because outer lock already held
}
// CommitUpload writes the staged bytes from source to the resource at ref.
func (fs *Decomposedfs) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
defer source.Body.Close()
n, err := fs.lu.NodeFromResource(ctx, ref)
if err != nil {
return nil, err
}
if !n.Exists {
return nil, errtypes.NotFound(ref.String())
}
if len(source.Checksums.SHA1) == 0 || len(source.Checksums.MD5) == 0 || len(source.Checksums.Adler32) == 0 {
return nil, errtypes.BadRequest("CommitUpload: pre-computed checksums missing from source")
}
attrs := node.Attributes{
prefixes.ChecksumPrefix + "sha1": source.Checksums.SHA1,
prefixes.ChecksumPrefix + "md5": source.Checksums.MD5,
prefixes.ChecksumPrefix + "adler32": source.Checksums.Adler32,
}
n.BlobID = uuid.New().String()
n.Blobsize = source.Length
attrs.SetString(prefixes.IDAttr, n.ID)
attrs.SetInt64(prefixes.TypeAttr, int64(provider.ResourceType_RESOURCE_TYPE_FILE))
attrs.SetString(prefixes.ParentidAttr, n.ParentID)
attrs.SetString(prefixes.NameAttr, n.Name)
attrs.SetString(prefixes.BlobIDAttr, n.BlobID)
attrs.SetInt64(prefixes.BlobsizeAttr, n.Blobsize)
mtime := time.Now()
if mts := source.Metadata["mtime"]; mts != "" {
parsed, err := utils.MTimeToTime(mts)
if err != nil {
return nil, errtypes.BadRequest("invalid mtime: " + mts)
}
mtime = parsed
}
if fs.um != nil {
if gid, ok := ctx.Value(CtxKeySpaceGID).(uint32); ok {
unscope, err := fs.um.ScopeUserByIds(-1, int(gid))
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to scope user")
}
if unscope != nil {
defer func() { _ = unscope() }()
}
}
}
n.SpaceRoot, err = node.ReadNode(ctx, fs.lu, n.SpaceID, n.SpaceID, false, nil, false)
if err != nil {
return nil, err
}
if err := n.CheckLock(ctx); err != nil {
return nil, err
}
var (
unlock metadata.UnlockFunc
sizeDiff int64
)
defer func() {
if unlock == nil {
return
}
if err := unlock(); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Str("parentid", n.ParentID).Msg("could not close lock")
}
}()
f, err := lockedfile.OpenFile(fs.lu.MetadataBackend().LockfilePath(n.InternalPath()), os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to lock node for overwrite")
}
unlock = func() error { return f.Close() }
old, err := node.ReadNode(ctx, fs.lu, n.SpaceID, n.ID, false, nil, false)
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to read existing node")
}
if err := node.CheckDiskSpace(ctx, n.SpaceRoot, uint64(source.Length)); err != nil {
return nil, err
}
oldNodeMtime, err := old.GetMTime(ctx)
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to read old mtime")
}
if !fs.o.DisableVersioning && old.BlobID != "" {
versionPath := fs.lu.InternalPath(n.SpaceID, n.ID+node.RevisionIDDelimiter+oldNodeMtime.UTC().Format(time.RFC3339Nano))
revFile, err := os.OpenFile(versionPath, os.O_CREATE|os.O_EXCL, 0600)
if err != nil {
if !errors.Is(err, os.ErrExist) {
return nil, errors.Wrap(err, "Decomposedfs: failed to create revision file")
}
// EEXIST: a revision archive at this mtime already exists from a
// prior CommitUpload run. If the archive is byte-identical to the
// live node, it is a leftover from an idempotent retry and can be
// safely reset; otherwise we refuse rather than clobber history.
if err := validateRevisionChecksums(ctx, fs.lu, old, versionPath); err != nil {
return nil, errors.Wrap(err, "Decomposedfs: existing revision archive does not match current node")
}
bID, _, err := fs.lu.ReadBlobIDAndSizeAttr(ctx, versionPath, nil)
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to read blob id of existing revision")
}
if err := fs.tp.DeleteBlob(&node.Node{BlobID: bID, SpaceID: n.SpaceID}); err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to delete stale revision blob")
}
revFile, err = os.Create(versionPath)
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to truncate revision file")
}
}
revFile.Close()
if err := fs.lu.CopyMetadataWithSourceLock(ctx, n.InternalPath(), versionPath,
func(name string, value []byte) ([]byte, bool) {
return value, strings.HasPrefix(name, prefixes.ChecksumPrefix) ||
name == prefixes.TypeAttr ||
name == prefixes.BlobIDAttr ||
name == prefixes.BlobsizeAttr ||
name == prefixes.MTimeAttr
}, f, true); err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to archive current revision")
}
if err := os.Chtimes(versionPath, oldNodeMtime, oldNodeMtime); err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to set revision mtime")
}
}
sizeDiff = source.Length - old.Blobsize
revisionNode := node.New(n.SpaceID, n.ID, n.ParentID, n.Name, n.Blobsize, n.BlobID,
provider.ResourceType_RESOURCE_TYPE_FILE, nil, fs.lu)
if err := fs.tp.WriteBlobFromReader(revisionNode, source.Body, source.Length); err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to write blob")
}
// The blob now exists in the blobstore but the node metadata does not yet
// reference it. If any of the steps below fail we return an error without
// persisting that reference, leaving the blob orphaned. Delete it on the
// error path; cleared once the commit completes.
committed := false
defer func() {
if committed {
return
}
if derr := fs.tp.DeleteBlob(revisionNode); derr != nil {
appctx.GetLogger(ctx).Error().Err(derr).Str("nodeid", n.ID).Str("blobid", n.BlobID).Msg("could not clean up orphaned blob after failed commit")
}
}()
if err := fs.lu.TimeManager().OverrideMtime(ctx, n, &attrs, mtime); err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to set the mtime")
}
if err := n.SetXattrsWithContext(ctx, attrs, false); err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to write metadata")
}
if err := fs.tp.Propagate(ctx, n, sizeDiff); err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to propagate")
}
etag, err := node.CalculateEtag(n.ID, mtime)
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: failed to calculate etag")
}
committed = true
return &provider.ResourceInfo{
Id: &provider.ResourceId{
StorageId: source.Metadata["providerID"],
SpaceId: n.SpaceID,
OpaqueId: n.ID,
},
Etag: etag,
Mtime: utils.TimeToTS(mtime),
}, nil
}
// validateRevisionChecksums returns nil iff every checksum xattr (md5, sha1,
// adler32) on the live node n equals the same xattr on the archive at
// versionPath. Used to detect a leftover archive from an idempotent retry.
func validateRevisionChecksums(ctx context.Context, lu node.PathLookup, n *node.Node, versionPath string) error {
for _, algo := range []string{"md5", "sha1", "adler32"} {
key := prefixes.ChecksumPrefix + algo
live, err := n.Xattr(ctx, key)
if err != nil {
return err
}
archived, err := lu.MetadataBackend().Get(ctx, versionPath, key)
if err != nil {
return err
}
if len(live) == 0 || len(archived) == 0 {
return errors.New("checksum not found")
}
if string(live) != string(archived) {
return errors.New("checksum mismatch on " + algo)
}
}
return nil
}
// UseIn tells the tus upload middleware which extensions it supports.
func (fs *Decomposedfs) UseIn(composer *tusd.StoreComposer) {
composer.UseCore(fs)
+8
View File
@@ -98,3 +98,11 @@ func (fs *eosfs) InitiateUpload(ctx context.Context, ref *provider.Reference, up
"simple": p,
}, nil
}
func (fs *eosfs) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
return errtypes.NotSupported("op not supported")
}
func (fs *eosfs) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
return nil, errtypes.NotSupported("op not supported")
}
+9 -1
View File
@@ -27,13 +27,13 @@ import (
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/google/uuid"
"github.com/owncloud/reva/v2/pkg/appctx"
ctxpkg "github.com/owncloud/reva/v2/pkg/ctx"
"github.com/owncloud/reva/v2/pkg/errtypes"
"github.com/owncloud/reva/v2/pkg/storage"
"github.com/owncloud/reva/v2/pkg/storage/utils/chunking"
"github.com/owncloud/reva/v2/pkg/utils"
"github.com/google/uuid"
"github.com/pkg/errors"
tusd "github.com/tus/tusd/v2/pkg/handler"
)
@@ -151,6 +151,14 @@ func (fs *localfs) InitiateUpload(ctx context.Context, ref *provider.Reference,
}, nil
}
func (fs *localfs) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
return errtypes.NotSupported("op not supported")
}
func (fs *localfs) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
return nil, errtypes.NotSupported("op not supported")
}
// UseIn tells the tus upload middleware which extensions it supports.
func (fs *localfs) UseIn(composer *tusd.StoreComposer) {
composer.UseCore(fs)
@@ -361,6 +361,60 @@ func (f *FS) Upload(ctx context.Context, req storage.UploadRequest, uploadFunc s
return res0, res1
}
func (f *FS) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
var (
err error
unhook UnHook
unhooks []UnHook
)
for _, hook := range f.hooks {
ctx, unhook, err = hook("MarkProcessing", ctx, ref.GetResourceId().GetSpaceId())
if err != nil {
return err
}
if unhook != nil {
unhooks = append(unhooks, unhook)
}
}
res := f.next.MarkProcessing(ctx, ref, processing, sessionID)
for _, unhook := range unhooks {
if err := unhook(); err != nil {
return err
}
}
return res
}
func (f *FS) CommitUpload(ctx context.Context, ref *provider.Reference, source storage.UploadSource) (*provider.ResourceInfo, error) {
var (
err error
unhook UnHook
unhooks []UnHook
)
for _, hook := range f.hooks {
ctx, unhook, err = hook("CommitUpload", ctx, ref.GetResourceId().GetSpaceId())
if err != nil {
return &provider.ResourceInfo{}, err
}
if unhook != nil {
unhooks = append(unhooks, unhook)
}
}
res0, res1 := f.next.CommitUpload(ctx, ref, source)
for _, unhook := range unhooks {
if err := unhook(); err != nil {
return &provider.ResourceInfo{}, err
}
}
return res0, res1
}
func (f *FS) Download(ctx context.Context, ref *provider.Reference, openReaderFunc func(md *provider.ResourceInfo) bool) (*provider.ResourceInfo, io.ReadCloser, error) {
var (
err error
+1 -1
View File
@@ -1319,7 +1319,7 @@ github.com/orcaman/concurrent-map
# github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
## explicit; go 1.18
github.com/owncloud/libre-graph-api-go
# github.com/owncloud/reva/v2 v2.0.0-20260622073440-d60fcb5db155
# github.com/owncloud/reva/v2 v2.0.0-20260619111530-bcf7d7d3dab4
## explicit; go 1.25.7
github.com/owncloud/reva/v2/cmd/revad/internal/grace
github.com/owncloud/reva/v2/cmd/revad/runtime