Re: fscrypt and file truncation on cephfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2021-03-12 at 15:36 -0800, Gregory Farnum wrote:
> On Fri, Mar 12, 2021 at 12:24 PM Jeff Layton <jlayton@xxxxxxxxxx> wrote:
> > 
> > On Fri, 2021-03-12 at 11:45 -0800, Gregory Farnum wrote:
> > > On Fri, Mar 12, 2021 at 4:49 AM Jeff Layton <jlayton@xxxxxxxxxx> wrote:
> > > > 
> > > > On Fri, 2021-03-12 at 00:43 -0800, Gregory Farnum wrote:
> > > 
> > > > > ...although in my current sleep-addled state, I'm actually not sure we
> > > > > need to add any permanent storage to the MDS to handle this case! We
> > > > > can probably just extend the front-end truncate op so that it can take
> > > > > a separate "real-truncate-size" and the logical file size, can't we?
> > > > 
> > > > That would be one nice thing about the approach of #1. Truncating the
> > > > size downward is always done via an explicit SETATTR op (I think), so we
> > > > could just extend that with a new field for that tells the MDS where to
> > > > stop truncating.
> > > > 
> > > > Note that regardless of the approach we choose, the client will still
> > > > need to do a read/modify/write on the edge block before we can really
> > > > treat the truncation as "done". I'm not yet sure whether that has any
> > > > bearing on the consistency/safety of the truncation process.
> > > 
> > > Wait what? Let's talk more about that: I can't emphasize enough how
> > > much you really, *really* don't want to require clients to do a RMW to
> > > RADOS that is coordinated with MDS state changes that may modify the
> > > same objects.
> > > 
> > > Isn't it enough for:
> > > 1) truncate op sets file size to new logical size, and truncate_size
> > > to end of crypto block
> > > 2) clients do rados reads until the end of the crypto block and throw
> > > away the data past the logical end-of-file when serving IO
> > > 3) clients can remove the old data on a write when they feel like it
> > > and then set truncate_size to the real file size
> > > 
> > > The only tricky bit there is making sure the MDS respects the
> > > truncate_size everywhere it needs to, and doesn't inadvertently force
> > > it down to the file size when we don't want that happening.
> > > 
> > 
> > That sounds like it would work. I'll probably take something like that
> > approach.
> > 
> > In principle, the MDS really should not care about the logical size of
> > the file at all. All it needs to know is how big the actual backing
> > objects are, and that will always be rounded up to the next crypto
> > block.
> > 
> > So, I'm sort of a fan of the idea of having a "private" size field that
> > only the clients with valid the crypto keys use. Everything else would
> > just report (and deal with) the rounded-up size. So, the clients would
> > always set the current inode size field to the rounded-up size, and then
> > maintain the actual logical file size in their private field.
> > 
> > This has the advantage that we don't need to tinker with the MDS
> > mechanics so much -- only extend the inode with the new field (which
> > sucks, but is a reasonably mechanical change).
> 
> Yeah, I initially really disliked the idea of adding a new "real
> logical size" member, but the more I think about it the less I like
> the alternatives, too. IIRC we go to a fair bit of trouble in the
> server to handle sizes changing while other stuff is going on so
> you'll want to look at that and see if we're okay just relying on the
> clients to set their "logical crypto size" or not.
> 

Yeah, this is tricky business, and the MDS side of things is definitely
not my area of expertise. What kind of "other stuff" do you mean in this
case?

In any case, after thinking about this a bit, what may be best is to add
new "crypto_info" field to the inode. This field would basically be
opaque to the MDS, but it'd need to record and track changes to it.

It might be good to make that field some multiple of 16 bytes (which is
the fundamental fscrypt blocksize). I like the idea of being able to
encrypt this info, and there may be other private info we'd wish to
stash in there later.

We could consider tacking this field onto the encryption context xattr,
but I'm not sure that's the best idea.

> > 
> > This also dovetails nicely with having the client "lazily" zero-pad the
> > EOF block after resetting the size.
> > 
> > > I do foresee one leak, which is how we handle probing for file size
> > > when a client with write caps disappears[2], but that's going to be
> > > the case no matter what solution we come up with unless we're willing
> > > to tolerate a two-phase commit. Which would be *awful*[1].
> > > -Greg
> > > 
> > > [1]: We're talking about needing to send a crypto-truncate to the MDS,
> > > have it withdraw all client caps, return a new "start your phase"
> > > message/state which grants read and write caps to the truncating
> > > client (which I have no idea how we'd do while a logical MDS write is
> > > happening), have the client do the RMW on the tail object and return
> > > its caps, commit the new file size, and then return the final op and
> > > re-issue caps — and handle cleaning up if the client fails at any
> > > point in that process. I guess if we did manage to jump through all
> > > those hoops, client failure recovery would be deterministic and
> > > accurate based on if the final object size was larger than or equal to
> > > the attempted new size...
> > 
> > How does this probing work today?
> 
> The MDS checks for objects in the interval from the latest size it has
> seen up to the max allowed size for the client, and sets the size to
> the last byte it finds. There's nothing tricky about it. (It may also
> probe *every* object in the file to try and resolve the mtime, but I'm
> less sure about that.)
> 

Oh right, I sort of remember seeing this at some point.

I think this can still work -- the MDS would just be determining the
rounded-up size of the file. The client would need to determine the
length of the last object though. It can't use the size of the object at
that point, so we'd need to come up with some other way to track the
size.

One idea might be to just set an xattr on the object with the latest
size of the decrypted object when we do a write? We'd have to do it in
the same WRITE compound op, but that could be done. We could even
encrypt that data too since prying eyes don't need to know.

Then the client could just vet the size in the xattr of the last object
vs. the (private) one in the inode.

Either way, I'm going to need to enlist some help for the MDS side of
this bit, I think, and whoever picks up that part should probably be
involved in the design.

> > 
> > > [2]: And now that I think about the implications of crypto some more,
> > > we can even fix this. Since crypto clients can never do rados append
> > > ops (and I don't think we can in the FS *anyway*?) we can just have
> > > all crypto-client writes include setting a "logical size" xattr on the
> > > rados object that the MDS can use when probing. We maybe should do
> > > that for everything, actually...
> > > 
> > 
> > That does sound like a good idea, and it wouldn't be too difficult to
> > implement since we're already going to be moving to doing more multi-op
> > OSD write calls anyway.
> > 
> > --
> > Jeff Layton <jlayton@xxxxxxxxxx>
> > 
> 

-- 
Jeff Layton <jlayton@xxxxxxxxxx>
_______________________________________________
Dev mailing list -- dev@xxxxxxx
To unsubscribe send an email to dev-leave@xxxxxxx




[Index of Archives]     [CEPH Users]     [Ceph Devel]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux