On Wed 04-08-21 12:06:08, Gabriel Krisman Bertazi wrote:
Plumb the pieces to add a FID report to error records. Since all error
event memory must be pre-allocated, we estimate a file handler size and
if it is insuficient, we report an invalid FID and increase the
prediction for the next error slot allocation.
For errors that don't expose a file handler report it with an invalid
FID.
Signed-off-by: Gabriel Krisman Bertazi <redacted>
...
quoted hunk ↗ jump to hunk
@@ -715,6 +717,31 @@ static void fanotify_insert_error_event(struct fsnotify_group *group,
fee->fae.type = FANOTIFY_EVENT_TYPE_FS_ERROR;
fee->error = report->error;
fee->err_count = 1;
+ fee->fsid = fee->sb_mark->fsn_mark.connector->fsid;
+
+ /*
+ * Error reporting needs to happen in atomic context. If this
+ * inode's file handler length is more than we initially
+ * predicted, there is nothing better we can do than report the
+ * error with a bad file handler.
+ */
+ fh_len = fanotify_encode_fh_len(inode);
+ if (fh_len > fee->sb_mark->pred_fh_len) {
+ pr_warn_ratelimited(
+ "FH overflows error event. Drop inode information.\n");
+ /*
+ * Update the handler size prediction for the next error
+ * event allocation. This reduces the chance of another
+ * overflow.
+ */
+ fee->sb_mark->pred_fh_len = fh_len;
+
+ /* For the current error, ignore the inode information. */
+ inode = NULL;
+ fh_len = fanotify_encode_fh_len(NULL);
+ }
+
+ fanotify_encode_fh(&fee->object_fh, inode, fh_len, NULL, 0);
}
I don't think calling fanotify_encode_fh() from under notification_lock is
a good practice. It calls into a filesystem and god knows which locks it may
need to take to get necessary info... See my reply to patch 18 how we could
handle that better.
Honza
--
Jan Kara [off-list ref]
SUSE Labs, CR