Re: [PATCH] netfs: Use container_of() for offset casting
From: David Howells
Date: Wed May 18 2022 - 04:05:24 EST
I wonder if it would be worth making this explicit in the inode wrappers of
the users of netfslib. In afs, for instance, there is:
struct afs_vnode {
struct {
/* These must be contiguous */
struct inode vfs_inode;
struct netfs_i_context netfs_ctx;
};
...
};
would it be worth making that:
struct afs_vnode {
union {
struct netfs_i_c_pair netfs_inode;
struct {
/* These must be contiguous */
struct inode vfs_inode;
struct netfs_i_context netfs_ctx;
};
};
...
};
I don't want to do the following, say:
struct afs_vnode {
struct netfs_i_c_pair ni;
...
};
as that would then require a lot of s/->vfs_inode/->ni.vfs_inode/, but maybe
it would be better to include a struct inode in struct netfs_i_context, and
then do:
struct afs_vnode {
union {
struct netfs_i_context netfs_ctx;
struct inode vfs_inode;
};
...
};
and perhaps rename netfs_i_context to netfs_inode (though that looks a bit
close to nfs_inode). It's just a shame I can't do:
struct netfs_inode : inode {
...
};
struct afs_vnode : netfs_inode {
...
};
right? ;-)
On the other hand:
warthog>git grep '[>.]vfs_inode' -- fs/{9p,afs,ceph,cifs,nfs} | wc -l
181
so maybe a mass change to, say:
struct netfs_inode {
struct inode vfs_inode;
...
};
struct afs_vnode {
struct netfs_inode ni;
...
};
wouldn't be so bad.
David