* xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py
@ 2025-08-26 13:15 Christian Kujau
2025-08-26 15:57 ` Darrick J. Wong
0 siblings, 1 reply; 4+ messages in thread
From: Christian Kujau @ 2025-08-26 13:15 UTC (permalink / raw)
To: linux-xfs; +Cc: Darrick J. Wong
Running xfs_scrub_all under Python 3.13.5 prints the following warning:
----------------------------------------------
$ /usr/sbin/xfs_scrub_all --auto-media-scan-stamp \
/var/lib/xfsprogs/xfs_scrub_all_media.stamp \
--auto-media-scan-interval 1d
/usr/sbin/xfs_scrub_all:489: DeprecationWarning:
datetime.datetime.utcnow() is deprecated and scheduled for removal in a
future version. Use timezone-aware objects to represent datetimes in UTC:
datetime.datetime.now(datetime.UTC).
dt = datetime.utcnow()
Automatically enabling file data scrub.
----------------------------------------------
Python documentation for context:
https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow
Fix this by using datetime.now() instead.
NB: Debian/13 ships Python 3.13.5 and has a xfs_scrub_all.timer active,
I'd assume that many systems will have that warning now in their logs :-)
Signed-off-by: Christian Kujau <lists@nerdbynature.de>
diff --git a/scrub/xfs_scrub_all.py.in b/scrub/xfs_scrub_all.py.in
index 515cc144..a94b1b71 100644
--- a/scrub/xfs_scrub_all.py.in
+++ b/scrub/xfs_scrub_all.py.in
@@ -496,8 +496,7 @@ def scan_interval(string):
def utcnow():
'''Create a representation of the time right now, in UTC.'''
- dt = datetime.utcnow()
- return dt.replace(tzinfo = timezone.utc)
+ return datetime.now(timezone.utc)
def enable_automatic_media_scan(args):
'''Decide if we enable media scanning automatically.'''
--
BOFH excuse #360:
Your parity check is overdrawn and you're out of cache.
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py
2025-08-26 13:15 xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py Christian Kujau
@ 2025-08-26 15:57 ` Darrick J. Wong
2025-08-26 16:06 ` xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py [v2] Christian Kujau
0 siblings, 1 reply; 4+ messages in thread
From: Darrick J. Wong @ 2025-08-26 15:57 UTC (permalink / raw)
To: Christian Kujau; +Cc: linux-xfs, Andrey Albershteyn
On Tue, Aug 26, 2025 at 03:15:42PM +0200, Christian Kujau wrote:
> Running xfs_scrub_all under Python 3.13.5 prints the following warning:
>
> ----------------------------------------------
> $ /usr/sbin/xfs_scrub_all --auto-media-scan-stamp \
> /var/lib/xfsprogs/xfs_scrub_all_media.stamp \
> --auto-media-scan-interval 1d
> /usr/sbin/xfs_scrub_all:489: DeprecationWarning:
> datetime.datetime.utcnow() is deprecated and scheduled for removal in a
> future version. Use timezone-aware objects to represent datetimes in UTC:
> datetime.datetime.now(datetime.UTC).
> dt = datetime.utcnow()
> Automatically enabling file data scrub.
> ----------------------------------------------
>
> Python documentation for context:
> https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow
>
> Fix this by using datetime.now() instead.
>
> NB: Debian/13 ships Python 3.13.5 and has a xfs_scrub_all.timer active,
> I'd assume that many systems will have that warning now in their logs :-)
>
> Signed-off-by: Christian Kujau <lists@nerdbynature.de>
Heh heh heh. That old code was for compatibility with RHEL6(?) back
when I started writing online fsck. That's indeed no longer needed
because even RHEL7 supports datetime.now, so thank you for the update!
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
>
> diff --git a/scrub/xfs_scrub_all.py.in b/scrub/xfs_scrub_all.py.in
> index 515cc144..a94b1b71 100644
> --- a/scrub/xfs_scrub_all.py.in
> +++ b/scrub/xfs_scrub_all.py.in
> @@ -496,8 +496,7 @@ def scan_interval(string):
> def utcnow():
> '''Create a representation of the time right now, in UTC.'''
>
> - dt = datetime.utcnow()
> - return dt.replace(tzinfo = timezone.utc)
> + return datetime.now(timezone.utc)
>
> def enable_automatic_media_scan(args):
> '''Decide if we enable media scanning automatically.'''
>
>
> --
> BOFH excuse #360:
>
> Your parity check is overdrawn and you're out of cache.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py [v2]
2025-08-26 15:57 ` Darrick J. Wong
@ 2025-08-26 16:06 ` Christian Kujau
2025-08-26 16:10 ` Darrick J. Wong
0 siblings, 1 reply; 4+ messages in thread
From: Christian Kujau @ 2025-08-26 16:06 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs, Andrey Albershteyn
On Tue, 26 Aug 2025, Darrick J. Wong wrote:
> Heh heh heh. That old code was for compatibility with RHEL6(?) back
> when I started writing online fsck. That's indeed no longer needed
> because even RHEL7 supports datetime.now, so thank you for the update!
Thanks for providing the context. Scrolling through that whole script I'd
say the helper function is not even needed anymore. So, if it's not too
much hassle, here's a version 2 of the same:
Signed-off-by: Christian Kujau <lists@nerdbynature.de>
Thanks!
diff --git a/scrub/xfs_scrub_all.py.in b/scrub/xfs_scrub_all.py.in
index 515cc144..ce251dae 100644
--- a/scrub/xfs_scrub_all.py.in
+++ b/scrub/xfs_scrub_all.py.in
@@ -493,12 +493,6 @@ def scan_interval(string):
return timedelta(seconds = float(string[:-1]))
return timedelta(seconds = int(string))
-def utcnow():
- '''Create a representation of the time right now, in UTC.'''
-
- dt = datetime.utcnow()
- return dt.replace(tzinfo = timezone.utc)
-
def enable_automatic_media_scan(args):
'''Decide if we enable media scanning automatically.'''
already_enabled = args.x
@@ -515,7 +509,7 @@ def enable_automatic_media_scan(args):
else:
try:
last_run = p.stat().st_mtime
- now = utcnow().timestamp()
+ now = datetime.now(timezone.utc).timestamp()
res = last_run + interval.total_seconds() < now
except FileNotFoundError:
res = True
--
BOFH excuse #72:
Satan did it
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py [v2]
2025-08-26 16:06 ` xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py [v2] Christian Kujau
@ 2025-08-26 16:10 ` Darrick J. Wong
0 siblings, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2025-08-26 16:10 UTC (permalink / raw)
To: Christian Kujau; +Cc: linux-xfs, Andrey Albershteyn
On Tue, Aug 26, 2025 at 06:06:26PM +0200, Christian Kujau wrote:
> On Tue, 26 Aug 2025, Darrick J. Wong wrote:
> > Heh heh heh. That old code was for compatibility with RHEL6(?) back
> > when I started writing online fsck. That's indeed no longer needed
> > because even RHEL7 supports datetime.now, so thank you for the update!
>
> Thanks for providing the context. Scrolling through that whole script I'd
> say the helper function is not even needed anymore. So, if it's not too
> much hassle, here's a version 2 of the same:
>
> Signed-off-by: Christian Kujau <lists@nerdbynature.de>
That also works for me--
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
>
> Thanks!
>
> diff --git a/scrub/xfs_scrub_all.py.in b/scrub/xfs_scrub_all.py.in
> index 515cc144..ce251dae 100644
> --- a/scrub/xfs_scrub_all.py.in
> +++ b/scrub/xfs_scrub_all.py.in
> @@ -493,12 +493,6 @@ def scan_interval(string):
> return timedelta(seconds = float(string[:-1]))
> return timedelta(seconds = int(string))
>
> -def utcnow():
> - '''Create a representation of the time right now, in UTC.'''
> -
> - dt = datetime.utcnow()
> - return dt.replace(tzinfo = timezone.utc)
> -
> def enable_automatic_media_scan(args):
> '''Decide if we enable media scanning automatically.'''
> already_enabled = args.x
> @@ -515,7 +509,7 @@ def enable_automatic_media_scan(args):
> else:
> try:
> last_run = p.stat().st_mtime
> - now = utcnow().timestamp()
> + now = datetime.now(timezone.utc).timestamp()
> res = last_run + interval.total_seconds() < now
> except FileNotFoundError:
> res = True
>
> --
> BOFH excuse #72:
>
> Satan did it
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-26 16:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26 13:15 xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py Christian Kujau
2025-08-26 15:57 ` Darrick J. Wong
2025-08-26 16:06 ` xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py [v2] Christian Kujau
2025-08-26 16:10 ` Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox