From 3f3212838f8fb7d6c84892f1d6594eed6e46441d Mon Sep 17 00:00:00 2001 From: purplerain Date: Sun, 4 Feb 2024 06:16:28 +0000 Subject: [PATCH] sync with OpenBSD -current --- bin/ps/ps.1 | 5 +- distrib/special/sysctl/sysctl.c | 6 +- gnu/llvm/lld/ELF/Arch/AArch64.cpp | 4 +- gnu/llvm/lld/ELF/Arch/X86_64.cpp | 5 + gnu/llvm/lld/ELF/SyntheticSections.cpp | 4 + gnu/llvm/lld/ELF/Writer.cpp | 6 + lib/libssl/s3_lib.c | 86 +- lib/libssl/ssl.h | 11 +- lib/libssl/ssl3.h | 4 +- lib/libssl/ssl_both.c | 5 +- lib/libssl/ssl_cert.c | 6 +- lib/libssl/ssl_ciph.c | 107 +- lib/libssl/ssl_clnt.c | 212 +- lib/libssl/ssl_err.c | 3 +- lib/libssl/ssl_lib.c | 10 +- lib/libssl/ssl_local.h | 20 +- lib/libssl/ssl_sigalgs.c | 28 +- lib/libssl/ssl_sigalgs.h | 10 +- lib/libssl/ssl_srvr.c | 150 +- lib/libssl/tls1.h | 10 +- lib/libssl/tls12_key_schedule.c | 6 +- lib/libssl/tls12_record_layer.c | 43 +- lib/libssl/tls13_handshake.c | 26 +- regress/lib/libssl/client/clienttest.c | 226 +- regress/lib/libssl/interop/Makefile.inc | 15 +- regress/lib/libssl/interop/cipher/Makefile | 15 +- regress/lib/libssl/unit/tls_prf.c | 48 +- sbin/dump/traverse.c | 26 +- sbin/dumpfs/dumpfs.c | 6 +- sbin/fsck_ffs/dir.c | 6 +- sbin/fsck_ffs/fsck.h | 3 +- sbin/fsck_ffs/main.c | 5 +- sbin/fsck_ffs/pass1.c | 27 +- sbin/fsck_ffs/pass2.c | 15 +- sbin/fsck_ffs/pass5.c | 30 +- sbin/fsck_ffs/setup.c | 6 +- sbin/growfs/growfs.c | 7 +- sbin/iked/policy.c | 4 +- sbin/quotacheck/quotacheck.c | 26 +- sbin/slaacd/engine.c | 4 +- share/man/man5/fs.5 | 8 +- sys/arch/amd64/amd64/cacheinfo.c | 12 +- sys/arch/amd64/amd64/cpu.c | 5 +- sys/arch/amd64/amd64/machdep.c | 4 +- sys/arch/amd64/include/cpu.h | 6 +- sys/arch/arm64/dev/acpipci.c | 5 +- sys/arch/arm64/dev/agintc.c | 14 +- sys/arch/arm64/dev/aplpcie.c | 4 +- sys/arch/arm64/dev/pci_machdep.c | 61 +- sys/arch/arm64/include/pci_machdep.h | 10 +- sys/conf/files | 4 +- sys/ddb/db_interface.h | 7 +- sys/dev/fdt/bcm2711_pcie.c | 3 +- sys/dev/fdt/dwpcie.c | 8 +- sys/dev/fdt/mvkpcie.c | 5 +- sys/dev/fdt/pciecam.c | 5 +- sys/dev/fdt/rkpcie.c | 5 +- sys/dev/ic/qwx.c | 533 +- sys/dev/ic/qwxreg.h | 12 +- sys/dev/ic/qwxvar.h | 60 +- sys/dev/pci/drm/drm_edid.c | 4 +- sys/dev/pci/if_qwx_pci.c | 6 +- sys/dev/pci/pcivar.h | 16 +- sys/dev/softraid.c | 5 +- sys/kern/kern_physio.c | 3 +- sys/kern/spec_vnops.c | 5 +- sys/kern/uipc_socket.c | 189 +- sys/kern/uipc_socket2.c | 70 +- sys/kern/uipc_syscalls.c | 4 +- sys/kern/vfs_bio.c | 29 +- sys/kern/vfs_subr.c | 14 +- sys/kern/vfs_sync.c | 49 +- sys/kern/vfs_syscalls.c | 6 +- sys/miscfs/fifofs/fifo_vnops.c | 61 +- sys/netinet/ip_divert.c | 11 +- sys/netinet/ip_divert.h | 3 +- sys/netinet/ip_var.h | 3 +- sys/netinet/raw_ip.c | 11 +- sys/netinet/udp_usrreq.c | 12 +- sys/netinet/udp_var.h | 3 +- sys/netinet6/ip6_divert.c | 3 +- sys/netinet6/ip6_mroute.c | 8 +- sys/netinet6/ip6_var.h | 3 +- sys/netinet6/raw_ip6.c | 11 +- sys/sys/buf.h | 60 +- sys/sys/mount.h | 3 +- sys/sys/mutex.h | 5 +- sys/sys/proc.h | 3 +- sys/sys/protosw.h | 11 +- sys/sys/socketvar.h | 22 +- sys/sys/vnode.h | 3 +- sys/ufs/ffs/ffs_alloc.c | 22 +- sys/ufs/ffs/ffs_balloc.c | 121 +- sys/ufs/ffs/ffs_extern.h | 26 +- sys/ufs/ffs/ffs_inode.c | 42 +- sys/ufs/ffs/ffs_softdep.c | 5766 -------------------- sys/ufs/ffs/ffs_softdep_stub.c | 193 - sys/ufs/ffs/ffs_vfsops.c | 150 +- sys/ufs/ffs/ffs_vnops.c | 17 +- sys/ufs/ffs/fs.h | 3 +- sys/ufs/ffs/softdep.h | 590 -- sys/ufs/ufs/inode.h | 7 +- sys/ufs/ufs/ufs_extern.h | 17 +- sys/ufs/ufs/ufs_inode.c | 17 +- sys/ufs/ufs/ufs_lookup.c | 112 +- sys/ufs/ufs/ufs_vnops.c | 93 +- sys/uvm/uvm_swap.c | 4 +- usr.bin/openssl/openssl.c | 8 +- usr.sbin/bgpd/rde_peer.c | 4 +- usr.sbin/rpki-client/cert.c | 12 +- usr.sbin/rpki-client/extern.h | 5 +- usr.sbin/rpki-client/main.c | 13 +- usr.sbin/rpki-client/mft.c | 9 +- usr.sbin/rpki-client/output-json.c | 6 +- usr.sbin/rpki-client/output-ometric.c | 6 +- usr.sbin/rpki-client/output.c | 5 +- usr.sbin/rpki-client/parser.c | 11 +- usr.sbin/rpki-client/repo.c | 4 +- usr.sbin/smtpd/parse.y | 3 +- usr.sbin/smtpd/smtpd.c | 5 +- usr.sbin/smtpd/smtpd.conf.5 | 8 +- usr.sbin/vmd/vionet.c | 21 +- 122 files changed, 1363 insertions(+), 8580 deletions(-) diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 51e6b6740..2f0010597 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ps.1,v 1.133 2024/01/28 19:05:33 deraadt Exp $ +.\" $OpenBSD: ps.1,v 1.134 2024/02/03 18:51:57 beck Exp $ .\" $NetBSD: ps.1,v 1.16 1996/03/21 01:36:28 jtc Exp $ .\" .\" Copyright (c) 1980, 1990, 1991, 1993, 1994 @@ -30,7 +30,7 @@ .\" .\" @(#)ps.1 8.3 (Berkeley) 4/18/94 .\" -.Dd $Mdocdate: January 28 2024 $ +.Dd $Mdocdate: February 3 2024 $ .Dt PS 1 .Os .Sh NAME @@ -242,7 +242,6 @@ P_SUSPSINGLE 0x80000 need to suspend for single threading P_CONTINUED 0x800000 thread has continued after a stop P_THREAD 0x4000000 not the original thread P_SUSPSIG 0x8000000 stopped because of a signal -P_SOFTDEP 0x10000000 stuck processing softdep worklist P_CPUPEG 0x40000000 do not move to another cpu .Ed .It Cm gid diff --git a/distrib/special/sysctl/sysctl.c b/distrib/special/sysctl/sysctl.c index e7e946c35..41d198561 100644 --- a/distrib/special/sysctl/sysctl.c +++ b/distrib/special/sysctl/sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.c,v 1.15 2023/05/22 09:29:54 kn Exp $ */ +/* $OpenBSD: sysctl.c,v 1.16 2024/02/03 16:21:20 deraadt Exp $ */ /* * Copyright (c) 2009 Theo de Raadt @@ -58,6 +58,10 @@ struct var vars[] = { { CTL_HW, HW_DISKNAMES }}, { "hw.ncpufound", pint, 2, { CTL_HW, HW_NCPUFOUND }}, +#ifdef __amd64__ + { "machdep.retpoline", pint, 2, + { CTL_MACHDEP, CPU_RETPOLINE }}, +#endif #ifdef CPU_COMPATIBLE { "machdep.compatible", pstring, 2, { CTL_MACHDEP, CPU_COMPATIBLE }}, diff --git a/gnu/llvm/lld/ELF/Arch/AArch64.cpp b/gnu/llvm/lld/ELF/Arch/AArch64.cpp index dcea062c5..5ba8b5273 100644 --- a/gnu/llvm/lld/ELF/Arch/AArch64.cpp +++ b/gnu/llvm/lld/ELF/Arch/AArch64.cpp @@ -836,7 +836,7 @@ private: } // namespace AArch64BtiPac::AArch64BtiPac() { -#ifdef __OpenBSD__ +#ifdef __SecBSD__ btiHeader = true; #else btiHeader = (config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI); @@ -941,7 +941,7 @@ void AArch64BtiPac::writePlt(uint8_t *buf, const Symbol &sym, } static TargetInfo *getTargetInfo() { -#ifdef __OpenBSD__ +#ifdef __SecBSD__ static AArch64BtiPac t; return &t; #else diff --git a/gnu/llvm/lld/ELF/Arch/X86_64.cpp b/gnu/llvm/lld/ELF/Arch/X86_64.cpp index a44c2fe0b..0837ccf15 100644 --- a/gnu/llvm/lld/ELF/Arch/X86_64.cpp +++ b/gnu/llvm/lld/ELF/Arch/X86_64.cpp @@ -1186,6 +1186,10 @@ static TargetInfo *getTargetInfo() { return &t; } +#ifdef __SecBSD__ + static IntelIBT t; + return &t; +#else if (config->andFeatures & GNU_PROPERTY_X86_FEATURE_1_IBT) { static IntelIBT t; return &t; @@ -1193,6 +1197,7 @@ static TargetInfo *getTargetInfo() { static X86_64 t; return &t; +#endif } TargetInfo *elf::getX86_64TargetInfo() { return getTargetInfo(); } diff --git a/gnu/llvm/lld/ELF/SyntheticSections.cpp b/gnu/llvm/lld/ELF/SyntheticSections.cpp index e7c437bc7..1408a14ab 100644 --- a/gnu/llvm/lld/ELF/SyntheticSections.cpp +++ b/gnu/llvm/lld/ELF/SyntheticSections.cpp @@ -2500,6 +2500,10 @@ PltSection::PltSection() if ((config->emachine == EM_386 || config->emachine == EM_X86_64) && (config->andFeatures & GNU_PROPERTY_X86_FEATURE_1_IBT)) name = ".plt.sec"; +#ifdef __SecBSD__ + else if (config->emachine == EM_X86_64) + name = ".plt.sec"; +#endif // The PLT needs to be writable on SPARC as the dynamic linker will // modify the instructions in the PLT entries. diff --git a/gnu/llvm/lld/ELF/Writer.cpp b/gnu/llvm/lld/ELF/Writer.cpp index 3bba1b62d..264a021cd 100644 --- a/gnu/llvm/lld/ELF/Writer.cpp +++ b/gnu/llvm/lld/ELF/Writer.cpp @@ -489,6 +489,12 @@ template void elf::createSyntheticSections() { in.ibtPlt = std::make_unique(); add(*in.ibtPlt); } +#ifdef __SecBSD__ + else if (config->emachine == EM_X86_64) { + in.ibtPlt = std::make_unique(); + add(*in.ibtPlt); + } +#endif if (config->emachine == EM_PPC) in.plt = std::make_unique(); diff --git a/lib/libssl/s3_lib.c b/lib/libssl/s3_lib.c index 1ae2d047b..bb8e9465b 100644 --- a/lib/libssl/s3_lib.c +++ b/lib/libssl/s3_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s3_lib.c,v 1.248 2023/11/29 13:39:34 tb Exp $ */ +/* $OpenBSD: s3_lib.c,v 1.249 2024/02/03 15:58:33 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -577,41 +577,6 @@ const SSL_CIPHER ssl3_ciphers[] = { .alg_bits = 256, }, - /* GOST Ciphersuites */ - - /* Cipher 81 */ - { - .valid = 1, - .name = "GOST2001-GOST89-GOST89", - .id = 0x3000081, - .algorithm_mkey = SSL_kGOST, - .algorithm_auth = SSL_aGOST01, - .algorithm_enc = SSL_eGOST2814789CNT, - .algorithm_mac = SSL_GOST89MAC, - .algorithm_ssl = SSL_TLSV1, - .algo_strength = SSL_HIGH, - .algorithm2 = SSL_HANDSHAKE_MAC_GOST94|TLS1_PRF_GOST94| - TLS1_STREAM_MAC, - .strength_bits = 256, - .alg_bits = 256 - }, - - /* Cipher 83 */ - { - .valid = 1, - .name = "GOST2001-NULL-GOST94", - .id = 0x3000083, - .algorithm_mkey = SSL_kGOST, - .algorithm_auth = SSL_aGOST01, - .algorithm_enc = SSL_eNULL, - .algorithm_mac = SSL_GOST94, - .algorithm_ssl = SSL_TLSV1, - .algo_strength = SSL_STRONG_NONE, - .algorithm2 = SSL_HANDSHAKE_MAC_GOST94|TLS1_PRF_GOST94, - .strength_bits = 0, - .alg_bits = 0 - }, - #ifndef OPENSSL_NO_CAMELLIA /* Camellia ciphersuites from RFC4132 (256-bit portion) */ @@ -1362,40 +1327,6 @@ const SSL_CIPHER ssl3_ciphers[] = { .alg_bits = 256, }, - /* Cipher FF85 FIXME IANA */ - { - .valid = 1, - .name = "GOST2012256-GOST89-GOST89", - .id = 0x300ff85, /* FIXME IANA */ - .algorithm_mkey = SSL_kGOST, - .algorithm_auth = SSL_aGOST01, - .algorithm_enc = SSL_eGOST2814789CNT, - .algorithm_mac = SSL_GOST89MAC, - .algorithm_ssl = SSL_TLSV1, - .algo_strength = SSL_HIGH, - .algorithm2 = SSL_HANDSHAKE_MAC_STREEBOG256|TLS1_PRF_STREEBOG256| - TLS1_STREAM_MAC, - .strength_bits = 256, - .alg_bits = 256 - }, - - /* Cipher FF87 FIXME IANA */ - { - .valid = 1, - .name = "GOST2012256-NULL-STREEBOG256", - .id = 0x300ff87, /* FIXME IANA */ - .algorithm_mkey = SSL_kGOST, - .algorithm_auth = SSL_aGOST01, - .algorithm_enc = SSL_eNULL, - .algorithm_mac = SSL_STREEBOG256, - .algorithm_ssl = SSL_TLSV1, - .algo_strength = SSL_STRONG_NONE, - .algorithm2 = SSL_HANDSHAKE_MAC_STREEBOG256|TLS1_PRF_STREEBOG256, - .strength_bits = 0, - .alg_bits = 0 - }, - - /* end of list */ }; @@ -2668,21 +2599,6 @@ ssl3_get_req_cert_types(SSL *s, CBB *cbb) alg_k = s->s3->hs.cipher->algorithm_mkey; -#ifndef OPENSSL_NO_GOST - if ((alg_k & SSL_kGOST) != 0) { - if (!CBB_add_u8(cbb, TLS_CT_GOST01_SIGN)) - return 0; - if (!CBB_add_u8(cbb, TLS_CT_GOST12_256_SIGN)) - return 0; - if (!CBB_add_u8(cbb, TLS_CT_GOST12_512_SIGN)) - return 0; - if (!CBB_add_u8(cbb, TLS_CT_GOST12_256_SIGN_COMPAT)) - return 0; - if (!CBB_add_u8(cbb, TLS_CT_GOST12_512_SIGN_COMPAT)) - return 0; - } -#endif - if ((alg_k & SSL_kDHE) != 0) { if (!CBB_add_u8(cbb, SSL3_CT_RSA_FIXED_DH)) return 0; diff --git a/lib/libssl/ssl.h b/lib/libssl/ssl.h index 8d65a1ec0..03a5a80d0 100644 --- a/lib/libssl/ssl.h +++ b/lib/libssl/ssl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl.h,v 1.232 2023/11/22 15:43:42 tb Exp $ */ +/* $OpenBSD: ssl.h,v 1.233 2024/02/03 15:58:33 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -245,7 +245,6 @@ extern "C" { #define SSL_TXT_kECDH "kECDH" #define SSL_TXT_kEECDH "kEECDH" #define SSL_TXT_kPSK "kPSK" -#define SSL_TXT_kGOST "kGOST" #define SSL_TXT_kSRP "kSRP" #define SSL_TXT_aRSA "aRSA" @@ -255,9 +254,6 @@ extern "C" { #define SSL_TXT_aKRB5 "aKRB5" #define SSL_TXT_aECDSA "aECDSA" #define SSL_TXT_aPSK "aPSK" -#define SSL_TXT_aGOST94 "aGOST94" -#define SSL_TXT_aGOST01 "aGOST01" -#define SSL_TXT_aGOST "aGOST" #define SSL_TXT_DSS "DSS" #define SSL_TXT_DH "DH" @@ -293,12 +289,8 @@ extern "C" { #define SSL_TXT_MD5 "MD5" #define SSL_TXT_SHA1 "SHA1" #define SSL_TXT_SHA "SHA" /* same as "SHA1" */ -#define SSL_TXT_GOST94 "GOST94" -#define SSL_TXT_GOST89MAC "GOST89MAC" #define SSL_TXT_SHA256 "SHA256" #define SSL_TXT_SHA384 "SHA384" -#define SSL_TXT_STREEBOG256 "STREEBOG256" -#define SSL_TXT_STREEBOG512 "STREEBOG512" #define SSL_TXT_DTLS1 "DTLSv1" #define SSL_TXT_DTLS1_2 "DTLSv1.2" @@ -2176,7 +2168,6 @@ void ERR_load_SSL_strings(void); #define SSL_R_NO_CLIENT_CERT_METHOD 331 #define SSL_R_NO_CLIENT_CERT_RECEIVED 186 #define SSL_R_NO_COMPRESSION_SPECIFIED 187 -#define SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER 330 #define SSL_R_NO_METHOD_SPECIFIED 188 #define SSL_R_NO_PRIVATEKEY 189 #define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190 diff --git a/lib/libssl/ssl3.h b/lib/libssl/ssl3.h index 6c6cc2ad2..603d9ccb4 100644 --- a/lib/libssl/ssl3.h +++ b/lib/libssl/ssl3.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl3.h,v 1.57 2021/09/10 14:49:13 tb Exp $ */ +/* $OpenBSD: ssl3.h,v 1.58 2024/02/03 15:58:33 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -325,7 +325,7 @@ extern "C" { * enough to contain all of the cert types defined either for * SSLv3 and TLSv1. */ -#define SSL3_CT_NUMBER 13 +#define SSL3_CT_NUMBER 7 #define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 #define TLS1_FLAGS_SKIP_CERT_VERIFY 0x0010 diff --git a/lib/libssl/ssl_both.c b/lib/libssl/ssl_both.c index 14d9aa85a..995f1c460 100644 --- a/lib/libssl/ssl_both.c +++ b/lib/libssl/ssl_both.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_both.c,v 1.46 2023/07/07 08:53:55 tb Exp $ */ +/* $OpenBSD: ssl_both.c,v 1.47 2024/02/03 15:58:33 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -384,9 +384,6 @@ ssl_cert_type(EVP_PKEY *pkey) switch (EVP_PKEY_id(pkey)) { case EVP_PKEY_EC: return SSL_PKEY_ECC; - case NID_id_GostR3410_2001: - case NID_id_GostR3410_2001_cc: - return SSL_PKEY_GOST01; case EVP_PKEY_RSA: case EVP_PKEY_RSA_PSS: return SSL_PKEY_RSA; diff --git a/lib/libssl/ssl_cert.c b/lib/libssl/ssl_cert.c index a28805026..5b2fe1a48 100644 --- a/lib/libssl/ssl_cert.c +++ b/lib/libssl/ssl_cert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_cert.c,v 1.107 2023/07/08 16:40:13 beck Exp $ */ +/* $OpenBSD: ssl_cert.c,v 1.108 2024/02/03 15:58:33 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -233,10 +233,6 @@ ssl_cert_dup(SSL_CERT *cert) /* We have an ECC key */ break; - case SSL_PKEY_GOST01: - /* We have a GOST key */ - break; - default: /* Can't happen. */ SSLerrorx(SSL_R_LIBRARY_BUG); diff --git a/lib/libssl/ssl_ciph.c b/lib/libssl/ssl_ciph.c index cea4d3e6f..76a384052 100644 --- a/lib/libssl/ssl_ciph.c +++ b/lib/libssl/ssl_ciph.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_ciph.c,v 1.138 2024/01/04 20:02:10 tb Exp $ */ +/* $OpenBSD: ssl_ciph.c,v 1.139 2024/02/03 15:58:33 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -212,10 +212,6 @@ static const SSL_CIPHER cipher_aliases[] = { .name = SSL_TXT_ECDH, .algorithm_mkey = SSL_kECDHE, }, - { - .name = SSL_TXT_kGOST, - .algorithm_mkey = SSL_kGOST, - }, /* server authentication aliases */ { @@ -242,14 +238,6 @@ static const SSL_CIPHER cipher_aliases[] = { .name = SSL_TXT_ECDSA, .algorithm_auth = SSL_aECDSA, }, - { - .name = SSL_TXT_aGOST01, - .algorithm_auth = SSL_aGOST01, - }, - { - .name = SSL_TXT_aGOST, - .algorithm_auth = SSL_aGOST01, - }, /* aliases combining key exchange and server authentication */ { @@ -355,14 +343,6 @@ static const SSL_CIPHER cipher_aliases[] = { .name = SSL_TXT_SHA, .algorithm_mac = SSL_SHA1, }, - { - .name = SSL_TXT_GOST94, - .algorithm_mac = SSL_GOST94, - }, - { - .name = SSL_TXT_GOST89MAC, - .algorithm_mac = SSL_GOST89MAC, - }, { .name = SSL_TXT_SHA256, .algorithm_mac = SSL_SHA256, @@ -371,10 +351,6 @@ static const SSL_CIPHER cipher_aliases[] = { .name = SSL_TXT_SHA384, .algorithm_mac = SSL_SHA384, }, - { - .name = SSL_TXT_STREEBOG256, - .algorithm_mac = SSL_STREEBOG256, - }, /* protocol version aliases */ { @@ -472,11 +448,6 @@ ssl_cipher_get_evp(const SSL_SESSION *ss, const EVP_CIPHER **enc, case SSL_CAMELLIA256: *enc = EVP_camellia_256_cbc(); break; -#ifndef OPENSSL_NO_GOST - case SSL_eGOST2814789CNT: - *enc = EVP_gost2814789_cnt(); - break; -#endif } switch (ss->cipher->algorithm_mac) { @@ -492,21 +463,11 @@ ssl_cipher_get_evp(const SSL_SESSION *ss, const EVP_CIPHER **enc, case SSL_SHA384: *md = EVP_sha384(); break; -#ifndef OPENSSL_NO_GOST - case SSL_GOST89MAC: - *md = EVP_gost2814789imit(); - break; - case SSL_GOST94: - *md = EVP_gostr341194(); - break; - case SSL_STREEBOG256: - *md = EVP_streebog256(); - break; -#endif } if (*enc == NULL || *md == NULL) return 0; + /* XXX remove these from ssl_cipher_get_evp? */ /* * EVP_CIPH_FLAG_AEAD_CIPHER and EVP_CIPH_GCM_MODE ciphers are not * supported via EVP_CIPHER (they should be using EVP_AEAD instead). @@ -515,18 +476,9 @@ ssl_cipher_get_evp(const SSL_SESSION *ss, const EVP_CIPHER **enc, return 0; if (EVP_CIPHER_mode(*enc) == EVP_CIPH_GCM_MODE) return 0; -#ifndef OPENSSL_NO_GOST - /* XXX JFC. die in fire already */ - if (ss->cipher->algorithm_mac == SSL_GOST89MAC) { - *mac_pkey_type = EVP_PKEY_GOSTIMIT; - *mac_secret_size = 32; /* XXX */ - } else { -#endif - *mac_pkey_type = EVP_PKEY_HMAC; - *mac_secret_size = EVP_MD_size(*md); -#ifndef OPENSSL_NO_GOST - } -#endif + + *mac_pkey_type = EVP_PKEY_HMAC; + *mac_secret_size = EVP_MD_size(*md); return 1; } @@ -581,14 +533,6 @@ ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md) case SSL_HANDSHAKE_MAC_DEFAULT: *md = EVP_md5_sha1(); return 1; -#ifndef OPENSSL_NO_GOST - case SSL_HANDSHAKE_MAC_GOST94: - *md = EVP_gostr341194(); - return 1; - case SSL_HANDSHAKE_MAC_STREEBOG256: - *md = EVP_streebog256(); - return 1; -#endif case SSL_HANDSHAKE_MAC_SHA256: *md = EVP_sha256(); return 1; @@ -641,6 +585,7 @@ ll_append_head(CIPHER_ORDER **head, CIPHER_ORDER *curr, *head = curr; } +/* XXX beck: remove this in a followon to removing GOST */ static void ssl_cipher_get_disabled(unsigned long *mkey, unsigned long *auth, unsigned long *enc, unsigned long *mac, unsigned long *ssl) @@ -651,16 +596,6 @@ ssl_cipher_get_disabled(unsigned long *mkey, unsigned long *auth, *mac = 0; *ssl = 0; - /* - * Check for the availability of GOST 34.10 public/private key - * algorithms. If they are not available disable the associated - * authentication and key exchange algorithms. - */ -#if defined(OPENSSL_NO_GOST) || !defined(EVP_PKEY_GOSTR01) - *auth |= SSL_aGOST01; - *mkey |= SSL_kGOST; -#endif - #ifdef SSL_FORBID_ENULL *enc |= SSL_eNULL; #endif @@ -1455,9 +1390,6 @@ SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len) case SSL_kECDHE: kx = "ECDH"; break; - case SSL_kGOST: - kx = "GOST"; - break; case SSL_kTLS1_3: kx = "TLSv1.3"; break; @@ -1478,9 +1410,6 @@ SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len) case SSL_aECDSA: au = "ECDSA"; break; - case SSL_aGOST01: - au = "GOST01"; - break; case SSL_aTLS1_3: au = "TLSv1.3"; break; @@ -1520,9 +1449,6 @@ SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len) case SSL_CHACHA20POLY1305: enc = "ChaCha20-Poly1305"; break; - case SSL_eGOST2814789CNT: - enc = "GOST-28178-89-CNT"; - break; default: enc = "unknown"; break; @@ -1544,15 +1470,6 @@ SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len) case SSL_AEAD: mac = "AEAD"; break; - case SSL_GOST94: - mac = "GOST94"; - break; - case SSL_GOST89MAC: - mac = "GOST89IMIT"; - break; - case SSL_STREEBOG256: - mac = "STREEBOG256"; - break; default: mac = "unknown"; break; @@ -1666,8 +1583,6 @@ SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c) return NID_des_cbc; case SSL_RC4: return NID_rc4; - case SSL_eGOST2814789CNT: - return NID_gost89_cnt; default: return NID_undef; } @@ -1680,10 +1595,6 @@ SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c) switch (c->algorithm_mac) { case SSL_AEAD: return NID_undef; - case SSL_GOST89MAC: - return NID_id_Gost28147_89_MAC; - case SSL_GOST94: - return NID_id_GostR3411_94; case SSL_MD5: return NID_md5; case SSL_SHA1: @@ -1692,8 +1603,6 @@ SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c) return NID_sha256; case SSL_SHA384: return NID_sha384; - case SSL_STREEBOG256: - return NID_id_tc26_gost3411_2012_256; default: return NID_undef; } @@ -1708,8 +1617,6 @@ SSL_CIPHER_get_kx_nid(const SSL_CIPHER *c) return NID_kx_dhe; case SSL_kECDHE: return NID_kx_ecdhe; - case SSL_kGOST: - return NID_kx_gost; case SSL_kRSA: return NID_kx_rsa; default: @@ -1726,8 +1633,6 @@ SSL_CIPHER_get_auth_nid(const SSL_CIPHER *c) return NID_auth_null; case SSL_aECDSA: return NID_auth_ecdsa; - case SSL_aGOST01: - return NID_auth_gost01; case SSL_aRSA: return NID_auth_rsa; default: diff --git a/lib/libssl/ssl_clnt.c b/lib/libssl/ssl_clnt.c index ae90d6f52..0903f7ea2 100644 --- a/lib/libssl/ssl_clnt.c +++ b/lib/libssl/ssl_clnt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_clnt.c,v 1.163 2023/12/29 12:24:33 tb Exp $ */ +/* $OpenBSD: ssl_clnt.c,v 1.165 2024/02/03 18:03:49 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -161,10 +161,6 @@ #include #include -#ifndef OPENSSL_NO_GOST -#include -#endif - #include "bytestring.h" #include "dtls_local.h" #include "ssl_local.h" @@ -459,12 +455,6 @@ ssl3_connect(SSL *s) s->s3->hs.state = SSL3_ST_CW_CHANGE_A; s->s3->change_cipher_spec = 0; } - if (!SSL_is_dtls(s)) { - if (s->s3->flags & TLS1_FLAGS_SKIP_CERT_VERIFY) { - s->s3->hs.state = SSL3_ST_CW_CHANGE_A; - s->s3->change_cipher_spec = 0; - } - } s->init_num = 0; break; @@ -829,7 +819,6 @@ ssl3_get_server_hello(SSL *s) uint8_t compression_method; const SSL_CIPHER *cipher; const SSL_METHOD *method; - unsigned long alg_k; int al, ret; s->first_packet = 1; @@ -1038,8 +1027,7 @@ ssl3_get_server_hello(SSL *s) * Don't digest cached records if no sigalgs: we may need them for * client authentication. */ - alg_k = s->s3->hs.cipher->algorithm_mkey; - if (!(SSL_USE_SIGALGS(s) || (alg_k & SSL_kGOST))) + if (!SSL_USE_SIGALGS(s)) tls1_transcript_free(s); if (!CBS_get_u8(&cbs, &compression_method)) @@ -1930,119 +1918,6 @@ ssl3_send_client_kex_ecdhe(SSL *s, CBB *cbb) return ret; } -static int -ssl3_send_client_kex_gost(SSL *s, CBB *cbb) -{ - unsigned char premaster_secret[32], shared_ukm[32], tmp[256]; - EVP_PKEY_CTX *pkey_ctx = NULL; - EVP_MD_CTX *ukm_hash = NULL; - EVP_PKEY *pkey; - size_t msglen; - unsigned int md_len; - CBB gostblob; - int nid; - int ret = 0; - - /* Get server certificate PKEY and create ctx from it */ - pkey = X509_get0_pubkey(s->session->peer_cert); - if (pkey == NULL || s->session->peer_cert_type != SSL_PKEY_GOST01) { - SSLerror(s, SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER); - goto err; - } - if ((pkey_ctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL) { - SSLerror(s, ERR_R_MALLOC_FAILURE); - goto err; - } - - /* - * If we have send a certificate, and certificate key parameters match - * those of server certificate, use certificate key for key exchange. - * Otherwise, generate ephemeral key pair. - */ - if (EVP_PKEY_encrypt_init(pkey_ctx) <= 0) - goto err; - - /* Generate session key. */ - arc4random_buf(premaster_secret, sizeof(premaster_secret)); - - /* - * If we have client certificate, use its secret as peer key. - * XXX - this presumably lacks PFS. - */ - if (s->s3->hs.tls12.cert_request != 0 && - s->cert->key->privatekey != NULL) { - if (EVP_PKEY_derive_set_peer(pkey_ctx, - s->cert->key->privatekey) <=0) { - /* - * If there was an error - just ignore it. - * Ephemeral key would be used. - */ - ERR_clear_error(); - } - } - - /* - * Compute shared IV and store it in algorithm-specific context data. - */ - if ((ukm_hash = EVP_MD_CTX_new()) == NULL) { - SSLerror(s, ERR_R_MALLOC_FAILURE); - goto err; - } - - /* XXX check handshake hash instead. */ - if (s->s3->hs.cipher->algorithm2 & SSL_HANDSHAKE_MAC_GOST94) - nid = NID_id_GostR3411_94; - else - nid = NID_id_tc26_gost3411_2012_256; - if (!EVP_DigestInit(ukm_hash, EVP_get_digestbynid(nid))) - goto err; - if (!EVP_DigestUpdate(ukm_hash, s->s3->client_random, SSL3_RANDOM_SIZE)) - goto err; - if (!EVP_DigestUpdate(ukm_hash, s->s3->server_random, SSL3_RANDOM_SIZE)) - goto err; - if (!EVP_DigestFinal_ex(ukm_hash, shared_ukm, &md_len)) - goto err; - if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, EVP_PKEY_OP_ENCRYPT, - EVP_PKEY_CTRL_SET_IV, 8, shared_ukm) < 0) { - SSLerror(s, SSL_R_LIBRARY_BUG); - goto err; - } - - /* - * Make GOST keytransport blob message, encapsulate it into sequence. - */ - msglen = 255; - if (EVP_PKEY_encrypt(pkey_ctx, tmp, &msglen, premaster_secret, - sizeof(premaster_secret)) < 0) { - SSLerror(s, SSL_R_LIBRARY_BUG); - goto err; - } - - if (!CBB_add_asn1(cbb, &gostblob, CBS_ASN1_SEQUENCE)) - goto err; - if (!CBB_add_bytes(&gostblob, tmp, msglen)) - goto err; - if (!CBB_flush(cbb)) - goto err; - - /* Check if pubkey from client certificate was used. */ - if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 2, - NULL) > 0) - s->s3->flags |= TLS1_FLAGS_SKIP_CERT_VERIFY; - - if (!tls12_derive_master_secret(s, premaster_secret, 32)) - goto err; - - ret = 1; - - err: - explicit_bzero(premaster_secret, sizeof(premaster_secret)); - EVP_PKEY_CTX_free(pkey_ctx); - EVP_MD_CTX_free(ukm_hash); - - return ret; -} - static int ssl3_send_client_key_exchange(SSL *s) { @@ -2067,9 +1942,6 @@ ssl3_send_client_key_exchange(SSL *s) } else if (alg_k & SSL_kECDHE) { if (!ssl3_send_client_kex_ecdhe(s, &kex)) goto err; - } else if (alg_k & SSL_kGOST) { - if (!ssl3_send_client_kex_gost(s, &kex)) - goto err; } else { ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); @@ -2115,14 +1987,6 @@ ssl3_send_client_verify_sigalgs(SSL *s, EVP_PKEY *pkey, SSLerror(s, ERR_R_EVP_LIB); goto err; } -#ifndef OPENSSL_NO_GOST - if (sigalg->key_type == EVP_PKEY_GOSTR01 && - EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN, - EVP_PKEY_CTRL_GOST_SIG_FORMAT, GOST_SIG_FORMAT_RS_LE, NULL) <= 0) { - SSLerror(s, ERR_R_EVP_LIB); - goto err; - } -#endif if ((sigalg->flags & SIGALG_FLAG_RSA_PSS) && (!EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING) || !EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, -1))) { @@ -2230,72 +2094,6 @@ ssl3_send_client_verify_ec(SSL *s, EVP_PKEY *pkey, CBB *cert_verify) return ret; } -#ifndef OPENSSL_NO_GOST -static int -ssl3_send_client_verify_gost(SSL *s, EVP_PKEY *pkey, CBB *cert_verify) -{ - CBB cbb_signature; - EVP_MD_CTX *mctx; - EVP_PKEY_CTX *pctx; - const EVP_MD *md; - const unsigned char *hdata; - unsigned char *signature = NULL; - size_t signature_len; - size_t hdata_len; - int nid; - int ret = 0; - - if ((mctx = EVP_MD_CTX_new()) == NULL) - goto err; - - if (!tls1_transcript_data(s, &hdata, &hdata_len)) { - SSLerror(s, ERR_R_INTERNAL_ERROR); - goto err; - } - if (!EVP_PKEY_get_default_digest_nid(pkey, &nid) || - (md = EVP_get_digestbynid(nid)) == NULL) { - SSLerror(s, ERR_R_EVP_LIB); - goto err; - } - if (!EVP_DigestSignInit(mctx, &pctx, md, NULL, pkey)) { - SSLerror(s, ERR_R_EVP_LIB); - goto err; - } -#ifndef OPENSSL_NO_GOST - if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN, - EVP_PKEY_CTRL_GOST_SIG_FORMAT, GOST_SIG_FORMAT_RS_LE, NULL) <= 0) { - SSLerror(s, ERR_R_EVP_LIB); - goto err; - } -#endif - if (!EVP_DigestSign(mctx, NULL, &signature_len, hdata, hdata_len)) { - SSLerror(s, ERR_R_EVP_LIB); - goto err; - } - if ((signature = calloc(1, signature_len)) == NULL) { - SSLerror(s, ERR_R_MALLOC_FAILURE); - goto err; - } - if (!EVP_DigestSign(mctx, signature, &signature_len, hdata, hdata_len)) { - SSLerror(s, ERR_R_EVP_LIB); - goto err; - } - - if (!CBB_add_u16_length_prefixed(cert_verify, &cbb_signature)) - goto err; - if (!CBB_add_bytes(&cbb_signature, signature, signature_len)) - goto err; - if (!CBB_flush(cert_verify)) - goto err; - - ret = 1; - err: - EVP_MD_CTX_free(mctx); - free(signature); - return ret; -} -#endif - static int ssl3_send_client_verify(SSL *s) { @@ -2331,12 +2129,6 @@ ssl3_send_client_verify(SSL *s) } else if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) { if (!ssl3_send_client_verify_ec(s, pkey, &cert_verify)) goto err; -#ifndef OPENSSL_NO_GOST - } else if (EVP_PKEY_id(pkey) == NID_id_GostR3410_94 || - EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) { - if (!ssl3_send_client_verify_gost(s, pkey, &cert_verify)) - goto err; -#endif } else { SSLerror(s, ERR_R_INTERNAL_ERROR); goto err; diff --git a/lib/libssl/ssl_err.c b/lib/libssl/ssl_err.c index 28097ea70..30ca96b2f 100644 --- a/lib/libssl/ssl_err.c +++ b/lib/libssl/ssl_err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_err.c,v 1.46 2023/07/08 16:40:13 beck Exp $ */ +/* $OpenBSD: ssl_err.c,v 1.47 2024/02/03 15:58:33 beck Exp $ */ /* ==================================================================== * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. * @@ -306,7 +306,6 @@ static ERR_STRING_DATA SSL_str_reasons[]= { {ERR_REASON(SSL_R_NO_CLIENT_CERT_METHOD) , "no client cert method"}, {ERR_REASON(SSL_R_NO_CLIENT_CERT_RECEIVED), "no client cert received"}, {ERR_REASON(SSL_R_NO_COMPRESSION_SPECIFIED), "no compression specified"}, - {ERR_REASON(SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER), "Peer haven't sent GOST certificate, required for selected ciphersuite"}, {ERR_REASON(SSL_R_NO_METHOD_SPECIFIED) , "no method specified"}, {ERR_REASON(SSL_R_NO_PRIVATEKEY) , "no privatekey"}, {ERR_REASON(SSL_R_NO_PRIVATE_KEY_ASSIGNED), "no private key assigned"}, diff --git a/lib/libssl/ssl_lib.c b/lib/libssl/ssl_lib.c index c97441c9c..0277202de 100644 --- a/lib/libssl/ssl_lib.c +++ b/lib/libssl/ssl_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_lib.c,v 1.318 2023/12/29 12:24:33 tb Exp $ */ +/* $OpenBSD: ssl_lib.c,v 1.319 2024/02/03 15:58:34 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -2297,12 +2297,6 @@ ssl_set_cert_masks(SSL_CERT *c, const SSL_CIPHER *cipher) mask_a |= SSL_aECDSA; } - cpk = &(c->pkeys[SSL_PKEY_GOST01]); - if (cpk->x509 != NULL && cpk->privatekey != NULL) { - mask_k |= SSL_kGOST; - mask_a |= SSL_aGOST01; - } - cpk = &(c->pkeys[SSL_PKEY_RSA]); if (cpk->x509 != NULL && cpk->privatekey != NULL) { mask_a |= SSL_aRSA; @@ -2363,8 +2357,6 @@ ssl_get_server_send_pkey(const SSL *s) i = SSL_PKEY_ECC; } else if (alg_a & SSL_aRSA) { i = SSL_PKEY_RSA; - } else if (alg_a & SSL_aGOST01) { - i = SSL_PKEY_GOST01; } else { /* if (alg_a & SSL_aNULL) */ SSLerror(s, ERR_R_INTERNAL_ERROR); return (NULL); diff --git a/lib/libssl/ssl_local.h b/lib/libssl/ssl_local.h index bd6275fac..b4d093b22 100644 --- a/lib/libssl/ssl_local.h +++ b/lib/libssl/ssl_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_local.h,v 1.12 2023/12/29 12:24:33 tb Exp $ */ +/* $OpenBSD: ssl_local.h,v 1.13 2024/02/03 15:58:34 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -197,7 +197,6 @@ __BEGIN_HIDDEN_DECLS #define SSL_kRSA 0x00000001L /* RSA key exchange */ #define SSL_kDHE 0x00000008L /* tmp DH key no DH cert */ #define SSL_kECDHE 0x00000080L /* ephemeral ECDH */ -#define SSL_kGOST 0x00000200L /* GOST key exchange */ #define SSL_kTLS1_3 0x00000400L /* TLSv1.3 key exchange */ /* Bits for algorithm_auth (server authentication) */ @@ -205,7 +204,6 @@ __BEGIN_HIDDEN_DECLS #define SSL_aDSS 0x00000002L /* DSS auth */ #define SSL_aNULL 0x00000004L /* no auth (i.e. use ADH or AECDH) */ #define SSL_aECDSA 0x00000040L /* ECDSA auth*/ -#define SSL_aGOST01 0x00000200L /* GOST R 34.10-2001 signature auth */ #define SSL_aTLS1_3 0x00000400L /* TLSv1.3 authentication */ /* Bits for algorithm_enc (symmetric encryption) */ @@ -218,7 +216,6 @@ __BEGIN_HIDDEN_DECLS #define SSL_AES256 0x00000040L #define SSL_CAMELLIA128 0x00000080L #define SSL_CAMELLIA256 0x00000100L -#define SSL_eGOST2814789CNT 0x00000200L #define SSL_AES128GCM 0x00000400L #define SSL_AES256GCM 0x00000800L #define SSL_CHACHA20POLY1305 0x00001000L @@ -231,8 +228,6 @@ __BEGIN_HIDDEN_DECLS #define SSL_MD5 0x00000001L #define SSL_SHA1 0x00000002L -#define SSL_GOST94 0x00000004L -#define SSL_GOST89MAC 0x00000008L #define SSL_SHA256 0x00000010L #define SSL_SHA384 0x00000020L /* Not a real MAC, just an indication it is part of cipher */ @@ -251,10 +246,8 @@ __BEGIN_HIDDEN_DECLS #define SSL_HANDSHAKE_MAC_MASK 0xff0 #define SSL_HANDSHAKE_MAC_MD5 0x010 #define SSL_HANDSHAKE_MAC_SHA 0x020 -#define SSL_HANDSHAKE_MAC_GOST94 0x040 #define SSL_HANDSHAKE_MAC_SHA256 0x080 #define SSL_HANDSHAKE_MAC_SHA384 0x100 -#define SSL_HANDSHAKE_MAC_STREEBOG256 0x200 #define SSL_HANDSHAKE_MAC_DEFAULT (SSL_HANDSHAKE_MAC_MD5 | SSL_HANDSHAKE_MAC_SHA) #define SSL3_CK_ID 0x03000000 @@ -267,16 +260,8 @@ __BEGIN_HIDDEN_DECLS #define TLS1_PRF_SHA1 (SSL_HANDSHAKE_MAC_SHA << TLS1_PRF_DGST_SHIFT) #define TLS1_PRF_SHA256 (SSL_HANDSHAKE_MAC_SHA256 << TLS1_PRF_DGST_SHIFT) #define TLS1_PRF_SHA384 (SSL_HANDSHAKE_MAC_SHA384 << TLS1_PRF_DGST_SHIFT) -#define TLS1_PRF_GOST94 (SSL_HANDSHAKE_MAC_GOST94 << TLS1_PRF_DGST_SHIFT) -#define TLS1_PRF_STREEBOG256 (SSL_HANDSHAKE_MAC_STREEBOG256 << TLS1_PRF_DGST_SHIFT) #define TLS1_PRF (TLS1_PRF_MD5 | TLS1_PRF_SHA1) -/* - * Stream MAC for GOST ciphersuites from cryptopro draft - * (currently this also goes into algorithm2). - */ -#define TLS1_STREAM_MAC 0x04 - /* * SSL_CIPHER_ALGORITHM2_VARIABLE_NONCE_IN_RECORD is an algorithm2 flag that * indicates that the variable part of the nonce is included as a prefix of @@ -324,8 +309,7 @@ __BEGIN_HIDDEN_DECLS #define SSL_PKEY_RSA 0 #define SSL_PKEY_ECC 1 -#define SSL_PKEY_GOST01 2 -#define SSL_PKEY_NUM 3 +#define SSL_PKEY_NUM 2 #define SSL_MAX_EMPTY_RECORDS 32 diff --git a/lib/libssl/ssl_sigalgs.c b/lib/libssl/ssl_sigalgs.c index f59beb432..9876e82a6 100644 --- a/lib/libssl/ssl_sigalgs.c +++ b/lib/libssl/ssl_sigalgs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_sigalgs.c,v 1.48 2022/11/26 16:08:56 tb Exp $ */ +/* $OpenBSD: ssl_sigalgs.c,v 1.49 2024/02/03 15:58:34 beck Exp $ */ /* * Copyright (c) 2018-2020 Bob Beck * Copyright (c) 2021 Joel Sing @@ -41,14 +41,6 @@ const struct ssl_sigalg sigalgs[] = { .security_level = 5, .group_nid = NID_secp521r1, }, -#ifndef OPENSSL_NO_GOST - { - .value = SIGALG_GOSTR12_512_STREEBOG_512, - .key_type = EVP_PKEY_GOSTR12_512, - .md = EVP_streebog512, - .security_level = 0, - }, -#endif { .value = SIGALG_RSA_PKCS1_SHA384, .key_type = EVP_PKEY_RSA, @@ -75,20 +67,6 @@ const struct ssl_sigalg sigalgs[] = { .security_level = 3, .group_nid = NID_X9_62_prime256v1, }, -#ifndef OPENSSL_NO_GOST - { - .value = SIGALG_GOSTR12_256_STREEBOG_256, - .key_type = EVP_PKEY_GOSTR12_256, - .md = EVP_streebog256, - .security_level = 0, - }, - { - .value = SIGALG_GOSTR01_GOST94, - .key_type = EVP_PKEY_GOSTR01, - .md = EVP_gostr341194, - .security_level = 0, /* XXX */ - }, -#endif { .value = SIGALG_RSA_PSS_RSAE_SHA256, .key_type = EVP_PKEY_RSA, @@ -283,10 +261,6 @@ ssl_sigalg_for_legacy(SSL *s, EVP_PKEY *pkey) return ssl_sigalg_lookup(SIGALG_RSA_PKCS1_SHA1); case EVP_PKEY_EC: return ssl_sigalg_lookup(SIGALG_ECDSA_SHA1); -#ifndef OPENSSL_NO_GOST - case EVP_PKEY_GOSTR01: - return ssl_sigalg_lookup(SIGALG_GOSTR01_GOST94); -#endif } SSLerror(s, SSL_R_UNKNOWN_PKEY_TYPE); return NULL; diff --git a/lib/libssl/ssl_sigalgs.h b/lib/libssl/ssl_sigalgs.h index 21a54d642..5211ec6b6 100644 --- a/lib/libssl/ssl_sigalgs.h +++ b/lib/libssl/ssl_sigalgs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_sigalgs.h,v 1.26 2022/07/02 16:00:12 tb Exp $ */ +/* $OpenBSD: ssl_sigalgs.h,v 1.27 2024/02/03 15:58:34 beck Exp $ */ /* * Copyright (c) 2018-2019 Bob Beck * @@ -47,14 +47,6 @@ __BEGIN_HIDDEN_DECLS #define SIGALG_PRIVATE_START 0xFE00 #define SIGALG_PRIVATE_END 0xFFFF -/* - * If Russia can elect the US President, surely - * IANA could fix this problem. - */ -#define SIGALG_GOSTR12_512_STREEBOG_512 0xEFEF -#define SIGALG_GOSTR12_256_STREEBOG_256 0xEEEE -#define SIGALG_GOSTR01_GOST94 0xEDED - /* Legacy sigalg for < TLSv1.2 same value as BoringSSL uses. */ #define SIGALG_RSA_PKCS1_MD5_SHA1 0xFF01 diff --git a/lib/libssl/ssl_srvr.c b/lib/libssl/ssl_srvr.c index f26fde506..6d61a4e4f 100644 --- a/lib/libssl/ssl_srvr.c +++ b/lib/libssl/ssl_srvr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssl_srvr.c,v 1.158 2023/12/29 12:24:33 tb Exp $ */ +/* $OpenBSD: ssl_srvr.c,v 1.160 2024/02/03 17:39:17 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -162,10 +162,6 @@ #include #include -#ifndef OPENSSL_NO_GOST -#include -#endif - #include "bytestring.h" #include "dtls_local.h" #include "ssl_local.h" @@ -564,15 +560,7 @@ ssl3_accept(SSL *s) } alg_k = s->s3->hs.cipher->algorithm_mkey; - if (s->s3->flags & TLS1_FLAGS_SKIP_CERT_VERIFY) { - /* - * A GOST client may use the key from its - * certificate for key exchange, in which case - * the CertificateVerify message is not sent. - */ - s->s3->hs.state = SSL3_ST_SR_FINISHED_A; - s->init_num = 0; - } else if (SSL_USE_SIGALGS(s) || (alg_k & SSL_kGOST)) { + if (SSL_USE_SIGALGS(s)) { s->s3->hs.state = SSL3_ST_SR_CERT_VRFY_A; s->init_num = 0; if (!s->session->peer_cert) @@ -795,7 +783,6 @@ ssl3_get_client_hello(SSL *s) unsigned long id; SSL_CIPHER *c; STACK_OF(SSL_CIPHER) *ciphers = NULL; - unsigned long alg_k; const SSL_METHOD *method; uint16_t shared_version; @@ -1138,9 +1125,7 @@ ssl3_get_client_hello(SSL *s) if (!tls1_transcript_hash_init(s)) goto err; - alg_k = s->s3->hs.cipher->algorithm_mkey; - if (!(SSL_USE_SIGALGS(s) || (alg_k & SSL_kGOST)) || - !(s->verify_mode & SSL_VERIFY_PEER)) + if (!SSL_USE_SIGALGS(s) || !(s->verify_mode & SSL_VERIFY_PEER)) tls1_transcript_free(s); /* @@ -1815,75 +1800,6 @@ ssl3_get_client_kex_ecdhe(SSL *s, CBS *cbs) return ret; } -static int -ssl3_get_client_kex_gost(SSL *s, CBS *cbs) -{ - unsigned char premaster_secret[32]; - EVP_PKEY_CTX *pkey_ctx = NULL; - EVP_PKEY *client_pubkey; - EVP_PKEY *pkey = NULL; - size_t outlen; - CBS gostblob; - - /* Get our certificate private key*/ -#ifndef OPENSSL_NO_GOST - if ((s->s3->hs.cipher->algorithm_auth & SSL_aGOST01) != 0) - pkey = s->cert->pkeys[SSL_PKEY_GOST01].privatekey; -#endif - - if ((pkey_ctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL) - goto err; - if (EVP_PKEY_decrypt_init(pkey_ctx) <= 0) - goto err; - - /* - * If client certificate is present and is of the same type, - * maybe use it for key exchange. - * Don't mind errors from EVP_PKEY_derive_set_peer, because - * it is completely valid to use a client certificate for - * authorization only. - */ - if ((client_pubkey = X509_get0_pubkey(s->session->peer_cert)) != NULL) { - if (EVP_PKEY_derive_set_peer(pkey_ctx, client_pubkey) <= 0) - ERR_clear_error(); - } - - /* Decrypt session key */ - if (!CBS_get_asn1(cbs, &gostblob, CBS_ASN1_SEQUENCE)) - goto decode_err; - if (CBS_len(cbs) != 0) - goto decode_err; - outlen = sizeof(premaster_secret); - if (EVP_PKEY_decrypt(pkey_ctx, premaster_secret, &outlen, - CBS_data(&gostblob), CBS_len(&gostblob)) <= 0) { - SSLerror(s, SSL_R_DECRYPTION_FAILED); - goto err; - } - - if (!tls12_derive_master_secret(s, premaster_secret, - sizeof(premaster_secret))) - goto err; - - /* Check if pubkey from client certificate was used */ - if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, - 2, NULL) > 0) - s->s3->flags |= TLS1_FLAGS_SKIP_CERT_VERIFY; - - explicit_bzero(premaster_secret, sizeof(premaster_secret)); - EVP_PKEY_CTX_free(pkey_ctx); - - return 1; - - decode_err: - SSLerror(s, SSL_R_BAD_PACKET_LENGTH); - ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); - err: - explicit_bzero(premaster_secret, sizeof(premaster_secret)); - EVP_PKEY_CTX_free(pkey_ctx); - - return 0; -} - static int ssl3_get_client_key_exchange(SSL *s) { @@ -1912,9 +1828,6 @@ ssl3_get_client_key_exchange(SSL *s) } else if (alg_k & SSL_kECDHE) { if (!ssl3_get_client_kex_ecdhe(s, &cbs)) goto err; - } else if (alg_k & SSL_kGOST) { - if (!ssl3_get_client_kex_gost(s, &cbs)) - goto err; } else { al = SSL_AD_HANDSHAKE_FAILURE; SSLerror(s, SSL_R_UNKNOWN_CIPHER_TYPE); @@ -2043,15 +1956,6 @@ ssl3_get_cert_verify(SSL *s) al = SSL_AD_INTERNAL_ERROR; goto fatal_err; } -#ifndef OPENSSL_NO_GOST - if (sigalg->key_type == EVP_PKEY_GOSTR01 && - EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_VERIFY, - EVP_PKEY_CTRL_GOST_SIG_FORMAT, GOST_SIG_FORMAT_RS_LE, - NULL) <= 0) { - al = SSL_AD_INTERNAL_ERROR; - goto fatal_err; - } -#endif if (EVP_DigestVerify(mctx, CBS_data(&signature), CBS_len(&signature), hdata, hdatalen) <= 0) { SSLerror(s, ERR_R_EVP_LIB); @@ -2096,54 +2000,6 @@ ssl3_get_cert_verify(SSL *s) SSLerror(s, SSL_R_BAD_ECDSA_SIGNATURE); goto fatal_err; } -#ifndef OPENSSL_NO_GOST - } else if (EVP_PKEY_id(pkey) == NID_id_GostR3410_94 || - EVP_PKEY_id(pkey) == NID_id_GostR3410_2001) { - unsigned char sigbuf[128]; - unsigned int siglen = sizeof(sigbuf); - EVP_PKEY_CTX *pctx; - const EVP_MD *md; - int nid; - - if (!tls1_transcript_data(s, &hdata, &hdatalen)) { - SSLerror(s, ERR_R_INTERNAL_ERROR); - al = SSL_AD_INTERNAL_ERROR; - goto fatal_err; - } - if (!EVP_PKEY_get_default_digest_nid(pkey, &nid) || - !(md = EVP_get_digestbynid(nid))) { - SSLerror(s, ERR_R_EVP_LIB); - al = SSL_AD_INTERNAL_ERROR; - goto fatal_err; - } - if ((pctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL) { - SSLerror(s, ERR_R_EVP_LIB); - al = SSL_AD_INTERNAL_ERROR; - goto fatal_err; - } - if (!EVP_DigestInit_ex(mctx, md, NULL) || - !EVP_DigestUpdate(mctx, hdata, hdatalen) || - !EVP_DigestFinal(mctx, sigbuf, &siglen) || - (EVP_PKEY_verify_init(pctx) <= 0) || - (EVP_PKEY_CTX_set_signature_md(pctx, md) <= 0) || - (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_VERIFY, - EVP_PKEY_CTRL_GOST_SIG_FORMAT, - GOST_SIG_FORMAT_RS_LE, NULL) <= 0)) { - SSLerror(s, ERR_R_EVP_LIB); - al = SSL_AD_INTERNAL_ERROR; - EVP_PKEY_CTX_free(pctx); - goto fatal_err; - } - if (EVP_PKEY_verify(pctx, CBS_data(&signature), - CBS_len(&signature), sigbuf, siglen) <= 0) { - al = SSL_AD_DECRYPT_ERROR; - SSLerror(s, SSL_R_BAD_SIGNATURE); - EVP_PKEY_CTX_free(pctx); - goto fatal_err; - } - - EVP_PKEY_CTX_free(pctx); -#endif } else { SSLerror(s, ERR_R_INTERNAL_ERROR); al = SSL_AD_UNSUPPORTED_CERTIFICATE; diff --git a/lib/libssl/tls1.h b/lib/libssl/tls1.h index 2bdbd3c18..daf6cba6f 100644 --- a/lib/libssl/tls1.h +++ b/lib/libssl/tls1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tls1.h,v 1.56 2022/07/17 14:39:09 jsing Exp $ */ +/* $OpenBSD: tls1.h,v 1.57 2024/02/03 15:58:34 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -741,18 +741,12 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb) #define TLS_CT_DSS_SIGN 2 #define TLS_CT_RSA_FIXED_DH 3 #define TLS_CT_DSS_FIXED_DH 4 -#define TLS_CT_GOST94_SIGN 21 -#define TLS_CT_GOST01_SIGN 22 #define TLS_CT_ECDSA_SIGN 64 #define TLS_CT_RSA_FIXED_ECDH 65 #define TLS_CT_ECDSA_FIXED_ECDH 66 -#define TLS_CT_GOST12_256_SIGN 67 -#define TLS_CT_GOST12_512_SIGN 68 -#define TLS_CT_GOST12_256_SIGN_COMPAT 238 /* pre-IANA, for compat */ -#define TLS_CT_GOST12_512_SIGN_COMPAT 239 /* pre-IANA, for compat */ /* when correcting this number, correct also SSL3_CT_NUMBER in ssl3.h (see * comment there) */ -#define TLS_CT_NUMBER 13 +#define TLS_CT_NUMBER 7 #define TLS1_FINISH_MAC_LENGTH 12 diff --git a/lib/libssl/tls12_key_schedule.c b/lib/libssl/tls12_key_schedule.c index 6d714c118..1ac003329 100644 --- a/lib/libssl/tls12_key_schedule.c +++ b/lib/libssl/tls12_key_schedule.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls12_key_schedule.c,v 1.3 2022/11/26 16:08:56 tb Exp $ */ +/* $OpenBSD: tls12_key_schedule.c,v 1.4 2024/02/03 15:58:34 beck Exp $ */ /* * Copyright (c) 2021 Joel Sing * @@ -124,10 +124,6 @@ tls12_key_block_generate(struct tls12_key_block *kb, SSL *s, mac_key_len = EVP_MD_size(mac_hash); key_len = EVP_CIPHER_key_length(cipher); iv_len = EVP_CIPHER_iv_length(cipher); - - /* Special handling for GOST... */ - if (EVP_MD_type(mac_hash) == NID_id_Gost28147_89_MAC) - mac_key_len = 32; } if (mac_key_len > EVP_MAX_MD_SIZE) diff --git a/lib/libssl/tls12_record_layer.c b/lib/libssl/tls12_record_layer.c index 3f2fe71e2..9786d7d0b 100644 --- a/lib/libssl/tls12_record_layer.c +++ b/lib/libssl/tls12_record_layer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls12_record_layer.c,v 1.41 2024/01/18 16:30:43 tb Exp $ */ +/* $OpenBSD: tls12_record_layer.c,v 1.42 2024/02/03 15:58:34 beck Exp $ */ /* * Copyright (c) 2020 Joel Sing * @@ -468,7 +468,6 @@ tls12_record_layer_ccs_cipher(struct tls12_record_layer *rl, CBS *iv) { EVP_PKEY *mac_pkey = NULL; - int gost_param_nid; int mac_type; int ret = 0; @@ -484,25 +483,10 @@ tls12_record_layer_ccs_cipher(struct tls12_record_layer *rl, goto err; if (EVP_CIPHER_key_length(rl->cipher) != CBS_len(key)) goto err; - -#ifndef OPENSSL_NO_GOST - /* XXX die die die */ - /* Special handling for GOST... */ - if (EVP_MD_type(rl->mac_hash) == NID_id_Gost28147_89_MAC) { - if (CBS_len(mac_key) != 32) - goto err; - mac_type = EVP_PKEY_GOSTIMIT; - rp->stream_mac = 1; - } else { -#endif - if (CBS_len(mac_key) > INT_MAX) - goto err; - if (EVP_MD_size(rl->mac_hash) != CBS_len(mac_key)) - goto err; -#ifndef OPENSSL_NO_GOST - } -#endif - + if (CBS_len(mac_key) > INT_MAX) + goto err; + if (EVP_MD_size(rl->mac_hash) != CBS_len(mac_key)) + goto err; if ((rp->cipher_ctx = EVP_CIPHER_CTX_new()) == NULL) goto err; if ((rp->hash_ctx = EVP_MD_CTX_new()) == NULL) @@ -524,23 +508,6 @@ tls12_record_layer_ccs_cipher(struct tls12_record_layer *rl, mac_pkey) <= 0) goto err; - /* More special handling for GOST... */ - if (EVP_CIPHER_nid(rl->cipher) == NID_gost89_cnt) { - gost_param_nid = NID_id_tc26_gost_28147_param_Z; - if (EVP_MD_type(rl->handshake_hash) == NID_id_GostR3411_94) - gost_param_nid = NID_id_Gost28147_89_CryptoPro_A_ParamSet; - - if (EVP_CIPHER_CTX_ctrl(rp->cipher_ctx, EVP_CTRL_GOST_SET_SBOX, - gost_param_nid, 0) <= 0) - goto err; - - if (EVP_MD_type(rl->mac_hash) == NID_id_Gost28147_89_MAC) { - if (EVP_MD_CTX_ctrl(rp->hash_ctx, EVP_MD_CTRL_GOST_SET_SBOX, - gost_param_nid, 0) <= 0) - goto err; - } - } - ret = 1; err: diff --git a/lib/libssl/tls13_handshake.c b/lib/libssl/tls13_handshake.c index 9723edfea..0dc233370 100644 --- a/lib/libssl/tls13_handshake.c +++ b/lib/libssl/tls13_handshake.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_handshake.c,v 1.72 2022/11/26 16:08:56 tb Exp $ */ +/* $OpenBSD: tls13_handshake.c,v 1.73 2024/02/03 19:57:14 tb Exp $ */ /* * Copyright (c) 2018-2021 Theo Buehler * Copyright (c) 2019 Joel Sing @@ -546,22 +546,24 @@ tls13_handshake_recv_action(struct tls13_ctx *ctx, return TLS13_IO_FAILURE; ret = TLS13_IO_FAILURE; - if (action->recv(ctx, &cbs)) { - if (CBS_len(&cbs) != 0) { - tls13_set_errorx(ctx, TLS13_ERR_TRAILING_DATA, 0, - "trailing data in handshake message", NULL); - ctx->alert = TLS13_ALERT_DECODE_ERROR; - } else { - ret = TLS13_IO_SUCCESS; - } + if (!action->recv(ctx, &cbs)) + goto err; + + if (CBS_len(&cbs) != 0) { + tls13_set_errorx(ctx, TLS13_ERR_TRAILING_DATA, 0, + "trailing data in handshake message", NULL); + ctx->alert = TLS13_ALERT_DECODE_ERROR; + goto err; } + ret = TLS13_IO_SUCCESS; + if (ctx->ssl->method->version < TLS1_3_VERSION) + ret = TLS13_IO_USE_LEGACY; + + err: tls13_handshake_msg_free(ctx->hs_msg); ctx->hs_msg = NULL; - if (ctx->ssl->method->version < TLS1_3_VERSION) - return TLS13_IO_USE_LEGACY; - return ret; } diff --git a/regress/lib/libssl/client/clienttest.c b/regress/lib/libssl/client/clienttest.c index 8fb5a1da7..18cf2d0c9 100644 --- a/regress/lib/libssl/client/clienttest.c +++ b/regress/lib/libssl/client/clienttest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clienttest.c,v 1.42 2023/07/11 17:03:44 tb Exp $ */ +/* $OpenBSD: clienttest.c,v 1.43 2024/02/03 15:58:34 beck Exp $ */ /* * Copyright (c) 2015 Joel Sing * @@ -36,7 +36,7 @@ #define TLS13_RANDOM_OFFSET (TLS13_HM_OFFSET + 2) #define TLS13_SESSION_OFFSET (TLS13_HM_OFFSET + 34) #define TLS13_CIPHER_OFFSET (TLS13_HM_OFFSET + 69) -#define TLS13_KEY_SHARE_OFFSET (TLS13_HM_OFFSET + 188) +#define TLS13_KEY_SHARE_OFFSET (TLS13_HM_OFFSET + 184) #define TLS13_ONLY_KEY_SHARE_OFFSET (TLS13_HM_OFFSET + 98) #define TLS1_3_VERSION_ONLY (TLS1_3_VERSION | 0x10000) @@ -75,57 +75,54 @@ static const uint8_t cipher_list_dtls12_aes[] = { 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, - 0xff, 0x85, 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, - 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, - 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, - 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, - 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, - 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, - 0x00, 0x41, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, - 0x00, 0x0a, 0x00, 0xff + 0x00, 0xc4, 0x00, 0x88, 0x00, 0x9d, 0x00, 0x3d, + 0x00, 0x35, 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, + 0xc0, 0x2b, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, + 0xc0, 0x09, 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, + 0x00, 0xbe, 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, + 0x00, 0x2f, 0x00, 0xba, 0x00, 0x41, 0xc0, 0x12, + 0xc0, 0x08, 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, }; static const uint8_t cipher_list_dtls12_chacha[] = { 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, - 0xff, 0x85, 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, - 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, - 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, - 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, - 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, - 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, - 0x00, 0x41, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, - 0x00, 0x0a, 0x00, 0xff, + 0x00, 0xc4, 0x00, 0x88, 0x00, 0x9d, 0x00, 0x3d, + 0x00, 0x35, 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, + 0xc0, 0x2b, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, + 0xc0, 0x09, 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, + 0x00, 0xbe, 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, + 0x00, 0x2f, 0x00, 0xba, 0x00, 0x41, 0xc0, 0x12, + 0xc0, 0x08, 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, }; static const uint8_t client_hello_dtls12[] = { 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xbe, 0x01, 0x00, 0x00, - 0xb2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xb2, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xba, 0x01, 0x00, 0x00, + 0xae, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xae, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0xc0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x9f, 0x00, 0x6b, 0x00, - 0x39, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xff, - 0x85, 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, 0x00, - 0x9d, 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, 0x00, - 0x84, 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, 0xc0, - 0x23, 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, 0x00, - 0x67, 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, 0x00, - 0x9c, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, 0x00, - 0x41, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, 0x00, - 0x0a, 0x00, 0xff, 0x01, 0x00, 0x00, 0x34, 0x00, - 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0a, 0x00, - 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, - 0x18, 0x00, 0x19, 0x00, 0x23, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x18, 0x00, 0x16, 0x08, 0x06, 0x06, - 0x01, 0x06, 0x03, 0x08, 0x05, 0x05, 0x01, 0x05, - 0x03, 0x08, 0x04, 0x04, 0x01, 0x04, 0x03, 0x02, - 0x01, 0x02, 0x03, + 0x39, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0x00, + 0xc4, 0x00, 0x88, 0x00, 0x9d, 0x00, 0x3d, 0x00, + 0x35, 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, 0xc0, + 0x2b, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, 0xc0, + 0x09, 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, 0x00, + 0xbe, 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, 0x00, + 0x2f, 0x00, 0xba, 0x00, 0x41, 0xc0, 0x12, 0xc0, + 0x08, 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, 0x01, + 0x00, 0x00, 0x34, 0x00, 0x0b, 0x00, 0x02, 0x01, + 0x00, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, + 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x00, + 0x23, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x18, 0x00, + 0x16, 0x08, 0x06, 0x06, 0x01, 0x06, 0x03, 0x08, + 0x05, 0x05, 0x01, 0x05, 0x03, 0x08, 0x04, 0x04, + 0x01, 0x04, 0x03, 0x02, 0x01, 0x02, 0x03, }; static const uint8_t cipher_list_tls10[] = { @@ -186,92 +183,90 @@ static const uint8_t cipher_list_tls12_aes[] = { 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, - 0xff, 0x85, 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, - 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, - 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, - 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, - 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, - 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, - 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, - 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, 0x00, 0x0a, - 0x00, 0xff, + 0x00, 0xc4, 0x00, 0x88, 0x00, 0x9d, 0x00, 0x3d, + 0x00, 0x35, 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, + 0xc0, 0x2b, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, + 0xc0, 0x09, 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, + 0x00, 0xbe, 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, + 0x00, 0x2f, 0x00, 0xba, 0x00, 0x41, 0xc0, 0x11, + 0xc0, 0x07, 0x00, 0x05, 0xc0, 0x12, 0xc0, 0x08, + 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, }; static const uint8_t cipher_list_tls12_chacha[] = { 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, - 0xff, 0x85, 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, - 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, - 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, - 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, - 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, - 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, - 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, - 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, 0x00, 0x0a, - 0x00, 0xff, + 0x00, 0xc4, 0x00, 0x88, 0x00, 0x9d, 0x00, 0x3d, + 0x00, 0x35, 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, + 0xc0, 0x2b, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, + 0xc0, 0x09, 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, + 0x00, 0xbe, 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, + 0x00, 0x2f, 0x00, 0xba, 0x00, 0x41, 0xc0, 0x11, + 0xc0, 0x07, 0x00, 0x05, 0xc0, 0x12, 0xc0, 0x08, + 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, }; static const uint8_t client_hello_tls12[] = { - 0x16, 0x03, 0x03, 0x00, 0xbb, 0x01, 0x00, 0x00, - 0xb7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x16, 0x03, 0x03, 0x00, 0xb7, 0x01, 0x00, 0x00, + 0xb3, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x5a, 0xc0, 0x30, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, - 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xff, 0x85, - 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, 0x00, 0x9d, - 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, 0x00, 0x84, - 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, 0xc0, 0x23, - 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, 0x00, 0x67, - 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, 0x00, 0x9c, - 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, 0x00, 0x41, - 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, 0xc0, 0x12, - 0xc0, 0x08, 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, - 0x01, 0x00, 0x00, 0x34, 0x00, 0x0b, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, - 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, - 0x00, 0x23, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x18, - 0x00, 0x16, 0x08, 0x06, 0x06, 0x01, 0x06, 0x03, - 0x08, 0x05, 0x05, 0x01, 0x05, 0x03, 0x08, 0x04, - 0x04, 0x01, 0x04, 0x03, 0x02, 0x01, 0x02, 0x03, + 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0x00, 0xc4, + 0x00, 0x88, 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, + 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, + 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, + 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, + 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, + 0x00, 0xba, 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, + 0x00, 0x05, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, + 0x00, 0x0a, 0x00, 0xff, 0x01, 0x00, 0x00, 0x34, + 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0a, + 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, + 0x00, 0x18, 0x00, 0x19, 0x00, 0x23, 0x00, 0x00, + 0x00, 0x0d, 0x00, 0x18, 0x00, 0x16, 0x08, 0x06, + 0x06, 0x01, 0x06, 0x03, 0x08, 0x05, 0x05, 0x01, + 0x05, 0x03, 0x08, 0x04, 0x04, 0x01, 0x04, 0x03, + 0x02, 0x01, 0x02, 0x03, }; static const uint8_t cipher_list_tls13_aes[] = { 0x13, 0x02, 0x13, 0x03, 0x13, 0x01, 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, - 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xff, 0x85, - 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, 0x00, 0x9d, - 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, 0x00, 0x84, - 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, 0xc0, 0x23, - 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, 0x00, 0x67, - 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, 0x00, 0x9c, - 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, 0x00, 0x41, - 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, 0xc0, 0x12, - 0xc0, 0x08, 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, + 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0x00, 0xc4, + 0x00, 0x88, 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, + 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, + 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, + 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, + 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, + 0x00, 0xba, 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, + 0x00, 0x05, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, + 0x00, 0x0a, 0x00, 0xff, }; static const uint8_t cipher_list_tls13_chacha[] = { 0x13, 0x03, 0x13, 0x02, 0x13, 0x01, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, - 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, 0xff, 0x85, - 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, 0x00, 0x9d, - 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, 0x00, 0x84, - 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, 0xc0, 0x23, - 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, 0x00, 0x67, - 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, 0x00, 0x9c, - 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, 0x00, 0x41, - 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, 0xc0, 0x12, - 0xc0, 0x08, 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, + 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, 0x00, 0xc4, + 0x00, 0x88, 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, + 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, + 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, + 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, + 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, + 0x00, 0xba, 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, + 0x00, 0x05, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, + 0x00, 0x0a, 0x00, 0xff, }; static const uint8_t client_hello_tls13[] = { - 0x16, 0x03, 0x03, 0x01, 0x14, 0x01, 0x00, 0x01, - 0x10, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x16, 0x03, 0x03, 0x01, 0x10, 0x01, 0x00, 0x01, + 0x0c, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -279,33 +274,32 @@ static const uint8_t client_hello_tls13[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x13, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x13, 0x03, 0x13, 0x02, 0x13, 0x01, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x9f, - 0x00, 0x6b, 0x00, 0x39, 0xff, 0x85, 0x00, 0xc4, - 0x00, 0x88, 0x00, 0x81, 0x00, 0x9d, 0x00, 0x3d, - 0x00, 0x35, 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, - 0xc0, 0x2b, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, - 0xc0, 0x09, 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, - 0x00, 0xbe, 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, - 0x00, 0x2f, 0x00, 0xba, 0x00, 0x41, 0xc0, 0x11, - 0xc0, 0x07, 0x00, 0x05, 0xc0, 0x12, 0xc0, 0x08, - 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, 0x01, 0x00, - 0x00, 0x67, 0x00, 0x2b, 0x00, 0x05, 0x04, 0x03, - 0x04, 0x03, 0x03, 0x00, 0x33, 0x00, 0x26, 0x00, - 0x24, 0x00, 0x1d, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x6b, 0x00, 0x39, 0x00, 0xc4, 0x00, 0x88, + 0x00, 0x81, 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, + 0x00, 0xc0, 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, + 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, + 0x00, 0x9e, 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, + 0x00, 0x45, 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, + 0x00, 0xba, 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, + 0x00, 0x05, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, + 0x00, 0x0a, 0x01, 0x00, 0x00, 0x67, 0x00, 0x2b, + 0x00, 0x05, 0x04, 0x03, 0x04, 0x03, 0x03, 0x00, + 0x33, 0x00, 0x26, 0x00, 0x24, 0x00, 0x1d, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, - 0x02, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x0a, 0x00, - 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, - 0x19, 0x00, 0x23, 0x00, 0x00, 0x00, 0x0d, 0x00, - 0x18, 0x00, 0x16, 0x08, 0x06, 0x06, 0x01, 0x06, - 0x03, 0x08, 0x05, 0x05, 0x01, 0x05, 0x03, 0x08, - 0x04, 0x04, 0x01, 0x04, 0x03, 0x02, 0x01, 0x02, - 0x03, + 0x00, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, + 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, + 0x17, 0x00, 0x18, 0x00, 0x19, 0x00, 0x23, 0x00, + 0x00, 0x00, 0x0d, 0x00, 0x18, 0x00, 0x16, 0x08, + 0x06, 0x06, 0x01, 0x06, 0x03, 0x08, 0x05, 0x05, + 0x01, 0x05, 0x03, 0x08, 0x04, 0x04, 0x01, 0x04, + 0x03, 0x02, 0x01, 0x02, 0x03, }; static const uint8_t cipher_list_tls13_only_aes[] = { diff --git a/regress/lib/libssl/interop/Makefile.inc b/regress/lib/libssl/interop/Makefile.inc index 4a66390cb..fa22fb851 100644 --- a/regress/lib/libssl/interop/Makefile.inc +++ b/regress/lib/libssl/interop/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.9 2023/10/18 19:14:32 anton Exp $ +# $OpenBSD: Makefile.inc,v 1.10 2024/02/03 15:58:34 beck Exp $ .PATH: ${.CURDIR}/.. @@ -39,7 +39,7 @@ run-self-client-server: client server 127.0.0.1.crt CLEANFILES += 127.0.0.1.{crt,key} \ ca.{crt,key,srl} fake-ca.{crt,key} \ {client,server}.{req,crt,key} \ - {dsa,ec,gost,rsa}.{key,req,crt} \ + {dsa,ec,rsa}.{key,req,crt} \ dh.param 127.0.0.1.crt: @@ -70,10 +70,6 @@ dsa.key: ec.key: openssl ecparam -genkey -name secp256r1 -out $@ -gost.key: - openssl genpkey -algorithm gost2001 \ - -pkeyopt paramset:A -pkeyopt dgst:md_gost94 -out $@ - rsa.key: openssl genrsa -out $@ 2048 @@ -82,11 +78,6 @@ dsa.req ec.req rsa.req: ${@:R}.key -subj /L=OpenBSD/O=tls-regress/OU=${@:R}/CN=localhost/ \ -nodes -key ${@:R}.key -out $@ -gost.req: ${@:R}.key - openssl req -batch -new -md_gost94 \ - -subj /L=OpenBSD/O=tls-regress/OU=${@:R}/CN=localhost/ \ - -nodes -key ${@:R}.key -out $@ - -dsa.crt ec.crt gost.crt rsa.crt: ca.crt ${@:R}.req +dsa.crt ec.crt rsa.crt: ca.crt ${@:R}.req openssl x509 -CAcreateserial -CAkey ca.key -CA ca.crt \ -req -in ${@:R}.req -out $@ diff --git a/regress/lib/libssl/interop/cipher/Makefile b/regress/lib/libssl/interop/cipher/Makefile index 627cfc8f9..3a116d5ed 100644 --- a/regress/lib/libssl/interop/cipher/Makefile +++ b/regress/lib/libssl/interop/cipher/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.13 2023/10/30 17:15:21 tb Exp $ +# $OpenBSD: Makefile,v 1.14 2024/02/03 15:58:34 beck Exp $ # Connect a client to a server. Both can be current libressl, or # openssl 1.1 or 3.0. Create lists of supported ciphers @@ -6,17 +6,6 @@ # certificate with compatible type. Check that client and server # have used correct cipher by grepping in their session print out. -run-cipher-GOST2001-GOST89-GOST89-client-libressl-server-libressl \ -run-cipher-GOST2012256-GOST89-GOST89-client-libressl-server-libressl \ -client-cipher-GOST2012256-GOST89-GOST89-client-libressl-server-libressl.out \ -client-cipher-GOST2001-GOST89-GOST89-client-libressl-server-libressl.out \ -server-cipher-GOST2001-GOST89-GOST89-client-libressl-server-libressl.out \ -server-cipher-GOST2012256-GOST89-GOST89-client-libressl-server-libressl.out \ -check-cipher-GOST2001-GOST89-GOST89-client-libressl-server-libressl \ -check-cipher-GOST2012256-GOST89-GOST89-client-libressl-server-libressl: - # gost does not work with libressl TLS 1.3 right now - @echo DISABLED - LIBRARIES = libressl .if exists(/usr/local/bin/eopenssl11) LIBRARIES += openssl11 @@ -96,8 +85,6 @@ LEVEL_openssl30 = ,@SECLEVEL=0 TYPE_${cipher} = dsa .elif "${cipher:M*-ECDSA-*}" != "" TYPE_${cipher} = ec -.elif "${cipher:M*-GOST89-*}" != "" -TYPE_${cipher} = gost .elif "${cipher:M*-RSA-*}" != "" TYPE_${cipher} = rsa .else diff --git a/regress/lib/libssl/unit/tls_prf.c b/regress/lib/libssl/unit/tls_prf.c index a22d0e70d..b6836da16 100644 --- a/regress/lib/libssl/unit/tls_prf.c +++ b/regress/lib/libssl/unit/tls_prf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_prf.c,v 1.8 2022/11/26 16:08:57 tb Exp $ */ +/* $OpenBSD: tls_prf.c,v 1.9 2024/02/03 15:58:34 beck Exp $ */ /* * Copyright (c) 2017 Joel Sing * @@ -57,29 +57,6 @@ static struct tls_prf_test tls_prf_tests[] = { 0x12, 0x44, 0xec, 0x60, 0x61, 0xd1, 0x8a, 0x66, }, }, - { - .desc = "GOST94", - .ssl_method = TLSv1_2_method, - .cipher_value = 0x0081, - .out = { - 0xcc, 0xd4, 0x89, 0x5f, 0x52, 0x08, 0x9b, 0xc7, - 0xf9, 0xb5, 0x83, 0x58, 0xe8, 0xc7, 0x71, 0x49, - 0x39, 0x99, 0x1f, 0x14, 0x8f, 0x85, 0xbe, 0x64, - 0xee, 0x40, 0x5c, 0xe7, 0x5f, 0x68, 0xaf, 0xf2, - 0xcd, 0x3a, 0x94, 0x52, 0x33, 0x53, 0x46, 0x7d, - 0xb6, 0xc5, 0xe1, 0xb8, 0xa4, 0x04, 0x69, 0x91, - 0x0a, 0x9c, 0x88, 0x86, 0xd9, 0x60, 0x63, 0xdd, - 0xd8, 0xe7, 0x2e, 0xee, 0xce, 0xe2, 0x20, 0xd8, - 0x9a, 0xfa, 0x9c, 0x63, 0x0c, 0x9c, 0xa1, 0x76, - 0xed, 0x78, 0x9a, 0x84, 0x70, 0xb4, 0xd1, 0x51, - 0x1f, 0xde, 0x44, 0xe8, 0x90, 0x21, 0x3f, 0xeb, - 0x05, 0xf4, 0x77, 0x59, 0xf3, 0xad, 0xdd, 0x34, - 0x3d, 0x3a, 0x7c, 0xd0, 0x59, 0x40, 0xe1, 0x3f, - 0x04, 0x4b, 0x8b, 0xd6, 0x95, 0x46, 0xb4, 0x9e, - 0x4c, 0x2d, 0xf7, 0xee, 0xbd, 0xbc, 0xcb, 0x5c, - 0x3a, 0x36, 0x0c, 0xd0, 0x27, 0xcb, 0x45, 0x06, - }, - }, { .desc = "SHA256 (via TLSv1.2)", .ssl_method = TLSv1_2_method, @@ -126,29 +103,6 @@ static struct tls_prf_test tls_prf_tests[] = { 0x05, 0x76, 0x4b, 0xe4, 0x28, 0x50, 0x4a, 0xf2, }, }, - { - .desc = "STREEBOG256", - .ssl_method = TLSv1_2_method, - .cipher_value = 0xff87, - .out = { - 0x3e, 0x13, 0xb9, 0xeb, 0x85, 0x8c, 0xb4, 0x21, - 0x23, 0x40, 0x9b, 0x73, 0x04, 0x56, 0xe2, 0xff, - 0xce, 0x52, 0x1f, 0x82, 0x7f, 0x17, 0x5b, 0x80, - 0x23, 0x71, 0xca, 0x30, 0xdf, 0xfc, 0xdc, 0x2d, - 0xc0, 0xfc, 0x5d, 0x23, 0x5a, 0x54, 0x7f, 0xae, - 0xf5, 0x7d, 0x52, 0x1e, 0x86, 0x95, 0xe1, 0x2d, - 0x28, 0xe7, 0xbe, 0xd7, 0xd0, 0xbf, 0xa9, 0x96, - 0x13, 0xd0, 0x9c, 0x0c, 0x1c, 0x16, 0x05, 0xbb, - 0x26, 0xd7, 0x30, 0x39, 0xb9, 0x53, 0x28, 0x98, - 0x4f, 0x1b, 0x83, 0xc3, 0xce, 0x1c, 0x7c, 0x34, - 0xa2, 0xc4, 0x7a, 0x54, 0x16, 0xc6, 0xa7, 0x9e, - 0xed, 0x4b, 0x7b, 0x83, 0xa6, 0xae, 0xe2, 0x5b, - 0x96, 0xf5, 0x6c, 0xad, 0x1f, 0xa3, 0x83, 0xb2, - 0x84, 0x32, 0xed, 0xe3, 0x2c, 0xf6, 0xd4, 0x73, - 0x30, 0xef, 0x9d, 0xbe, 0xe7, 0x23, 0x9a, 0xbf, - 0x4d, 0x1c, 0xe7, 0xef, 0x3d, 0xea, 0x46, 0xe2, - }, - }, }; #define N_TLS_PRF_TESTS \ diff --git a/sbin/dump/traverse.c b/sbin/dump/traverse.c index 5d3225d61..7863794c8 100644 --- a/sbin/dump/traverse.c +++ b/sbin/dump/traverse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: traverse.c,v 1.41 2024/01/09 03:16:00 guenther Exp $ */ +/* $OpenBSD: traverse.c,v 1.42 2024/02/03 18:51:57 beck Exp $ */ /* $NetBSD: traverse.c,v 1.17 1997/06/05 11:13:27 lukem Exp $ */ /*- @@ -163,30 +163,6 @@ fs_mapinodes(ino_t maxino, int64_t *tapesize, int *anydirskipped) inosused = cgp->cg_initediblk; else inosused = sblock->fs_ipg; - /* - * If we are using soft updates, then we can trust the - * cylinder group inode allocation maps to tell us which - * inodes are allocated. We will scan the used inode map - * to find the inodes that are really in use, and then - * read only those inodes in from disk. - */ - if (sblock->fs_flags & FS_DOSOFTDEP) { - if (!cg_chkmagic(cgp)) - quit("mapfiles: cg %d: bad magic number\n", cg); - cp = &cg_inosused(cgp)[(inosused - 1) / CHAR_BIT]; - for ( ; inosused > 0; inosused -= CHAR_BIT, cp--) { - if (*cp == 0) - continue; - for (i = 1 << (CHAR_BIT - 1); i > 0; i >>= 1) { - if (*cp & i) - break; - inosused--; - } - break; - } - if (inosused <= 0) - continue; - } for (i = 0; i < inosused; i++, ino++) { if (ino < ROOTINO) continue; diff --git a/sbin/dumpfs/dumpfs.c b/sbin/dumpfs/dumpfs.c index f5a1a0bf2..bd9d9ca69 100644 --- a/sbin/dumpfs/dumpfs.c +++ b/sbin/dumpfs/dumpfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dumpfs.c,v 1.37 2022/12/04 23:50:46 cheloha Exp $ */ +/* $OpenBSD: dumpfs.c,v 1.38 2024/02/03 18:51:57 beck Exp $ */ /* * Copyright (c) 2002 Networks Associates Technology, Inc. @@ -273,12 +273,10 @@ dumpfs(int fd, const char *name) printf("none"); if (fsflags & FS_UNCLEAN) printf("unclean "); - if (fsflags & FS_DOSOFTDEP) - printf("soft-updates "); if (fsflags & FS_FLAGS_UPDATED) printf("updated "); #if 0 - fsflags &= ~(FS_UNCLEAN | FS_DOSOFTDEP | FS_FLAGS_UPDATED); + fsflags &= ~(FS_UNCLEAN | FS_FLAGS_UPDATED); if (fsflags != 0) printf("unknown flags (%#x)", fsflags); #endif diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c index 150987a22..350989c5e 100644 --- a/sbin/fsck_ffs/dir.c +++ b/sbin/fsck_ffs/dir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.c,v 1.34 2024/01/09 03:16:00 guenther Exp $ */ +/* $OpenBSD: dir.c,v 1.35 2024/02/03 18:51:57 beck Exp $ */ /* $NetBSD: dir.c,v 1.20 1996/09/27 22:45:11 christos Exp $ */ /* @@ -265,7 +265,7 @@ adjust(struct inodesc *idesc, short lcnt) pinode(idesc->id_number); printf(" COUNT %d SHOULD BE %d", DIP(dp, di_nlink), DIP(dp, di_nlink) - lcnt); - if (preen || usedsoftdep) { + if (preen) { if (lcnt < 0) { printf("\n"); pfatal("LINK COUNT INCREASING"); @@ -332,7 +332,7 @@ linkup(ino_t orphan, ino_t parentdir) lostdir = (DIP(dp, di_mode) & IFMT) == IFDIR; pwarn("UNREF %s ", lostdir ? "DIR" : "FILE"); pinode(orphan); - if ((preen || usedsoftdep) && DIP(dp, di_size) == 0) + if (preen && DIP(dp, di_size) == 0) return (0); if (preen) printf(" (RECONNECTED)\n"); diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h index 981871cd8..8af2e0a77 100644 --- a/sbin/fsck_ffs/fsck.h +++ b/sbin/fsck_ffs/fsck.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fsck.h,v 1.34 2021/01/27 05:03:25 deraadt Exp $ */ +/* $OpenBSD: fsck.h,v 1.35 2024/02/03 18:51:57 beck Exp $ */ /* $NetBSD: fsck.h,v 1.13 1996/10/11 20:15:46 thorpej Exp $ */ /* @@ -229,7 +229,6 @@ extern char yflag; /* assume a yes response */ extern daddr_t bflag; /* location of alternate super block */ extern int debug; /* output debugging info */ extern int cvtlevel; /* convert to newer file system format */ -extern char usedsoftdep; /* just fix soft dependency inconsistencies */ extern int preen; /* just fix normal inconsistencies */ extern char resolved; /* cleared if unresolved changes => not clean */ extern char havesb; /* superblock has been read */ diff --git a/sbin/fsck_ffs/main.c b/sbin/fsck_ffs/main.c index a3978dbe1..a3d43d495 100644 --- a/sbin/fsck_ffs/main.c +++ b/sbin/fsck_ffs/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.54 2023/03/08 04:43:06 guenther Exp $ */ +/* $OpenBSD: main.c,v 1.55 2024/02/03 18:51:57 beck Exp $ */ /* $NetBSD: main.c,v 1.22 1996/10/11 20:15:48 thorpej Exp $ */ /* @@ -77,7 +77,6 @@ char yflag; /* assume a yes response */ daddr_t bflag; /* location of alternate super block */ int debug; /* output debugging info */ int cvtlevel; /* convert to newer file system format */ -char usedsoftdep; /* just fix soft dependency inconsistencies */ int preen; /* just fix normal inconsistencies */ char resolved; /* cleared if unresolved changes => not clean */ char havesb; /* superblock has been read */ @@ -257,7 +256,7 @@ checkfilesys(char *filesys, char *mntpt, long auxdata, int child) * 1b: locate first references to duplicates, if any */ if (duplist) { - if (preen || usedsoftdep) + if (preen) pfatal("INTERNAL ERROR: dups with -p"); printf("** Phase 1b - Rescan For More DUPS\n"); pass1b(); diff --git a/sbin/fsck_ffs/pass1.c b/sbin/fsck_ffs/pass1.c index edeb370c7..05e0afe75 100644 --- a/sbin/fsck_ffs/pass1.c +++ b/sbin/fsck_ffs/pass1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass1.c,v 1.48 2024/01/09 03:16:00 guenther Exp $ */ +/* $OpenBSD: pass1.c,v 1.49 2024/02/03 18:51:57 beck Exp $ */ /* $NetBSD: pass1.c,v 1.16 1996/09/27 22:45:15 christos Exp $ */ /* @@ -110,31 +110,6 @@ pass1(void) } else inosused = sblock.fs_ipg; - /* - * If we are using soft updates, then we can trust the - * cylinder group inode allocation maps to tell us which - * inodes are allocated. We will scan the used inode map - * to find the inodes that are really in use, and then - * read only those inodes in from disk. - */ - if (preen && usedsoftdep) { - cp = &cg_inosused(cgp)[(inosused - 1) / CHAR_BIT]; - for ( ; inosused != 0; cp--) { - if (*cp == 0) { - if (inosused > CHAR_BIT) - inosused -= CHAR_BIT; - else - inosused = 0; - continue; - } - for (i = 1 << (CHAR_BIT - 1); i > 0; i >>= 1) { - if (*cp & i) - break; - inosused--; - } - break; - } - } /* * Allocate inoinfo structures for the allocated inodes. */ diff --git a/sbin/fsck_ffs/pass2.c b/sbin/fsck_ffs/pass2.c index c048ba86f..04446c5ca 100644 --- a/sbin/fsck_ffs/pass2.c +++ b/sbin/fsck_ffs/pass2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass2.c,v 1.38 2024/01/09 03:16:00 guenther Exp $ */ +/* $OpenBSD: pass2.c,v 1.39 2024/02/03 18:51:57 beck Exp $ */ /* $NetBSD: pass2.c,v 1.17 1996/09/27 22:45:15 christos Exp $ */ /* @@ -162,14 +162,9 @@ pass2(void) } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) { getpathname(pathbuf, sizeof pathbuf, inp->i_number, inp->i_number); - if (usedsoftdep) - pfatal("%s %s: LENGTH %zu NOT MULTIPLE of %d", - "DIRECTORY", pathbuf, inp->i_isize, - DIRBLKSIZ); - else - pwarn("%s %s: LENGTH %zu NOT MULTIPLE OF %d", - "DIRECTORY", pathbuf, inp->i_isize, - DIRBLKSIZ); + pwarn("%s %s: LENGTH %zu NOT MULTIPLE OF %d", + "DIRECTORY", pathbuf, inp->i_isize, + DIRBLKSIZ); if (preen) printf(" (ADJUSTED)\n"); inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ); @@ -403,7 +398,7 @@ again: break; if (GET_ISTATE(dirp->d_ino) == FCLEAR) errmsg = "DUP/BAD"; - else if (!preen && !usedsoftdep) + else if (!preen) errmsg = "ZERO LENGTH DIRECTORY"; else { n = 1; diff --git a/sbin/fsck_ffs/pass5.c b/sbin/fsck_ffs/pass5.c index c5e357d7c..81bdd9b7f 100644 --- a/sbin/fsck_ffs/pass5.c +++ b/sbin/fsck_ffs/pass5.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass5.c,v 1.50 2020/07/13 06:52:53 otto Exp $ */ +/* $OpenBSD: pass5.c,v 1.51 2024/02/03 18:51:57 beck Exp $ */ /* $NetBSD: pass5.c,v 1.16 1996/09/27 22:45:18 christos Exp $ */ /* @@ -333,34 +333,6 @@ pass5(void) memcpy(cg, newcg, (size_t)basesize); dirty(cgbp); } - if (usedsoftdep) { - for (i = 0; i < inomapsize; i++) { - j = cg_inosused(newcg)[i]; - if ((cg_inosused(cg)[i] & j) == j) - continue; - for (k = 0; k < NBBY; k++) { - if ((j & (1 << k)) == 0) - continue; - if (cg_inosused(cg)[i] & (1 << k)) - continue; - pwarn("ALLOCATED INODE %llu MARKED FREE\n", - ((ino_t)c * fs->fs_ipg + i * 8) + k); - } - } - for (i = 0; i < blkmapsize; i++) { - j = cg_blksfree(cg)[i]; - if ((cg_blksfree(newcg)[i] & j) == j) - continue; - for (k = 0; k < NBBY; k++) { - if ((j & (1 << k)) == 0) - continue; - if (cg_blksfree(newcg)[i] & (1 << k)) - continue; - pwarn("ALLOCATED FRAG %lld MARKED FREE\n", - ((long long)c * fs->fs_fpg + i * 8) + k); - } - } - } if (memcmp(cg_inosused(newcg), cg_inosused(cg), mapsize) != 0 && dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) { diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c index 716609fdd..f856c89c0 100644 --- a/sbin/fsck_ffs/setup.c +++ b/sbin/fsck_ffs/setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setup.c,v 1.69 2022/09/01 13:37:57 krw Exp $ */ +/* $OpenBSD: setup.c,v 1.70 2024/02/03 18:51:57 beck Exp $ */ /* $NetBSD: setup.c,v 1.27 1996/09/27 22:45:19 christos Exp $ */ /* @@ -450,10 +450,6 @@ found: goto badsblabel; } bufinit(); - if (sblock.fs_flags & FS_DOSOFTDEP) - usedsoftdep = 1; - else - usedsoftdep = 0; return (1); badsblabel: diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c index 73b849656..1f71d27ae 100644 --- a/sbin/growfs/growfs.c +++ b/sbin/growfs/growfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: growfs.c,v 1.55 2022/12/04 23:50:46 cheloha Exp $ */ +/* $OpenBSD: growfs.c,v 1.56 2024/02/03 18:51:57 beck Exp $ */ /* * Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz * Copyright (c) 1980, 1989, 1993 The Regents of the University of California. @@ -202,8 +202,6 @@ growfs(int fsi, int fso, unsigned int Nflag) printf("\tusing %u cylinder groups of %.2fMB, %d blks, %u inodes.\n", sblock.fs_ncg, (float)sblock.fs_fpg * sblock.fs_fsize * B2MBFACTOR, sblock.fs_fpg / sblock.fs_frag, sblock.fs_ipg); - if (sblock.fs_flags & FS_DOSOFTDEP) - printf("\twith soft updates\n"); #undef B2MBFACTOR /* @@ -282,9 +280,6 @@ growfs(int fsi, int fso, unsigned int Nflag) sblock.fs_cgrotor = 0; sblock.fs_state = 0; memset(&sblock.fs_fsmnt, 0, sizeof(sblock.fs_fsmnt)); - sblock.fs_flags &= FS_DOSOFTDEP; - if (sblock.fs_magic == FS_UFS1_MAGIC) - sblock.fs_ffs1_flags &= FS_DOSOFTDEP; /* * XXX diff --git a/sbin/iked/policy.c b/sbin/iked/policy.c index 1e39beac2..a9e783c82 100644 --- a/sbin/iked/policy.c +++ b/sbin/iked/policy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: policy.c,v 1.97 2023/11/10 08:03:02 tobhe Exp $ */ +/* $OpenBSD: policy.c,v 1.98 2024/02/03 00:54:14 jsg Exp $ */ /* * Copyright (c) 2020-2021 Tobias Heider @@ -1091,7 +1091,7 @@ proposals_match(struct iked_proposal *local, struct iked_proposal *peer, for (i = 0; i < peer->prop_nxforms; i++) { tpeer = peer->prop_xforms + i; - if (tpeer->xform_type > IKEV2_XFORMTYPE_MAX) + if (tpeer->xform_type >= IKEV2_XFORMTYPE_MAX) continue; if (noauth && tpeer->xform_type == IKEV2_XFORMTYPE_INTEGR) return (0); diff --git a/sbin/quotacheck/quotacheck.c b/sbin/quotacheck/quotacheck.c index 427b12822..6151963fc 100644 --- a/sbin/quotacheck/quotacheck.c +++ b/sbin/quotacheck/quotacheck.c @@ -1,4 +1,4 @@ -/* $OpenBSD: quotacheck.c,v 1.41 2019/06/28 13:32:45 deraadt Exp $ */ +/* $OpenBSD: quotacheck.c,v 1.42 2024/02/03 18:51:57 beck Exp $ */ /* $NetBSD: quotacheck.c,v 1.12 1996/03/30 22:34:25 mark Exp $ */ /* @@ -303,30 +303,6 @@ chkquota(const char *vfstype, const char *fsname, const char *mntpt, inosused = cgblk.cg_initediblk; else inosused = sblock.fs_ipg; - /* - * If we are using soft updates, then we can trust the - * cylinder group inode allocation maps to tell us which - * inodes are allocated. We will scan the used inode map - * to find the inodes that are really in use, and then - * read only those inodes in from disk. - */ - if (sblock.fs_flags & FS_DOSOFTDEP) { - if (!cg_chkmagic(&cgblk)) - errx(1, "CG %d: BAD MAGIC NUMBER\n", cg); - cp = &cg_inosused(&cgblk)[(inosused - 1) / CHAR_BIT]; - for ( ; inosused > 0; inosused -= CHAR_BIT, cp--) { - if (*cp == 0) - continue; - for (i = 1 << (CHAR_BIT - 1); i > 0; i >>= 1) { - if (*cp & i) - break; - inosused--; - } - break; - } - if (inosused <= 0) - continue; - } for (i = 0; i < inosused; i++, ino++) { if ((dp = getnextinode(ino)) == NULL || ino < ROOTINO || diff --git a/sbin/slaacd/engine.c b/sbin/slaacd/engine.c index 18e716ee1..ef25f4b46 100644 --- a/sbin/slaacd/engine.c +++ b/sbin/slaacd/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.86 2023/12/14 09:58:59 claudio Exp $ */ +/* $OpenBSD: engine.c,v 1.87 2024/02/03 18:30:17 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser @@ -1272,7 +1272,7 @@ request_solicitation(struct slaacd_iface *iface) clock_gettime(CLOCK_MONOTONIC, &now); timespecsub(&now, &iface->last_sol, &diff); if (timespeccmp(&diff, &sol_delay, <)) { - log_warnx("last solicitation less then %d seconds ago", + log_debug("last solicitation less than %d seconds ago", RTR_SOLICITATION_INTERVAL); return; } diff --git a/share/man/man5/fs.5 b/share/man/man5/fs.5 index d821db65a..73cc418d1 100644 --- a/share/man/man5/fs.5 +++ b/share/man/man5/fs.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fs.5,v 1.19 2015/09/10 17:55:21 schwarze Exp $ +.\" $OpenBSD: fs.5,v 1.20 2024/02/03 18:51:57 beck Exp $ .\" $NetBSD: fs.5,v 1.3 1994/11/30 19:31:17 jtc Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)fs.5 8.2 (Berkeley) 4/19/94 .\" -.Dd $Mdocdate: September 10 2015 $ +.Dd $Mdocdate: February 3 2024 $ .Dt FS 5 .Os .Sh NAME @@ -276,9 +276,7 @@ The .Va fs_flags element specifies how the filesystem was mounted: .Pp -.Bl -tag -width FS_DOSOFTDEP -offset ind -compact -.It Dv FS_DOSOFTDEP -The filesystem was mounted using soft dependencies. +.Bl -tag -width FS_UNCLEAN -offset ind -compact .It Dv FS_UNCLEAN The filesystem was mounted uncleanly. .El diff --git a/sys/arch/amd64/amd64/cacheinfo.c b/sys/arch/amd64/amd64/cacheinfo.c index 55fd72131..d0c5ed2e1 100644 --- a/sys/arch/amd64/amd64/cacheinfo.c +++ b/sys/arch/amd64/amd64/cacheinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cacheinfo.c,v 1.11 2022/07/12 04:46:00 jsg Exp $ */ +/* $OpenBSD: cacheinfo.c,v 1.12 2024/02/03 09:53:15 jsg Exp $ */ /* * Copyright (c) 2022 Jonathan Gray @@ -43,10 +43,7 @@ amd64_print_l1_cacheinfo(struct cpu_info *ci) printf("%s: ", ci->ci_dev->dv_xname); - if (totalsize < 1024) - printf("%dKB ", totalsize); - else - printf("%dMB ", totalsize >> 10); + printf("%dKB ", totalsize); printf("%db/line ", linesize); switch (ways) { @@ -70,10 +67,7 @@ amd64_print_l1_cacheinfo(struct cpu_info *ci) ways = (edx >> 16) & 0xff; totalsize = (edx >> 24) & 0xff; /* KB */ - if (totalsize < 1024) - printf("%dKB ", totalsize); - else - printf("%dMB ", totalsize >> 10); + printf("%dKB ", totalsize); printf("%db/line ", linesize); switch (ways) { diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index bd88aab3e..54f0d6ef6 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.177 2023/11/22 18:50:10 bluhm Exp $ */ +/* $OpenBSD: cpu.c,v 1.178 2024/02/03 16:21:22 deraadt Exp $ */ /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -163,6 +163,7 @@ int cpu_apmi_edx = 0; /* cpuid(0x80000007).edx */ int ecpu_ecxfeature = 0; /* cpuid(0x80000001).ecx */ int cpu_meltdown = 0; int cpu_use_xsaves = 0; +int need_retpoline = 1; /* most systems need retpoline */ void replacesmap(void) @@ -232,9 +233,11 @@ replacemeltdown(void) if (ibrs == 2 || (ci->ci_feature_sefflags_edx & SEFF0EDX_IBT)) { extern const char _jmprax, _jmpr11, _jmpr13; extern const short _jmprax_len, _jmpr11_len, _jmpr13_len; + codepatch_replace(CPTAG_RETPOLINE_RAX, &_jmprax, _jmprax_len); codepatch_replace(CPTAG_RETPOLINE_R11, &_jmpr11, _jmpr11_len); codepatch_replace(CPTAG_RETPOLINE_R13, &_jmpr13, _jmpr13_len); + need_retpoline = 0; } if (!cpu_meltdown) diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index ec472ca48..9fa994bdc 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.289 2024/01/19 18:38:16 kettenis Exp $ */ +/* $OpenBSD: machdep.c,v 1.290 2024/02/03 16:21:22 deraadt Exp $ */ /* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */ /*- @@ -486,6 +486,7 @@ bios_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, extern int tsc_is_invariant; extern int amd64_has_xcrypt; +extern int need_retpoline; const struct sysctl_bounded_args cpuctl_vars[] = { { CPU_LIDACTION, &lid_action, 0, 2 }, @@ -494,6 +495,7 @@ const struct sysctl_bounded_args cpuctl_vars[] = { { CPU_CPUFEATURE, &cpu_feature, SYSCTL_INT_READONLY }, { CPU_XCRYPT, &amd64_has_xcrypt, SYSCTL_INT_READONLY }, { CPU_INVARIANTTSC, &tsc_is_invariant, SYSCTL_INT_READONLY }, + { CPU_RETPOLINE, &need_retpoline, SYSCTL_INT_READONLY }, }; /* diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h index 6c7ae1de4..5c209b90a 100644 --- a/sys/arch/amd64/include/cpu.h +++ b/sys/arch/amd64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.160 2024/01/24 19:23:39 cheloha Exp $ */ +/* $OpenBSD: cpu.h,v 1.161 2024/02/03 16:21:22 deraadt Exp $ */ /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */ /*- @@ -481,7 +481,8 @@ void mp_setperf_init(void); #define CPU_TSCFREQ 16 /* TSC frequency */ #define CPU_INVARIANTTSC 17 /* has invariant TSC */ #define CPU_PWRACTION 18 /* action caused by power button */ -#define CPU_MAXID 19 /* number of valid machdep ids */ +#define CPU_RETPOLINE 19 /* cpu requires retpoline pattern */ +#define CPU_MAXID 20 /* number of valid machdep ids */ #define CTL_MACHDEP_NAMES { \ { 0, 0 }, \ @@ -503,6 +504,7 @@ void mp_setperf_init(void); { "tscfreq", CTLTYPE_QUAD }, \ { "invarianttsc", CTLTYPE_INT }, \ { "pwraction", CTLTYPE_INT }, \ + { "retpoline", CTLTYPE_INT }, \ } #endif /* !_MACHINE_CPU_H_ */ diff --git a/sys/arch/arm64/dev/acpipci.c b/sys/arch/arm64/dev/acpipci.c index fa2d7ab24..cf6246e58 100644 --- a/sys/arch/arm64/dev/acpipci.c +++ b/sys/arch/arm64/dev/acpipci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpipci.c,v 1.41 2023/09/16 23:25:16 jmatthew Exp $ */ +/* $OpenBSD: acpipci.c,v 1.42 2024/02/03 10:37:25 kettenis Exp $ */ /* * Copyright (c) 2018 Mark Kettenis * @@ -207,6 +207,7 @@ acpipci_attach(struct device *parent, struct device *self, void *aux) sc->sc_pc->pc_intr_v = sc; sc->sc_pc->pc_intr_map = acpipci_intr_map; sc->sc_pc->pc_intr_map_msi = _pci_intr_map_msi; + sc->sc_pc->pc_intr_map_msivec = _pci_intr_map_msivec; sc->sc_pc->pc_intr_map_msix = _pci_intr_map_msix; sc->sc_pc->pc_intr_string = acpipci_intr_string; sc->sc_pc->pc_intr_establish = acpipci_intr_establish; @@ -629,7 +630,7 @@ acpipci_intr_establish(void *v, pci_intr_handle_t ih, int level, if (ih.ih_type != PCI_INTX) { struct interrupt_controller *ic = sc->sc_msi_ic; bus_dma_segment_t seg; - uint64_t addr, data; + uint64_t addr = 0, data; KASSERT(ic); diff --git a/sys/arch/arm64/dev/agintc.c b/sys/arch/arm64/dev/agintc.c index 4d306bf27..dc04b7e5d 100644 --- a/sys/arch/arm64/dev/agintc.c +++ b/sys/arch/arm64/dev/agintc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agintc.c,v 1.54 2023/09/22 01:10:43 jsg Exp $ */ +/* $OpenBSD: agintc.c,v 1.55 2024/02/03 10:37:25 kettenis Exp $ */ /* * Copyright (c) 2007, 2009, 2011, 2017 Dale Rahn * Copyright (c) 2018 Mark Kettenis @@ -1540,7 +1540,7 @@ struct agintc_msi_device { LIST_ENTRY(agintc_msi_device) md_list; uint32_t md_deviceid; - uint32_t md_eventid; + uint32_t md_events; struct agintc_dmamem *md_itt; }; @@ -1949,7 +1949,15 @@ agintc_intr_establish_msi(void *self, uint64_t *addr, uint64_t *data, if (md == NULL) return NULL; - eventid = md->md_eventid++; + eventid = *addr; + if (eventid > 0 && (md->md_events & (1U << eventid))) + return NULL; + for (; eventid < 32; eventid++) { + if ((md->md_events & (1U << eventid)) == 0) { + md->md_events |= (1U << eventid); + break; + } + } if (eventid >= 32) return NULL; diff --git a/sys/arch/arm64/dev/aplpcie.c b/sys/arch/arm64/dev/aplpcie.c index 4b2ac02eb..a38ea5240 100644 --- a/sys/arch/arm64/dev/aplpcie.c +++ b/sys/arch/arm64/dev/aplpcie.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aplpcie.c,v 1.18 2023/12/28 13:32:56 kettenis Exp $ */ +/* $OpenBSD: aplpcie.c,v 1.19 2024/02/03 10:37:25 kettenis Exp $ */ /* * Copyright (c) 2021 Mark Kettenis * @@ -405,6 +405,7 @@ aplpcie_attach(struct device *parent, struct device *self, void *aux) sc->sc_pc.pc_intr_v = sc; sc->sc_pc.pc_intr_map = aplpcie_intr_map; sc->sc_pc.pc_intr_map_msi = _pci_intr_map_msi; + sc->sc_pc.pc_intr_map_msivec = _pci_intr_map_msivec; sc->sc_pc.pc_intr_map_msix = _pci_intr_map_msix; sc->sc_pc.pc_intr_string = aplpcie_intr_string; sc->sc_pc.pc_intr_establish = aplpcie_intr_establish; @@ -939,6 +940,7 @@ aplpcie_intr_establish(void *v, pci_intr_handle_t ih, int level, if (ih.ih_type != PCI_INTX) { uint64_t addr, data; + addr = data = 0; cookie = fdt_intr_establish_msi_cpu(sc->sc_node, &addr, &data, level, ci, func, arg, name); if (cookie == NULL) diff --git a/sys/arch/arm64/dev/pci_machdep.c b/sys/arch/arm64/dev/pci_machdep.c index efdf2a570..86b8edd67 100644 --- a/sys/arch/arm64/dev/pci_machdep.c +++ b/sys/arch/arm64/dev/pci_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_machdep.c,v 1.5 2021/03/22 20:30:21 patrick Exp $ */ +/* $OpenBSD: pci_machdep.c,v 1.6 2024/02/03 10:37:25 kettenis Exp $ */ /* * Copyright (c) 2019 Mark Kettenis @@ -24,16 +24,45 @@ #include #include +int +pci_intr_enable_msivec(struct pci_attach_args *pa, int num_vec) +{ + pci_chipset_tag_t pc = pa->pa_pc; + pcitag_t tag = pa->pa_tag; + pcireg_t reg; + int mmc, mme, off; + + if ((pa->pa_flags & PCI_FLAGS_MSI_ENABLED) == 0 || + pci_get_capability(pc, tag, PCI_CAP_MSI, &off, ®) == 0) + return 1; + + mmc = ((reg & PCI_MSI_MC_MMC_MASK) >> PCI_MSI_MC_MMC_SHIFT); + if (num_vec > (1 << mmc)) + return 1; + + mme = ((reg & PCI_MSI_MC_MME_MASK) >> PCI_MSI_MC_MME_SHIFT); + while ((1 << mme) < num_vec) + mme++; + reg &= ~PCI_MSI_MC_MME_MASK; + reg |= (mme << PCI_MSI_MC_MME_SHIFT); + pci_conf_write(pc, tag, off, reg); + + return 0; +} + void pci_msi_enable(pci_chipset_tag_t pc, pcitag_t tag, bus_addr_t addr, uint32_t data) { pcireg_t reg; - int off; + int mme, off; if (pci_get_capability(pc, tag, PCI_CAP_MSI, &off, ®) == 0) panic("%s: no msi capability", __func__); + mme = ((reg & PCI_MSI_MC_MME_MASK) >> PCI_MSI_MC_MME_SHIFT); + data &= ~((1 << mme) - 1); + if (reg & PCI_MSI_MC_C64) { pci_conf_write(pc, tag, off + PCI_MSI_MA, addr); pci_conf_write(pc, tag, off + PCI_MSI_MAU32, addr >> 32); @@ -128,6 +157,33 @@ _pci_intr_map_msi(struct pci_attach_args *pa, pci_intr_handle_t *ihp) ihp->ih_pc = pa->pa_pc; ihp->ih_tag = pa->pa_tag; + ihp->ih_intrpin = 0; + ihp->ih_type = PCI_MSI; + ihp->ih_dmat = pa->pa_dmat; + + return 0; +} + +int +_pci_intr_map_msivec(struct pci_attach_args *pa, int vec, + pci_intr_handle_t *ihp) +{ + pci_chipset_tag_t pc = pa->pa_pc; + pcitag_t tag = pa->pa_tag; + pcireg_t reg; + int mme, off; + + if ((pa->pa_flags & PCI_FLAGS_MSIVEC_ENABLED) == 0 || + pci_get_capability(pc, tag, PCI_CAP_MSI, &off, ®) == 0) + return -1; + + mme = ((reg & PCI_MSI_MC_MME_MASK) >> PCI_MSI_MC_MME_SHIFT); + if (vec >= (1 << mme)) + return -1; + + ihp->ih_pc = pa->pa_pc; + ihp->ih_tag = pa->pa_tag; + ihp->ih_intrpin = vec; ihp->ih_type = PCI_MSI; ihp->ih_dmat = pa->pa_dmat; @@ -164,4 +220,3 @@ _pci_intr_map_msix(struct pci_attach_args *pa, int vec, return 0; } - diff --git a/sys/arch/arm64/include/pci_machdep.h b/sys/arch/arm64/include/pci_machdep.h index 3cb9be099..a2ccd3b09 100644 --- a/sys/arch/arm64/include/pci_machdep.h +++ b/sys/arch/arm64/include/pci_machdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_machdep.h,v 1.11 2021/06/11 12:23:52 kettenis Exp $ */ +/* $OpenBSD: pci_machdep.h,v 1.12 2024/02/03 10:37:26 kettenis Exp $ */ /* * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -70,6 +70,8 @@ struct machine_pci_chipset { pci_intr_handle_t *); int (*pc_intr_map_msi)(struct pci_attach_args *, pci_intr_handle_t *); + int (*pc_intr_map_msivec)(struct pci_attach_args *, + int, pci_intr_handle_t *); int (*pc_intr_map_msix)(struct pci_attach_args *, int, pci_intr_handle_t *); const char *(*pc_intr_string)(void *, pci_intr_handle_t); @@ -102,6 +104,8 @@ struct machine_pci_chipset { (*(c)->pa_pc->pc_intr_map)((c), (ihp)) #define pci_intr_map_msi(c, ihp) \ (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp)) +#define pci_intr_map_msivec(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msivec)((c), (vec), (ihp)) #define pci_intr_map_msix(c, vec, ihp) \ (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp)) #define pci_intr_string(c, ih) \ @@ -123,10 +127,14 @@ struct machine_pci_chipset { void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); pci_chipset_tag_t pci_lookup_segment(int); +int pci_intr_enable_msivec(struct pci_attach_args *, int); + void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t); void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, int, bus_addr_t, uint32_t); int _pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +int _pci_intr_map_msivec(struct pci_attach_args *, int, + pci_intr_handle_t *); int _pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *); #define __HAVE_PCI_MSIX diff --git a/sys/conf/files b/sys/conf/files index 7ebeee9c3..fd76e9934 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.729 2024/01/01 18:25:50 kettenis Exp $ +# $OpenBSD: files,v 1.730 2024/02/03 18:51:57 beck Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -960,11 +960,9 @@ file ufs/ffs/ffs_alloc.c ffs | mfs file ufs/ffs/ffs_balloc.c ffs | mfs file ufs/ffs/ffs_inode.c ffs | mfs file ufs/ffs/ffs_subr.c ffs | mfs -file ufs/ffs/ffs_softdep_stub.c ffs | mfs file ufs/ffs/ffs_tables.c ffs | mfs file ufs/ffs/ffs_vfsops.c ffs | mfs file ufs/ffs/ffs_vnops.c ffs | mfs -file ufs/ffs/ffs_softdep.c ffs_softupdates file ufs/mfs/mfs_vfsops.c mfs file ufs/mfs/mfs_vnops.c mfs file ufs/ufs/ufs_bmap.c ffs | mfs | ext2fs diff --git a/sys/ddb/db_interface.h b/sys/ddb/db_interface.h index f9a206783..cccec9ed6 100644 --- a/sys/ddb/db_interface.h +++ b/sys/ddb/db_interface.h @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.h,v 1.26 2023/07/02 19:02:27 cheloha Exp $ */ +/* $OpenBSD: db_interface.h,v 1.27 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: db_interface.h,v 1.1 1996/02/05 01:57:03 christos Exp $ */ /* @@ -78,11 +78,6 @@ void nfs_node_print(void *, int, int (*)(const char *, ...)); /* uvm/uvm_swap.c */ void swap_print_all(int (*)(const char *, ...)); -/* ufs/ffs/ffs_softdep.c */ -struct worklist; -void worklist_print(struct worklist *, int, int (*)(const char *, ...)); -void softdep_print(struct buf *, int, int (*)(const char *, ...)); - /* arch///db_interface.c */ void db_machine_init(void); diff --git a/sys/dev/fdt/bcm2711_pcie.c b/sys/dev/fdt/bcm2711_pcie.c index b96fec4f4..ce8f92217 100644 --- a/sys/dev/fdt/bcm2711_pcie.c +++ b/sys/dev/fdt/bcm2711_pcie.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bcm2711_pcie.c,v 1.11 2022/04/06 18:59:28 naddy Exp $ */ +/* $OpenBSD: bcm2711_pcie.c,v 1.12 2024/02/03 10:37:26 kettenis Exp $ */ /* * Copyright (c) 2020 Mark Kettenis * @@ -299,6 +299,7 @@ bcmpcie_attach(struct device *parent, struct device *self, void *aux) sc->sc_pc.pc_intr_v = sc; sc->sc_pc.pc_intr_map = bcmpcie_intr_map; sc->sc_pc.pc_intr_map_msi = _pci_intr_map_msi; + sc->sc_pc.pc_intr_map_msivec = _pci_intr_map_msivec; sc->sc_pc.pc_intr_map_msix = _pci_intr_map_msix; sc->sc_pc.pc_intr_string = bcmpcie_intr_string; sc->sc_pc.pc_intr_establish = bcmpcie_intr_establish; diff --git a/sys/dev/fdt/dwpcie.c b/sys/dev/fdt/dwpcie.c index 104b951ec..19e45ca20 100644 --- a/sys/dev/fdt/dwpcie.c +++ b/sys/dev/fdt/dwpcie.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dwpcie.c,v 1.50 2023/09/21 19:39:41 patrick Exp $ */ +/* $OpenBSD: dwpcie.c,v 1.51 2024/02/03 10:37:26 kettenis Exp $ */ /* * Copyright (c) 2018 Mark Kettenis * @@ -711,6 +711,7 @@ dwpcie_attach_deferred(struct device *self) sc->sc_pc.pc_intr_v = sc; sc->sc_pc.pc_intr_map = dwpcie_intr_map; sc->sc_pc.pc_intr_map_msi = _pci_intr_map_msi; + sc->sc_pc.pc_intr_map_msivec = _pci_intr_map_msivec; sc->sc_pc.pc_intr_map_msix = _pci_intr_map_msix; sc->sc_pc.pc_intr_string = dwpcie_intr_string; sc->sc_pc.pc_intr_establish = dwpcie_intr_establish; @@ -729,6 +730,8 @@ dwpcie_attach_deferred(struct device *self) OF_getproplen(sc->sc_node, "msi-map") > 0 || sc->sc_msi_addr) pba.pba_flags |= PCI_FLAGS_MSI_ENABLED; + if (OF_getproplen(sc->sc_node, "msi-map") > 0) + pba.pba_flags |= PCI_FLAGS_MSIVEC_ENABLED; /* XXX No working MSI on RK3588 yet. */ if (OF_is_compatible(sc->sc_node, "rockchip,rk3588-pcie")) @@ -1835,6 +1838,8 @@ dwpcie_intr_establish(void *v, pci_intr_handle_t ih, int level, uint64_t addr, data; if (sc->sc_msi_addr) { + if (ih.ih_type == PCI_MSI && ih.ih_intrpin > 0) + return NULL; dm = dwpcie_msi_establish(sc, level, func, arg, name); if (dm == NULL) return NULL; @@ -1845,6 +1850,7 @@ dwpcie_intr_establish(void *v, pci_intr_handle_t ih, int level, * Assume hardware passes Requester ID as * sideband data. */ + addr = ih.ih_intrpin; data = pci_requester_id(ih.ih_pc, ih.ih_tag); cookie = fdt_intr_establish_msi_cpu(sc->sc_node, &addr, &data, level, ci, func, arg, (void *)name); diff --git a/sys/dev/fdt/mvkpcie.c b/sys/dev/fdt/mvkpcie.c index 592adfa48..7620b8738 100644 --- a/sys/dev/fdt/mvkpcie.c +++ b/sys/dev/fdt/mvkpcie.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mvkpcie.c,v 1.13 2022/04/06 18:59:28 naddy Exp $ */ +/* $OpenBSD: mvkpcie.c,v 1.14 2024/02/03 10:37:26 kettenis Exp $ */ /* * Copyright (c) 2018 Mark Kettenis * Copyright (c) 2020 Patrick Wildt @@ -528,6 +528,7 @@ mvkpcie_attach(struct device *parent, struct device *self, void *aux) sc->sc_pc.pc_intr_v = sc; sc->sc_pc.pc_intr_map = mvkpcie_intr_map; sc->sc_pc.pc_intr_map_msi = _pci_intr_map_msi; + sc->sc_pc.pc_intr_map_msivec = _pci_intr_map_msivec; sc->sc_pc.pc_intr_map_msix = _pci_intr_map_msix; sc->sc_pc.pc_intr_string = mvkpcie_intr_string; sc->sc_pc.pc_intr_establish = mvkpcie_intr_establish; @@ -783,7 +784,7 @@ mvkpcie_intr_establish(void *v, pci_intr_handle_t ih, int level, KASSERT(ih.ih_type != PCI_NONE); if (ih.ih_type != PCI_INTX) { - uint64_t addr, data; + uint64_t addr = 0, data; /* Assume hardware passes Requester ID as sideband data. */ data = pci_requester_id(ih.ih_pc, ih.ih_tag); diff --git a/sys/dev/fdt/pciecam.c b/sys/dev/fdt/pciecam.c index ffae96f0b..60b16e0ca 100644 --- a/sys/dev/fdt/pciecam.c +++ b/sys/dev/fdt/pciecam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pciecam.c,v 1.4 2022/04/06 18:59:28 naddy Exp $ */ +/* $OpenBSD: pciecam.c,v 1.5 2024/02/03 10:37:26 kettenis Exp $ */ /* * Copyright (c) 2013,2017 Patrick Wildt * @@ -245,6 +245,7 @@ pciecam_attach(struct device *parent, struct device *self, void *aux) sc->sc_pc.pc_intr_v = sc; sc->sc_pc.pc_intr_map = pciecam_intr_map; sc->sc_pc.pc_intr_map_msi = _pci_intr_map_msi; + sc->sc_pc.pc_intr_map_msivec = _pci_intr_map_msivec; sc->sc_pc.pc_intr_map_msix = _pci_intr_map_msix; sc->sc_pc.pc_intr_string = pciecam_intr_string; sc->sc_pc.pc_intr_establish = pciecam_intr_establish; @@ -391,7 +392,7 @@ pciecam_intr_establish(void *self, pci_intr_handle_t ih, int level, KASSERT(ih.ih_type != PCI_NONE); if (ih.ih_type != PCI_INTX) { - uint64_t addr, data; + uint64_t addr = 0, data; /* Assume hardware passes Requester ID as sideband data. */ data = pci_requester_id(ih.ih_pc, ih.ih_tag); diff --git a/sys/dev/fdt/rkpcie.c b/sys/dev/fdt/rkpcie.c index af73e98f0..4f62be8cf 100644 --- a/sys/dev/fdt/rkpcie.c +++ b/sys/dev/fdt/rkpcie.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rkpcie.c,v 1.17 2023/04/11 00:45:08 jsg Exp $ */ +/* $OpenBSD: rkpcie.c,v 1.18 2024/02/03 10:37:26 kettenis Exp $ */ /* * Copyright (c) 2018 Mark Kettenis * @@ -372,6 +372,7 @@ rkpcie_attach(struct device *parent, struct device *self, void *aux) sc->sc_pc.pc_intr_v = sc; sc->sc_pc.pc_intr_map = rkpcie_intr_map; sc->sc_pc.pc_intr_map_msi = _pci_intr_map_msi; + sc->sc_pc.pc_intr_map_msivec = _pci_intr_map_msivec; sc->sc_pc.pc_intr_map_msix = _pci_intr_map_msix; sc->sc_pc.pc_intr_string = rkpcie_intr_string; sc->sc_pc.pc_intr_establish = rkpcie_intr_establish; @@ -605,7 +606,7 @@ rkpcie_intr_establish(void *v, pci_intr_handle_t ih, int level, KASSERT(ih.ih_type != PCI_NONE); if (ih.ih_type != PCI_INTX) { - uint64_t addr, data; + uint64_t addr = 0, data; /* Assume hardware passes Requester ID as sideband data. */ data = pci_requester_id(ih.ih_pc, ih.ih_tag); diff --git a/sys/dev/ic/qwx.c b/sys/dev/ic/qwx.c index cc13b0978..1441f8a9d 100644 --- a/sys/dev/ic/qwx.c +++ b/sys/dev/ic/qwx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: qwx.c,v 1.14 2024/02/02 15:44:19 stsp Exp $ */ +/* $OpenBSD: qwx.c,v 1.16 2024/02/03 20:07:19 kettenis Exp $ */ /* * Copyright 2023 Stefan Sperling @@ -68,6 +68,10 @@ #include #include +#ifdef __HAVE_FDT +#include +#endif + #include #include @@ -136,6 +140,8 @@ int qwx_mac_start(struct qwx_softc *); void qwx_mac_scan_finish(struct qwx_softc *); int qwx_mac_mgmt_tx_wmi(struct qwx_softc *, struct qwx_vif *, uint8_t, struct mbuf *); +int qwx_dp_tx(struct qwx_softc *, struct qwx_vif *, uint8_t, + struct ieee80211_node *, struct mbuf *); int qwx_dp_tx_send_reo_cmd(struct qwx_softc *, struct dp_rx_tid *, enum hal_reo_cmd_type , struct ath11k_hal_reo_cmd *, void (*func)(struct qwx_dp *, void *, enum hal_reo_cmd_status)); @@ -358,9 +364,7 @@ qwx_tx(struct qwx_softc *sc, struct mbuf *m, struct ieee80211_node *ni) if (frame_type == IEEE80211_FC0_TYPE_MGT) return qwx_mac_mgmt_tx_wmi(sc, arvif, pdev_id, m); - printf("%s: not implemented\n", __func__); - m_freem(m); - return ENOTSUP; + return qwx_dp_tx(sc, arvif, pdev_id, ni, m); } void @@ -1455,10 +1459,38 @@ qwx_hw_wcn6855_rx_desc_mpdu_start_addr2(struct hal_rx_desc *desc) return desc->u.wcn6855.mpdu_start.addr2; } +/* Map from pdev index to hw mac index */ +uint8_t +qwx_hw_ipq8074_mac_from_pdev_id(int pdev_idx) +{ + switch (pdev_idx) { + case 0: + return 0; + case 1: + return 2; + case 2: + return 1; + default: + return ATH11K_INVALID_HW_MAC_ID; + } +} + +uint8_t qwx_hw_ipq6018_mac_from_pdev_id(int pdev_idx) +{ + return pdev_idx; +} + +static inline int +qwx_hw_get_mac_from_pdev_id(struct qwx_softc *sc, int pdev_idx) +{ + if (sc->hw_params.hw_ops->get_hw_mac_from_pdev_id) + return sc->hw_params.hw_ops->get_hw_mac_from_pdev_id(pdev_idx); + + return 0; +} + const struct ath11k_hw_ops ipq8074_ops = { -#if notyet - .get_hw_mac_from_pdev_id = ath11k_hw_ipq8074_mac_from_pdev_id, -#endif + .get_hw_mac_from_pdev_id = qwx_hw_ipq8074_mac_from_pdev_id, .wmi_init_config = qwx_init_wmi_config_ipq8074, .mac_id_to_pdev_id = qwx_hw_mac_id_to_pdev_id_ipq8074, .mac_id_to_srng_id = qwx_hw_mac_id_to_srng_id_ipq8074, @@ -1510,9 +1542,7 @@ const struct ath11k_hw_ops ipq8074_ops = { }; const struct ath11k_hw_ops ipq6018_ops = { -#if notyet - .get_hw_mac_from_pdev_id = ath11k_hw_ipq6018_mac_from_pdev_id, -#endif + .get_hw_mac_from_pdev_id = qwx_hw_ipq6018_mac_from_pdev_id, .wmi_init_config = qwx_init_wmi_config_ipq8074, .mac_id_to_pdev_id = qwx_hw_mac_id_to_pdev_id_ipq8074, .mac_id_to_srng_id = qwx_hw_mac_id_to_srng_id_ipq8074, @@ -1564,9 +1594,7 @@ const struct ath11k_hw_ops ipq6018_ops = { }; const struct ath11k_hw_ops qca6390_ops = { -#if notyet - .get_hw_mac_from_pdev_id = ath11k_hw_ipq8074_mac_from_pdev_id, -#endif + .get_hw_mac_from_pdev_id = qwx_hw_ipq8074_mac_from_pdev_id, .wmi_init_config = qwx_init_wmi_config_qca6390, .mac_id_to_pdev_id = qwx_hw_mac_id_to_pdev_id_qca6390, .mac_id_to_srng_id = qwx_hw_mac_id_to_srng_id_qca6390, @@ -1618,13 +1646,11 @@ const struct ath11k_hw_ops qca6390_ops = { }; const struct ath11k_hw_ops qcn9074_ops = { -#if notyet - .get_hw_mac_from_pdev_id = ath11k_hw_ipq6018_mac_from_pdev_id, -#endif + .get_hw_mac_from_pdev_id = qwx_hw_ipq6018_mac_from_pdev_id, .wmi_init_config = qwx_init_wmi_config_ipq8074, .mac_id_to_pdev_id = qwx_hw_mac_id_to_pdev_id_ipq8074, .mac_id_to_srng_id = qwx_hw_mac_id_to_srng_id_ipq8074, -#ifdef notyet +#if notyet .tx_mesh_enable = ath11k_hw_qcn9074_tx_mesh_enable, .rx_desc_get_first_msdu = ath11k_hw_qcn9074_rx_desc_get_first_msdu, .rx_desc_get_last_msdu = ath11k_hw_qcn9074_rx_desc_get_last_msdu, @@ -1672,13 +1698,11 @@ const struct ath11k_hw_ops qcn9074_ops = { }; const struct ath11k_hw_ops wcn6855_ops = { -#if notyet - .get_hw_mac_from_pdev_id = ath11k_hw_ipq8074_mac_from_pdev_id, -#endif + .get_hw_mac_from_pdev_id = qwx_hw_ipq8074_mac_from_pdev_id, .wmi_init_config = qwx_init_wmi_config_qca6390, .mac_id_to_pdev_id = qwx_hw_mac_id_to_pdev_id_qca6390, .mac_id_to_srng_id = qwx_hw_mac_id_to_srng_id_qca6390, -#ifdef notyet +#if notyet .tx_mesh_enable = ath11k_hw_wcn6855_tx_mesh_enable, .rx_desc_get_first_msdu = ath11k_hw_wcn6855_rx_desc_get_first_msdu, .rx_desc_get_last_msdu = ath11k_hw_wcn6855_rx_desc_get_last_msdu, @@ -1726,9 +1750,7 @@ const struct ath11k_hw_ops wcn6855_ops = { }; const struct ath11k_hw_ops wcn6750_ops = { -#if notyet - .get_hw_mac_from_pdev_id = ath11k_hw_ipq8074_mac_from_pdev_id, -#endif + .get_hw_mac_from_pdev_id = qwx_hw_ipq8074_mac_from_pdev_id, .wmi_init_config = qwx_init_wmi_config_qca6390, .mac_id_to_pdev_id = qwx_hw_mac_id_to_pdev_id_qca6390, .mac_id_to_srng_id = qwx_hw_mac_id_to_srng_id_qca6390, @@ -3052,7 +3074,9 @@ static const struct ath11k_hw_params ath11k_hw_params[] = { .sram_dump = {}, .tcl_ring_retry = true, +#endif .tx_ring_size = DP_TCL_DATA_RING_SIZE, +#ifdef notyet .smp2p_wow_exit = false, #endif }, @@ -3139,7 +3163,9 @@ static const struct ath11k_hw_params ath11k_hw_params[] = { .sram_dump = {}, .tcl_ring_retry = true, +#endif .tx_ring_size = DP_TCL_DATA_RING_SIZE, +#ifdef notyet .smp2p_wow_exit = false, #endif }, @@ -3228,7 +3254,9 @@ static const struct ath11k_hw_params ath11k_hw_params[] = { }, .tcl_ring_retry = true, +#endif .tx_ring_size = DP_TCL_DATA_RING_SIZE, +#ifdef notyet .smp2p_wow_exit = false, #endif }, @@ -3316,7 +3344,9 @@ static const struct ath11k_hw_params ath11k_hw_params[] = { .sram_dump = {}, .tcl_ring_retry = true, +#endif .tx_ring_size = DP_TCL_DATA_RING_SIZE, +#ifdef notyet .smp2p_wow_exit = false, #endif }, @@ -3405,7 +3435,9 @@ static const struct ath11k_hw_params ath11k_hw_params[] = { }, .tcl_ring_retry = true, +#endif .tx_ring_size = DP_TCL_DATA_RING_SIZE, +#ifdef notyet .smp2p_wow_exit = false, #endif }, @@ -3493,7 +3525,9 @@ static const struct ath11k_hw_params ath11k_hw_params[] = { }, .tcl_ring_retry = true, +#endif .tx_ring_size = DP_TCL_DATA_RING_SIZE, +#ifdef notyet .smp2p_wow_exit = false, #endif }, @@ -3578,7 +3612,9 @@ static const struct ath11k_hw_params ath11k_hw_params[] = { .sram_dump = {}, .tcl_ring_retry = false, +#endif .tx_ring_size = DP_TCL_DATA_RING_SIZE_WCN6750, +#ifdef notyet .smp2p_wow_exit = true, #endif }, @@ -7815,7 +7851,15 @@ qwx_core_check_smbios(struct qwx_softc *sc) int qwx_core_check_dt(struct qwx_softc *sc) { - return 0; /* TODO */ +#ifdef __HAVE_FDT + if (sc->sc_node == 0) + return 0; + + OF_getprop(sc->sc_node, "qcom,ath11k-calibration-variant", + sc->qmi_target.bdf_ext, sizeof(sc->qmi_target.bdf_ext) - 1); +#endif + + return 0; } int @@ -9953,6 +9997,51 @@ qwx_dp_link_desc_cleanup(struct qwx_softc *sc, } } +void +qwx_dp_tx_ring_free_tx_data(struct qwx_softc *sc, struct dp_tx_ring *tx_ring) +{ + int i; + + if (tx_ring->data == NULL) + return; + + for (i = 0; i < sc->hw_params.tx_ring_size; i++) { + struct qwx_tx_data *tx_data = &tx_ring->data[i]; + + if (tx_data->map) { + bus_dmamap_unload(sc->sc_dmat, tx_data->map); + bus_dmamap_destroy(sc->sc_dmat, tx_data->map); + } + + m_freem(tx_data->m); + } + + free(tx_ring->data, M_DEVBUF, + sc->hw_params.tx_ring_size * sizeof(struct qwx_tx_data)); + tx_ring->data = NULL; +} + +int +qwx_dp_tx_ring_alloc_tx_data(struct qwx_softc *sc, struct dp_tx_ring *tx_ring) +{ + int i, ret; + + tx_ring->data = mallocarray(sc->hw_params.tx_ring_size, + sizeof(struct qwx_tx_data), M_DEVBUF, M_NOWAIT | M_ZERO); + if (tx_ring->data == NULL) + return ENOMEM; + + for (i = 0; i < sc->hw_params.tx_ring_size; i++) { + struct qwx_tx_data *tx_data = &tx_ring->data[i]; + + ret = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1, MCLBYTES, 0, + BUS_DMA_NOWAIT, &tx_data->map); + if (ret) + return ret; + } + + return 0; +} int qwx_dp_alloc(struct qwx_softc *sc) @@ -10003,8 +10092,13 @@ qwx_dp_alloc(struct qwx_softc *sc) idr_init(&dp->tx_ring[i].txbuf_idr); spin_lock_init(&dp->tx_ring[i].tx_idr_lock); #endif - dp->tx_ring[i].tcl_data_ring_id = i; + ret = qwx_dp_tx_ring_alloc_tx_data(sc, &dp->tx_ring[i]); + if (ret) + goto fail_cmn_srng_cleanup; + dp->tx_ring[i].cur = 0; + dp->tx_ring[i].queued = 0; + dp->tx_ring[i].tcl_data_ring_id = i; dp->tx_ring[i].tx_status_head = 0; dp->tx_ring[i].tx_status_tail = DP_TX_COMP_RING_SIZE - 1; dp->tx_ring[i].tx_status = malloc(size, M_DEVBUF, @@ -10051,6 +10145,7 @@ qwx_dp_free(struct qwx_softc *sc) idr_destroy(&dp->tx_ring[i].txbuf_idr); spin_unlock_bh(&dp->tx_ring[i].tx_idr_lock); #endif + qwx_dp_tx_ring_free_tx_data(sc, &dp->tx_ring[i]); free(dp->tx_ring[i].tx_status, M_DEVBUF, sizeof(struct hal_wbm_release_ring) * DP_TX_COMP_RING_SIZE); dp->tx_ring[i].tx_status = NULL; @@ -14544,9 +14639,146 @@ qwx_dp_vdev_tx_attach(struct qwx_softc *sc, struct qwx_pdev *pdev, qwx_dp_update_vdev_search(sc, arvif); } +void +qwx_dp_tx_status_parse(struct qwx_softc *sc, struct hal_wbm_release_ring *desc, + struct hal_tx_status *ts) +{ + ts->buf_rel_source = FIELD_GET(HAL_WBM_RELEASE_INFO0_REL_SRC_MODULE, + desc->info0); + if (ts->buf_rel_source != HAL_WBM_REL_SRC_MODULE_FW && + ts->buf_rel_source != HAL_WBM_REL_SRC_MODULE_TQM) + return; + + if (ts->buf_rel_source == HAL_WBM_REL_SRC_MODULE_FW) + return; + + ts->status = FIELD_GET(HAL_WBM_RELEASE_INFO0_TQM_RELEASE_REASON, + desc->info0); + ts->ppdu_id = FIELD_GET(HAL_WBM_RELEASE_INFO1_TQM_STATUS_NUMBER, + desc->info1); + ts->try_cnt = FIELD_GET(HAL_WBM_RELEASE_INFO1_TRANSMIT_COUNT, + desc->info1); + ts->ack_rssi = FIELD_GET(HAL_WBM_RELEASE_INFO2_ACK_FRAME_RSSI, + desc->info2); + if (desc->info2 & HAL_WBM_RELEASE_INFO2_FIRST_MSDU) + ts->flags |= HAL_TX_STATUS_FLAGS_FIRST_MSDU; + ts->peer_id = FIELD_GET(HAL_WBM_RELEASE_INFO3_PEER_ID, desc->info3); + ts->tid = FIELD_GET(HAL_WBM_RELEASE_INFO3_TID, desc->info3); + if (desc->rate_stats.info0 & HAL_TX_RATE_STATS_INFO0_VALID) + ts->rate_stats = desc->rate_stats.info0; + else + ts->rate_stats = 0; +} + +void +qwx_dp_tx_process_htt_tx_complete(struct qwx_softc *sc, void *desc, + uint8_t mac_id, uint32_t msdu_id, struct dp_tx_ring *tx_ring) +{ + printf("%s: not implemented\n", __func__); +} + +void +qwx_dp_tx_complete_msdu(struct qwx_softc *sc, struct dp_tx_ring *tx_ring, + uint32_t msdu_id, struct hal_tx_status *ts) +{ + struct qwx_tx_data *tx_data = &tx_ring->data[msdu_id]; + + if (ts->buf_rel_source != HAL_WBM_REL_SRC_MODULE_TQM) { + /* Must not happen */ + return; + } + + bus_dmamap_unload(sc->sc_dmat, tx_data->map); + m_freem(tx_data->m); + tx_data->m = NULL; + + /* TODO: Tx rate adjustment? */ + + if (tx_ring->queued > 0) + tx_ring->queued--; +} + +#define QWX_TX_COMPL_NEXT(x) (((x) + 1) % DP_TX_COMP_RING_SIZE) + int qwx_dp_tx_completion_handler(struct qwx_softc *sc, int ring_id) { + struct qwx_dp *dp = &sc->dp; + int hal_ring_id = dp->tx_ring[ring_id].tcl_comp_ring.ring_id; + struct hal_srng *status_ring = &sc->hal.srng_list[hal_ring_id]; + struct hal_tx_status ts = { 0 }; + struct dp_tx_ring *tx_ring = &dp->tx_ring[ring_id]; + uint32_t *desc; + uint32_t msdu_id; + uint8_t mac_id; +#ifdef notyet + spin_lock_bh(&status_ring->lock); +#endif + qwx_hal_srng_access_begin(sc, status_ring); + + while ((QWX_TX_COMPL_NEXT(tx_ring->tx_status_head) != + tx_ring->tx_status_tail) && + (desc = qwx_hal_srng_dst_get_next_entry(sc, status_ring))) { + memcpy(&tx_ring->tx_status[tx_ring->tx_status_head], desc, + sizeof(struct hal_wbm_release_ring)); + tx_ring->tx_status_head = + QWX_TX_COMPL_NEXT(tx_ring->tx_status_head); + } +#if 0 + if (unlikely((ath11k_hal_srng_dst_peek(ab, status_ring) != NULL) && + (ATH11K_TX_COMPL_NEXT(tx_ring->tx_status_head) == + tx_ring->tx_status_tail))) { + /* TODO: Process pending tx_status messages when kfifo_is_full() */ + ath11k_warn(ab, "Unable to process some of the tx_status ring desc because status_fifo is full\n"); + } +#endif + qwx_hal_srng_access_end(sc, status_ring); +#ifdef notyet + spin_unlock_bh(&status_ring->lock); +#endif + while (QWX_TX_COMPL_NEXT(tx_ring->tx_status_tail) != + tx_ring->tx_status_head) { + struct hal_wbm_release_ring *tx_status; + uint32_t desc_id; + + tx_ring->tx_status_tail = + QWX_TX_COMPL_NEXT(tx_ring->tx_status_tail); + tx_status = &tx_ring->tx_status[tx_ring->tx_status_tail]; + qwx_dp_tx_status_parse(sc, tx_status, &ts); + + desc_id = FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE, + tx_status->buf_addr_info.info1); + mac_id = FIELD_GET(DP_TX_DESC_ID_MAC_ID, desc_id); + if (mac_id >= MAX_RADIOS) + continue; + msdu_id = FIELD_GET(DP_TX_DESC_ID_MSDU_ID, desc_id); + if (msdu_id >= sc->hw_params.tx_ring_size) + continue; + + if (ts.buf_rel_source == HAL_WBM_REL_SRC_MODULE_FW) { + qwx_dp_tx_process_htt_tx_complete(sc, + (void *)tx_status, mac_id, msdu_id, tx_ring); + continue; + } +#if 0 + spin_lock(&tx_ring->tx_idr_lock); + msdu = idr_remove(&tx_ring->txbuf_idr, msdu_id); + if (unlikely(!msdu)) { + ath11k_warn(ab, "tx completion for unknown msdu_id %d\n", + msdu_id); + spin_unlock(&tx_ring->tx_idr_lock); + continue; + } + + spin_unlock(&tx_ring->tx_idr_lock); + ar = ab->pdevs[mac_id].ar; + + if (atomic_dec_and_test(&ar->dp.num_tx_pending)) + wake_up(&ar->dp.tx_empty_waitq); +#endif + qwx_dp_tx_complete_msdu(sc, tx_ring, msdu_id, &ts); + } + return 0; } @@ -21050,6 +21282,7 @@ int qwx_peer_create(struct qwx_softc *sc, struct qwx_vif *arvif, uint8_t pdev_id, struct ieee80211_node *ni, struct peer_create_params *param) { + struct ieee80211com *ic = &sc->sc_ic; struct qwx_node *nq = (struct qwx_node *)ni; struct ath11k_peer *peer; int ret; @@ -21131,11 +21364,12 @@ qwx_peer_create(struct qwx_softc *sc, struct qwx_vif *arvif, uint8_t pdev_id, peer->pdev_id = pdev_id; #if 0 peer->sta = sta; - - if (arvif->vif->type == NL80211_IFTYPE_STATION) { +#endif + if (ic->ic_opmode == IEEE80211_M_STA) { arvif->ast_hash = peer->ast_hash; arvif->ast_idx = peer->hw_peer_id; } +#if 0 peer->sec_type = HAL_ENCRYPT_TYPE_OPEN; peer->sec_type_grp = HAL_ENCRYPT_TYPE_OPEN; @@ -21715,6 +21949,249 @@ peer_clean: return ret; } +enum hal_tcl_encap_type +qwx_dp_tx_get_encap_type(struct qwx_softc *sc) +{ + if (test_bit(ATH11K_FLAG_RAW_MODE, sc->sc_flags)) + return HAL_TCL_ENCAP_TYPE_RAW; +#if 0 + if (tx_info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) + return HAL_TCL_ENCAP_TYPE_ETHERNET; +#endif + return HAL_TCL_ENCAP_TYPE_NATIVE_WIFI; +} + +uint8_t +qwx_dp_tx_get_tid(struct mbuf *m) +{ + struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); + uint16_t qos = ieee80211_get_qos(wh); + uint8_t tid = qos & IEEE80211_QOS_TID; + + return tid; +} + +void +qwx_hal_tx_cmd_desc_setup(struct qwx_softc *sc, void *cmd, + struct hal_tx_info *ti) +{ + struct hal_tcl_data_cmd *tcl_cmd = (struct hal_tcl_data_cmd *)cmd; + + tcl_cmd->buf_addr_info.info0 = FIELD_PREP(BUFFER_ADDR_INFO0_ADDR, + ti->paddr); + tcl_cmd->buf_addr_info.info1 = FIELD_PREP(BUFFER_ADDR_INFO1_ADDR, + ((uint64_t)ti->paddr >> HAL_ADDR_MSB_REG_SHIFT)); + tcl_cmd->buf_addr_info.info1 |= FIELD_PREP( + BUFFER_ADDR_INFO1_RET_BUF_MGR, ti->rbm_id) | + FIELD_PREP(BUFFER_ADDR_INFO1_SW_COOKIE, ti->desc_id); + + tcl_cmd->info0 = + FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_DESC_TYPE, ti->type) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_ENCAP_TYPE, ti->encap_type) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_ENCRYPT_TYPE, ti->encrypt_type) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_SEARCH_TYPE, ti->search_type) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_ADDR_EN, ti->addr_search_flags) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO0_CMD_NUM, ti->meta_data_flags); + + tcl_cmd->info1 = ti->flags0 | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_DATA_LEN, ti->data_len) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_PKT_OFFSET, ti->pkt_offset); + + tcl_cmd->info2 = ti->flags1 | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO2_TID, ti->tid) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO2_LMAC_ID, ti->lmac_id); + + tcl_cmd->info3 = FIELD_PREP(HAL_TCL_DATA_CMD_INFO3_DSCP_TID_TABLE_IDX, + ti->dscp_tid_tbl_idx) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO3_SEARCH_INDEX, ti->bss_ast_idx) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO3_CACHE_SET_NUM, ti->bss_ast_hash); + tcl_cmd->info4 = 0; +#ifdef notyet + if (ti->enable_mesh) + ab->hw_params.hw_ops->tx_mesh_enable(ab, tcl_cmd); +#endif +} + +int +qwx_dp_tx(struct qwx_softc *sc, struct qwx_vif *arvif, uint8_t pdev_id, + struct ieee80211_node *ni, struct mbuf *m) +{ + struct ieee80211com *ic = &sc->sc_ic; + struct qwx_dp *dp = &sc->dp; + struct hal_tx_info ti = {0}; + struct qwx_tx_data *tx_data; + struct hal_srng *tcl_ring; + struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); + struct ieee80211_key *k = NULL; + struct dp_tx_ring *tx_ring; + void *hal_tcl_desc; + uint8_t pool_id; + uint8_t hal_ring_id; + int ret, msdu_id; + uint32_t ring_selector = 0; + uint8_t ring_map = 0; + + if (test_bit(ATH11K_FLAG_CRASH_FLUSH, sc->sc_flags)) { + m_freem(m); + printf("%s: crash flush\n", __func__); + return ESHUTDOWN; + } +#if 0 + if (unlikely(!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) && + !ieee80211_is_data(hdr->frame_control))) + return -ENOTSUPP; +#endif + pool_id = 0; + ring_selector = 0; + + ti.ring_id = ring_selector % sc->hw_params.max_tx_ring; + ti.rbm_id = sc->hw_params.hal_params->tcl2wbm_rbm_map[ti.ring_id].rbm_id; + + ring_map |= (1 << ti.ring_id); + + tx_ring = &dp->tx_ring[ti.ring_id]; + + if (tx_ring->queued >= sc->hw_params.tx_ring_size) { + m_freem(m); + return ENOSPC; + } + + msdu_id = tx_ring->cur; + tx_data = &tx_ring->data[msdu_id]; + if (tx_data->m != NULL) { + m_freem(m); + return ENOSPC; + } + + ti.desc_id = FIELD_PREP(DP_TX_DESC_ID_MAC_ID, pdev_id) | + FIELD_PREP(DP_TX_DESC_ID_MSDU_ID, msdu_id) | + FIELD_PREP(DP_TX_DESC_ID_POOL_ID, pool_id); + ti.encap_type = qwx_dp_tx_get_encap_type(sc); + + ti.meta_data_flags = arvif->tcl_metadata; + + if (ti.encap_type == HAL_TCL_ENCAP_TYPE_RAW) { +#if 0 + if (skb_cb->flags & ATH11K_SKB_CIPHER_SET) { + ti.encrypt_type = + ath11k_dp_tx_get_encrypt_type(skb_cb->cipher); + + if (ieee80211_has_protected(hdr->frame_control)) + skb_put(skb, IEEE80211_CCMP_MIC_LEN); + } else +#endif + ti.encrypt_type = HAL_ENCRYPT_TYPE_OPEN; + + if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { + k = ieee80211_get_txkey(ic, wh, ni); + if ((m = ieee80211_encrypt(ic, m, k)) == NULL) { + printf("%s: encrypt failed\n", __func__); + return ENOBUFS; + } + /* 802.11 header may have moved. */ + wh = mtod(m, struct ieee80211_frame *); + } + } + + ti.addr_search_flags = arvif->hal_addr_search_flags; + ti.search_type = arvif->search_type; + ti.type = HAL_TCL_DESC_TYPE_BUFFER; + ti.pkt_offset = 0; + ti.lmac_id = qwx_hw_get_mac_from_pdev_id(sc, pdev_id); + ti.bss_ast_hash = arvif->ast_hash; + ti.bss_ast_idx = arvif->ast_idx; + ti.dscp_tid_tbl_idx = 0; +#if 0 + if (likely(skb->ip_summed == CHECKSUM_PARTIAL && + ti.encap_type != HAL_TCL_ENCAP_TYPE_RAW)) { + ti.flags0 |= FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_IP4_CKSUM_EN, 1) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_UDP4_CKSUM_EN, 1) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_UDP6_CKSUM_EN, 1) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_TCP4_CKSUM_EN, 1) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_TCP6_CKSUM_EN, 1); + } + + if (ieee80211_vif_is_mesh(arvif->vif)) + ti.enable_mesh = true; +#endif + ti.flags1 |= FIELD_PREP(HAL_TCL_DATA_CMD_INFO2_TID_OVERWRITE, 1); + + ti.tid = qwx_dp_tx_get_tid(m); +#if 0 + switch (ti.encap_type) { + case HAL_TCL_ENCAP_TYPE_NATIVE_WIFI: + ath11k_dp_tx_encap_nwifi(skb); + break; + case HAL_TCL_ENCAP_TYPE_RAW: + if (!test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags)) { + ret = -EINVAL; + goto fail_remove_idr; + } + break; + case HAL_TCL_ENCAP_TYPE_ETHERNET: + /* no need to encap */ + break; + case HAL_TCL_ENCAP_TYPE_802_3: + default: + /* TODO: Take care of other encap modes as well */ + ret = -EINVAL; + atomic_inc(&ab->soc_stats.tx_err.misc_fail); + goto fail_remove_idr; + } +#endif + ret = bus_dmamap_load_mbuf(sc->sc_dmat, tx_data->map, + m, BUS_DMA_WRITE | BUS_DMA_NOWAIT); + if (ret) { + printf("%s: failed to map Tx buffer: %d\n", + sc->sc_dev.dv_xname, ret); + m_freem(m); + return ret; + } + ti.paddr = tx_data->map->dm_segs[0].ds_addr; + + ti.data_len = m->m_pkthdr.len; + + hal_ring_id = tx_ring->tcl_data_ring.ring_id; + tcl_ring = &sc->hal.srng_list[hal_ring_id]; +#ifdef notyet + spin_lock_bh(&tcl_ring->lock); +#endif + qwx_hal_srng_access_begin(sc, tcl_ring); + + hal_tcl_desc = (void *)qwx_hal_srng_src_get_next_entry(sc, tcl_ring); + if (!hal_tcl_desc) { + printf("%s: hal_tcl_desc == NULL\n", __func__); + /* NOTE: It is highly unlikely we'll be running out of tcl_ring + * desc because the desc is directly enqueued onto hw queue. + */ + qwx_hal_srng_access_end(sc, tcl_ring); +#if 0 + ab->soc_stats.tx_err.desc_na[ti.ring_id]++; +#endif +#ifdef notyet + spin_unlock_bh(&tcl_ring->lock); +#endif + bus_dmamap_unload(sc->sc_dmat, tx_data->map); + m_freem(m); + return ENOMEM; + } + + tx_data->m = m; + + qwx_hal_tx_cmd_desc_setup(sc, + hal_tcl_desc + sizeof(struct hal_tlv_hdr), &ti); + + qwx_hal_srng_access_end(sc, tcl_ring); + + qwx_dp_shadow_start_timer(sc, tcl_ring, &dp->tx_ring_timer[ti.ring_id]); +#ifdef notyet + spin_unlock_bh(&tcl_ring->lock); +#endif + tx_ring->queued++; + tx_ring->cur = (tx_ring->cur + 1) % sc->hw_params.tx_ring_size; + return 0; +} + int qwx_mac_station_add(struct qwx_softc *sc, struct qwx_vif *arvif, uint8_t pdev_id, struct ieee80211_node *ni) diff --git a/sys/dev/ic/qwxreg.h b/sys/dev/ic/qwxreg.h index d5a4aab50..2e4db5501 100644 --- a/sys/dev/ic/qwxreg.h +++ b/sys/dev/ic/qwxreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: qwxreg.h,v 1.5 2024/02/02 15:44:19 stsp Exp $ */ +/* $OpenBSD: qwxreg.h,v 1.6 2024/02/03 10:03:18 stsp Exp $ */ /* * Copyright (c) 2021-2022, Qualcomm Innovation Center, Inc. @@ -38,6 +38,16 @@ * core.h */ +#define ATH11K_TX_MGMT_NUM_PENDING_MAX 512 + +#define ATH11K_TX_MGMT_TARGET_MAX_SUPPORT_WMI 64 + +/* Pending management packets threshold for dropping probe responses */ +#define ATH11K_PRB_RSP_DROP_THRESHOLD ((ATH11K_TX_MGMT_TARGET_MAX_SUPPORT_WMI * 3) / 4) + +#define ATH11K_INVALID_HW_MAC_ID 0xFF +#define ATH11K_CONNECTION_LOSS_HZ (3 * HZ) + enum ath11k_hw_rev { ATH11K_HW_IPQ8074, ATH11K_HW_QCA6390_HW20, diff --git a/sys/dev/ic/qwxvar.h b/sys/dev/ic/qwxvar.h index ac915ac88..e27bca93f 100644 --- a/sys/dev/ic/qwxvar.h +++ b/sys/dev/ic/qwxvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: qwxvar.h,v 1.9 2024/02/02 15:44:19 stsp Exp $ */ +/* $OpenBSD: qwxvar.h,v 1.11 2024/02/03 20:07:19 kettenis Exp $ */ /* * Copyright (c) 2018-2019 The Linux Foundation. @@ -113,6 +113,53 @@ struct ath11k_hw_hal_params { const struct ath11k_hw_tcl2wbm_rbm_map *tcl2wbm_rbm_map; }; +struct hal_tx_info { + uint16_t meta_data_flags; /* %HAL_TCL_DATA_CMD_INFO0_META_ */ + uint8_t ring_id; + uint32_t desc_id; + enum hal_tcl_desc_type type; + enum hal_tcl_encap_type encap_type; + uint64_t paddr; + uint32_t data_len; + uint32_t pkt_offset; + enum hal_encrypt_type encrypt_type; + uint32_t flags0; /* %HAL_TCL_DATA_CMD_INFO1_ */ + uint32_t flags1; /* %HAL_TCL_DATA_CMD_INFO2_ */ + uint16_t addr_search_flags; /* %HAL_TCL_DATA_CMD_INFO0_ADDR(X/Y)_ */ + uint16_t bss_ast_hash; + uint16_t bss_ast_idx; + uint8_t tid; + uint8_t search_type; /* %HAL_TX_ADDR_SEARCH_ */ + uint8_t lmac_id; + uint8_t dscp_tid_tbl_idx; + bool enable_mesh; + uint8_t rbm_id; +}; + +/* TODO: Check if the actual desc macros can be used instead */ +#define HAL_TX_STATUS_FLAGS_FIRST_MSDU BIT(0) +#define HAL_TX_STATUS_FLAGS_LAST_MSDU BIT(1) +#define HAL_TX_STATUS_FLAGS_MSDU_IN_AMSDU BIT(2) +#define HAL_TX_STATUS_FLAGS_RATE_STATS_VALID BIT(3) +#define HAL_TX_STATUS_FLAGS_RATE_LDPC BIT(4) +#define HAL_TX_STATUS_FLAGS_RATE_STBC BIT(5) +#define HAL_TX_STATUS_FLAGS_OFDMA BIT(6) + +#define HAL_TX_STATUS_DESC_LEN sizeof(struct hal_wbm_release_ring) + +/* Tx status parsed from srng desc */ +struct hal_tx_status { + enum hal_wbm_rel_src_module buf_rel_source; + enum hal_wbm_tqm_rel_reason status; + uint8_t ack_rssi; + uint32_t flags; /* %HAL_TX_STATUS_FLAGS_ */ + uint32_t ppdu_id; + uint8_t try_cnt; + uint8_t tid; + uint16_t peer_id; + uint32_t rate_stats; +}; + struct ath11k_hw_params { const char *name; uint16_t hw_rev; @@ -209,9 +256,7 @@ struct ath11k_hw_params { }; struct ath11k_hw_ops { -#if notyet uint8_t (*get_hw_mac_from_pdev_id)(int pdev_id); -#endif void (*wmi_init_config)(struct qwx_softc *sc, struct target_resource_config *config); int (*mac_id_to_pdev_id)(struct ath11k_hw_params *hw, int mac_id); @@ -922,11 +967,9 @@ struct dp_tx_ring { uint8_t tcl_data_ring_id; struct dp_srng tcl_data_ring; struct dp_srng tcl_comp_ring; -#if 0 - struct idr txbuf_idr; - /* Protects txbuf_idr and num_pending */ - spinlock_t tx_idr_lock; -#endif + int cur; + int queued; + struct qwx_tx_data *data; struct hal_wbm_release_ring *tx_status; int tx_status_head; int tx_status_tail; @@ -1585,6 +1628,7 @@ struct qwx_softc { struct device sc_dev; struct ieee80211com sc_ic; uint32_t sc_flags; + int sc_node; int (*sc_newstate)(struct ieee80211com *, enum ieee80211_state, int); diff --git a/sys/dev/pci/drm/drm_edid.c b/sys/dev/pci/drm/drm_edid.c index 3766ff2cf..ba92bd045 100644 --- a/sys/dev/pci/drm/drm_edid.c +++ b/sys/dev/pci/drm/drm_edid.c @@ -2120,8 +2120,10 @@ static struct edid *edid_filter_invalid_blocks(struct edid *edid, kfree(edid); #else new = kmalloc(*alloc_size, GFP_KERNEL); - if (!new) + if (!new) { kfree(edid); + return NULL; + } memcpy(new, edid, EDID_LENGTH); kfree(edid); #endif diff --git a/sys/dev/pci/if_qwx_pci.c b/sys/dev/pci/if_qwx_pci.c index 5c560dc9f..9365d40c1 100644 --- a/sys/dev/pci/if_qwx_pci.c +++ b/sys/dev/pci/if_qwx_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_qwx_pci.c,v 1.4 2024/01/25 17:00:21 stsp Exp $ */ +/* $OpenBSD: if_qwx_pci.c,v 1.5 2024/02/03 20:07:19 kettenis Exp $ */ /* * Copyright 2023 Stefan Sperling @@ -770,6 +770,10 @@ qwx_pci_attach(struct device *parent, struct device *self, void *aux) psc->sc_pc = pa->pa_pc; psc->sc_tag = pa->pa_tag; +#ifdef __HAVE_FDT + sc->sc_node = PCITAG_NODE(pa->pa_tag); +#endif + rw_init(&sc->ioctl_rwl, "qwxioctl"); sreg = pci_conf_read(psc->sc_pc, psc->sc_tag, PCI_SUBSYS_ID_REG); diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index fa009f96b..a595e919e 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcivar.h,v 1.78 2023/04/13 15:07:43 miod Exp $ */ +/* $OpenBSD: pcivar.h,v 1.79 2024/02/03 10:37:26 kettenis Exp $ */ /* $NetBSD: pcivar.h,v 1.23 1997/06/06 23:48:05 thorpej Exp $ */ /* @@ -161,13 +161,15 @@ struct pci_attach_args { * * OpenBSD doesn't actually use them yet -- csapuntz@cvs.openbsd.org */ -#define PCI_FLAGS_IO_ENABLED 0x01 /* I/O space is enabled */ -#define PCI_FLAGS_MEM_ENABLED 0x02 /* memory space is enabled */ -#define PCI_FLAGS_MRL_OKAY 0x04 /* Memory Read Line okay */ -#define PCI_FLAGS_MRM_OKAY 0x08 /* Memory Read Multiple okay */ -#define PCI_FLAGS_MWI_OKAY 0x10 /* Memory Write and Invalidate +#define PCI_FLAGS_IO_ENABLED 0x01 /* I/O space is enabled */ +#define PCI_FLAGS_MEM_ENABLED 0x02 /* memory space is enabled */ +#define PCI_FLAGS_MRL_OKAY 0x04 /* Memory Read Line okay */ +#define PCI_FLAGS_MRM_OKAY 0x08 /* Memory Read Multiple okay */ +#define PCI_FLAGS_MWI_OKAY 0x10 /* Memory Write and Invalidate okay */ -#define PCI_FLAGS_MSI_ENABLED 0x20 /* Message Signaled Interrupt +#define PCI_FLAGS_MSI_ENABLED 0x20 /* Message Signaled Interrupt + enabled */ +#define PCI_FLAGS_MSIVEC_ENABLED 0x40 /* Multiple Message Capability enabled */ /* diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index decea16cb..b73f2d1de 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.429 2022/12/21 09:54:23 kn Exp $ */ +/* $OpenBSD: softraid.c,v 1.430 2024/02/03 18:51:58 beck Exp $ */ /* * Copyright (c) 2007, 2008, 2009 Marco Peereboom * Copyright (c) 2008 Chris Kuethe @@ -445,7 +445,6 @@ sr_rw(struct sr_softc *sc, dev_t dev, char *buf, size_t size, daddr_t blkno, splx(s); } - LIST_INIT(&b.b_dep); VOP_STRATEGY(vp, &b); biowait(&b); @@ -2018,8 +2017,6 @@ sr_ccb_rw(struct sr_discipline *sd, int chunk, daddr_t blkno, splx(s); } - LIST_INIT(&ccb->ccb_buf.b_dep); - DNPRINTF(SR_D_DIS, "%s: %s %s ccb " "b_bcount %ld b_blkno %lld b_flags 0x%0lx b_data %p\n", DEVNAME(sd->sd_sc), sd->sd_meta->ssd_devname, sd->sd_name, diff --git a/sys/kern/kern_physio.c b/sys/kern/kern_physio.c index 4cbe739f3..45661fcca 100644 --- a/sys/kern/kern_physio.c +++ b/sys/kern/kern_physio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_physio.c,v 1.48 2023/11/24 00:15:42 asou Exp $ */ +/* $OpenBSD: kern_physio.c,v 1.49 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: kern_physio.c,v 1.28 1997/05/19 10:43:28 pk Exp $ */ /*- @@ -84,7 +84,6 @@ physio(void (*strategy)(struct buf *), dev_t dev, int flags, bp->b_error = 0; bp->b_proc = p; bp->b_flags = B_BUSY; - LIST_INIT(&bp->b_dep); splx(s); /* diff --git a/sys/kern/spec_vnops.c b/sys/kern/spec_vnops.c index f43ceda68..48a06164b 100644 --- a/sys/kern/spec_vnops.c +++ b/sys/kern/spec_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spec_vnops.c,v 1.111 2022/12/05 23:18:37 deraadt Exp $ */ +/* $OpenBSD: spec_vnops.c,v 1.112 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: spec_vnops.c,v 1.29 1996/04/22 01:42:38 christos Exp $ */ /* @@ -444,9 +444,6 @@ spec_strategy(void *v) struct buf *bp = ap->a_bp; int maj = major(bp->b_dev); - if (LIST_FIRST(&bp->b_dep) != NULL) - buf_start(bp); - (*bdevsw[maj].d_strategy)(bp); return (0); } diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 41a6bd704..aa28062e1 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.315 2024/01/26 18:24:23 mvs Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.316 2024/02/03 22:50:08 mvs Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -72,26 +72,20 @@ int filt_soread(struct knote *kn, long hint); void filt_sowdetach(struct knote *kn); int filt_sowrite(struct knote *kn, long hint); int filt_soexcept(struct knote *kn, long hint); -int filt_solisten(struct knote *kn, long hint); -int filt_somodify(struct kevent *kev, struct knote *kn); -int filt_soprocess(struct knote *kn, struct kevent *kev); -const struct filterops solisten_filtops = { - .f_flags = FILTEROP_ISFD | FILTEROP_MPSAFE, - .f_attach = NULL, - .f_detach = filt_sordetach, - .f_event = filt_solisten, - .f_modify = filt_somodify, - .f_process = filt_soprocess, -}; +int filt_sowmodify(struct kevent *kev, struct knote *kn); +int filt_sowprocess(struct knote *kn, struct kevent *kev); + +int filt_sormodify(struct kevent *kev, struct knote *kn); +int filt_sorprocess(struct knote *kn, struct kevent *kev); const struct filterops soread_filtops = { .f_flags = FILTEROP_ISFD | FILTEROP_MPSAFE, .f_attach = NULL, .f_detach = filt_sordetach, .f_event = filt_soread, - .f_modify = filt_somodify, - .f_process = filt_soprocess, + .f_modify = filt_sormodify, + .f_process = filt_sorprocess, }; const struct filterops sowrite_filtops = { @@ -99,8 +93,8 @@ const struct filterops sowrite_filtops = { .f_attach = NULL, .f_detach = filt_sowdetach, .f_event = filt_sowrite, - .f_modify = filt_somodify, - .f_process = filt_soprocess, + .f_modify = filt_sowmodify, + .f_process = filt_sowprocess, }; const struct filterops soexcept_filtops = { @@ -108,18 +102,8 @@ const struct filterops soexcept_filtops = { .f_attach = NULL, .f_detach = filt_sordetach, .f_event = filt_soexcept, - .f_modify = filt_somodify, - .f_process = filt_soprocess, -}; - -void klist_soassertlk(void *); -int klist_solock(void *); -void klist_sounlock(void *, int); - -const struct klistops socket_klistops = { - .klo_assertlk = klist_soassertlk, - .klo_lock = klist_solock, - .klo_unlock = klist_sounlock, + .f_modify = filt_sormodify, + .f_process = filt_sorprocess, }; #ifndef SOMINCONN @@ -158,8 +142,10 @@ soalloc(const struct domain *dp, int wait) return (NULL); rw_init_flags(&so->so_lock, dp->dom_name, RWL_DUPOK); refcnt_init(&so->so_refcnt); - klist_init(&so->so_rcv.sb_klist, &socket_klistops, so); - klist_init(&so->so_snd.sb_klist, &socket_klistops, so); + mtx_init(&so->so_rcv.sb_mtx, IPL_MPFLOOR); + mtx_init(&so->so_snd.sb_mtx, IPL_MPFLOOR); + klist_init_mutex(&so->so_rcv.sb_klist, &so->so_rcv.sb_mtx); + klist_init_mutex(&so->so_snd.sb_klist, &so->so_snd.sb_mtx); sigio_init(&so->so_sigio); TAILQ_INIT(&so->so_q0); TAILQ_INIT(&so->so_q); @@ -1757,7 +1743,7 @@ somove(struct socket *so, int wait) void sorwakeup(struct socket *so) { - soassertlocked(so); + soassertlocked_readonly(so); #ifdef SOCKET_SPLICE if (so->so_rcv.sb_flags & SB_SPLICE) { @@ -1785,7 +1771,7 @@ sorwakeup(struct socket *so) void sowwakeup(struct socket *so) { - soassertlocked(so); + soassertlocked_readonly(so); #ifdef SOCKET_SPLICE if (so->so_snd.sb_flags & SB_SPLICE) @@ -2134,7 +2120,46 @@ void sohasoutofband(struct socket *so) { pgsigio(&so->so_sigio, SIGURG, 0); - knote_locked(&so->so_rcv.sb_klist, 0); + knote(&so->so_rcv.sb_klist, 0); +} + +void +sofilt_lock(struct socket *so, struct sockbuf *sb) +{ + switch (so->so_proto->pr_domain->dom_family) { + case PF_INET: + case PF_INET6: + NET_LOCK_SHARED(); + break; + default: + rw_enter_write(&so->so_lock); + break; + } + + mtx_enter(&sb->sb_mtx); +} + +void +sofilt_unlock(struct socket *so, struct sockbuf *sb) +{ + mtx_leave(&sb->sb_mtx); + + switch (so->so_proto->pr_domain->dom_family) { + case PF_INET: + case PF_INET6: + NET_UNLOCK_SHARED(); + break; + default: + rw_exit_write(&so->so_lock); + break; + } +} + +static inline void +sofilt_assert_locked(struct socket *so, struct sockbuf *sb) +{ + MUTEX_ASSERT_LOCKED(&sb->sb_mtx); + soassertlocked_readonly(so); } int @@ -2143,13 +2168,9 @@ soo_kqfilter(struct file *fp, struct knote *kn) struct socket *so = kn->kn_fp->f_data; struct sockbuf *sb; - solock(so); switch (kn->kn_filter) { case EVFILT_READ: - if (so->so_options & SO_ACCEPTCONN) - kn->kn_fop = &solisten_filtops; - else - kn->kn_fop = &soread_filtops; + kn->kn_fop = &soread_filtops; sb = &so->so_rcv; break; case EVFILT_WRITE: @@ -2161,12 +2182,10 @@ soo_kqfilter(struct file *fp, struct knote *kn) sb = &so->so_rcv; break; default: - sounlock(so); return (EINVAL); } - klist_insert_locked(&sb->sb_klist, kn); - sounlock(so); + klist_insert(&sb->sb_klist, kn); return (0); } @@ -2185,7 +2204,23 @@ filt_soread(struct knote *kn, long hint) struct socket *so = kn->kn_fp->f_data; int rv = 0; - soassertlocked(so); + sofilt_assert_locked(so, &so->so_rcv); + + if (so->so_options & SO_ACCEPTCONN) { + kn->kn_data = so->so_qlen; + rv = (kn->kn_data != 0); + + if (kn->kn_flags & (__EV_POLL | __EV_SELECT)) { + if (so->so_state & SS_ISDISCONNECTED) { + kn->kn_flags |= __EV_HUP; + rv = 1; + } else { + rv = soreadable(so); + } + } + + return rv; + } kn->kn_data = so->so_rcv.sb_cc; #ifdef SOCKET_SPLICE @@ -2226,7 +2261,7 @@ filt_sowrite(struct knote *kn, long hint) struct socket *so = kn->kn_fp->f_data; int rv; - soassertlocked(so); + sofilt_assert_locked(so, &so->so_snd); kn->kn_data = sbspace(so, &so->so_snd); if (so->so_snd.sb_state & SS_CANTSENDMORE) { @@ -2257,7 +2292,7 @@ filt_soexcept(struct knote *kn, long hint) struct socket *so = kn->kn_fp->f_data; int rv = 0; - soassertlocked(so); + sofilt_assert_locked(so, &so->so_rcv); #ifdef SOCKET_SPLICE if (isspliced(so)) { @@ -2283,77 +2318,55 @@ filt_soexcept(struct knote *kn, long hint) } int -filt_solisten(struct knote *kn, long hint) -{ - struct socket *so = kn->kn_fp->f_data; - int active; - - soassertlocked(so); - - kn->kn_data = so->so_qlen; - active = (kn->kn_data != 0); - - if (kn->kn_flags & (__EV_POLL | __EV_SELECT)) { - if (so->so_state & SS_ISDISCONNECTED) { - kn->kn_flags |= __EV_HUP; - active = 1; - } else { - active = soreadable(so); - } - } - - return (active); -} - -int -filt_somodify(struct kevent *kev, struct knote *kn) +filt_sowmodify(struct kevent *kev, struct knote *kn) { struct socket *so = kn->kn_fp->f_data; int rv; - solock(so); + sofilt_lock(so, &so->so_snd); rv = knote_modify(kev, kn); - sounlock(so); + sofilt_unlock(so, &so->so_snd); return (rv); } int -filt_soprocess(struct knote *kn, struct kevent *kev) +filt_sowprocess(struct knote *kn, struct kevent *kev) { struct socket *so = kn->kn_fp->f_data; int rv; - solock(so); + sofilt_lock(so, &so->so_snd); rv = knote_process(kn, kev); - sounlock(so); + sofilt_unlock(so, &so->so_snd); return (rv); } -void -klist_soassertlk(void *arg) +int +filt_sormodify(struct kevent *kev, struct knote *kn) { - struct socket *so = arg; + struct socket *so = kn->kn_fp->f_data; + int rv; - soassertlocked(so); + sofilt_lock(so, &so->so_rcv); + rv = knote_modify(kev, kn); + sofilt_unlock(so, &so->so_rcv); + + return (rv); } int -klist_solock(void *arg) +filt_sorprocess(struct knote *kn, struct kevent *kev) { - struct socket *so = arg; + struct socket *so = kn->kn_fp->f_data; + int rv; - solock(so); - return (1); -} + sofilt_lock(so, &so->so_rcv); + rv = knote_process(kn, kev); + sofilt_unlock(so, &so->so_rcv); -void -klist_sounlock(void *arg, int ls) -{ - struct socket *so = arg; - - sounlock(so); + return (rv); } #ifdef DDB diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index 5b55090dd..a86dd7d86 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.140 2024/01/11 14:15:11 bluhm Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.141 2024/02/03 22:50:08 mvs Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -439,7 +439,7 @@ sounlock_shared(struct socket *so) } void -soassertlocked(struct socket *so) +soassertlocked_readonly(struct socket *so) { switch (so->so_proto->pr_domain->dom_family) { case PF_INET: @@ -452,6 +452,27 @@ soassertlocked(struct socket *so) } } +void +soassertlocked(struct socket *so) +{ + switch (so->so_proto->pr_domain->dom_family) { + case PF_INET: + case PF_INET6: + if (rw_status(&netlock) == RW_READ) { + NET_ASSERT_LOCKED(); + + if (splassert_ctl > 0 && pru_locked(so) == 0 && + rw_status(&so->so_lock) != RW_WRITE) + splassert_fail(0, RW_WRITE, __func__); + } else + NET_ASSERT_LOCKED_EXCLUSIVE(); + break; + default: + rw_assert_wrlock(&so->so_lock); + break; + } +} + int sosleep_nsec(struct socket *so, void *ident, int prio, const char *wmesg, uint64_t nsecs) @@ -489,46 +510,62 @@ sbwait(struct socket *so, struct sockbuf *sb) soassertlocked(so); + mtx_enter(&sb->sb_mtx); sb->sb_flags |= SB_WAIT; + mtx_leave(&sb->sb_mtx); + return sosleep_nsec(so, &sb->sb_cc, prio, "netio", sb->sb_timeo_nsecs); } int sblock(struct socket *so, struct sockbuf *sb, int flags) { - int error, prio = PSOCK; + int error = 0, prio = PSOCK; soassertlocked(so); + mtx_enter(&sb->sb_mtx); if ((sb->sb_flags & SB_LOCK) == 0) { sb->sb_flags |= SB_LOCK; - return (0); + goto out; + } + if ((flags & SBL_WAIT) == 0) { + error = EWOULDBLOCK; + goto out; } - if ((flags & SBL_WAIT) == 0) - return (EWOULDBLOCK); if (!(flags & SBL_NOINTR || sb->sb_flags & SB_NOINTR)) prio |= PCATCH; while (sb->sb_flags & SB_LOCK) { sb->sb_flags |= SB_WANT; + mtx_leave(&sb->sb_mtx); error = sosleep_nsec(so, &sb->sb_flags, prio, "netlck", INFSLP); if (error) return (error); + mtx_enter(&sb->sb_mtx); } sb->sb_flags |= SB_LOCK; - return (0); +out: + mtx_leave(&sb->sb_mtx); + + return (error); } void sbunlock(struct socket *so, struct sockbuf *sb) { - soassertlocked(so); + int dowakeup = 0; + mtx_enter(&sb->sb_mtx); sb->sb_flags &= ~SB_LOCK; if (sb->sb_flags & SB_WANT) { sb->sb_flags &= ~SB_WANT; - wakeup(&sb->sb_flags); + dowakeup = 1; } + mtx_leave(&sb->sb_mtx); + + if (dowakeup) + wakeup(&sb->sb_flags); } /* @@ -539,15 +576,24 @@ sbunlock(struct socket *so, struct sockbuf *sb) void sowakeup(struct socket *so, struct sockbuf *sb) { - soassertlocked(so); + int dowakeup = 0, dopgsigio = 0; + mtx_enter(&sb->sb_mtx); if (sb->sb_flags & SB_WAIT) { sb->sb_flags &= ~SB_WAIT; - wakeup(&sb->sb_cc); + dowakeup = 1; } if (sb->sb_flags & SB_ASYNC) - pgsigio(&so->so_sigio, SIGIO, 0); + dopgsigio = 1; + knote_locked(&sb->sb_klist, 0); + mtx_leave(&sb->sb_mtx); + + if (dowakeup) + wakeup(&sb->sb_cc); + + if (dopgsigio) + pgsigio(&so->so_sigio, SIGIO, 0); } /* diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index c258936d7..c57950af2 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_syscalls.c,v 1.216 2024/01/03 11:07:04 bluhm Exp $ */ +/* $OpenBSD: uipc_syscalls.c,v 1.217 2024/02/03 22:50:09 mvs Exp $ */ /* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */ /* @@ -326,7 +326,7 @@ doaccept(struct proc *p, int sock, struct sockaddr *name, socklen_t *anamelen, : (flags & SOCK_NONBLOCK ? FNONBLOCK : 0); /* connection has been removed from the listen queue */ - knote_locked(&head->so_rcv.sb_klist, 0); + knote(&head->so_rcv.sb_klist, 0); if (persocket) sounlock(head); diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 3b2d20986..04f8fb1ab 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_bio.c,v 1.212 2023/04/26 15:13:52 beck Exp $ */ +/* $OpenBSD: vfs_bio.c,v 1.213 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */ /* @@ -65,7 +65,6 @@ int fliphigh; int nobuffers; int needbuffer; -struct bio_ops bioops; /* private bufcache functions */ void bufcache_init(void); @@ -120,8 +119,6 @@ buf_put(struct buf *bp) if (bp->b_vnbufs.le_next != NOLIST && bp->b_vnbufs.le_next != (void *)-1) panic("buf_put: still on the vnode list"); - if (!LIST_EMPTY(&bp->b_dep)) - panic("buf_put: b_dep is not empty"); #endif LIST_REMOVE(bp, b_list); @@ -879,13 +876,6 @@ brelse(struct buf *bp) if (bp->b_data != NULL) KASSERT(bp->b_bufsize > 0); - /* - * softdep is basically incompatible with not caching buffers - * that have dependencies, so this buffer must be cached - */ - if (LIST_FIRST(&bp->b_dep) != NULL) - CLR(bp->b_flags, B_NOCACHE); - /* * Determine which queue the buffer should be on, then put it there. */ @@ -904,9 +894,6 @@ brelse(struct buf *bp) * If the buffer is invalid, free it now rather than leaving * it in a queue and wasting memory. */ - if (LIST_FIRST(&bp->b_dep) != NULL) - buf_deallocate(bp); - if (ISSET(bp->b_flags, B_DELWRI)) { CLR(bp->b_flags, B_DELWRI); } @@ -1150,7 +1137,6 @@ buf_get(struct vnode *vp, daddr_t blkno, size_t size) bp->b_freelist.tqe_next = NOLIST; bp->b_dev = NODEV; - LIST_INIT(&bp->b_dep); bp->b_bcount = size; buf_acquire_nomap(bp); @@ -1243,16 +1229,6 @@ buf_daemon(void *arg) if (!ISSET(bp->b_flags, B_DELWRI)) panic("Clean buffer on dirty queue"); #endif - if (LIST_FIRST(&bp->b_dep) != NULL && - !ISSET(bp->b_flags, B_DEFERRED) && - buf_countdeps(bp, 0, 0)) { - SET(bp->b_flags, B_DEFERRED); - s = splbio(); - bufcache_release(bp); - buf_release(bp); - continue; - } - bawrite(bp); pushed++; @@ -1321,9 +1297,6 @@ biodone(struct buf *bp) if (bp->b_bq) bufq_done(bp->b_bq, bp); - if (LIST_FIRST(&bp->b_dep) != NULL) - buf_complete(bp); - if (!ISSET(bp->b_flags, B_READ)) { CLR(bp->b_flags, B_WRITEINPROG); vwakeup(bp->b_vp); diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 650fe5b61..41c73c797 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_subr.c,v 1.318 2022/12/26 19:25:49 miod Exp $ */ +/* $OpenBSD: vfs_subr.c,v 1.319 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */ /* @@ -1819,6 +1819,10 @@ vfs_syncwait(struct proc *p, int verbose) * With soft updates, some buffers that are * written will be remarked as dirty until other * buffers are written. + * + * XXX here be dragons. this should really go away + * but should be carefully made to go away on it's + * own with testing.. XXX */ if (bp->b_flags & B_DELWRI) { s = splbio(); @@ -2249,18 +2253,14 @@ vfs_buf_print(void *b, int full, bp->b_proc, bp->b_error, bp->b_flags, B_BITS); (*pr)(" bufsize 0x%lx bcount 0x%lx resid 0x%lx\n" - " data %p saveaddr %p dep %p iodone %p\n", + " data %p saveaddr %p iodone %p\n", bp->b_bufsize, bp->b_bcount, (long)bp->b_resid, bp->b_data, bp->b_saveaddr, - LIST_FIRST(&bp->b_dep), bp->b_iodone); + bp->b_iodone); (*pr)(" dirty {off 0x%x end 0x%x} valid {off 0x%x end 0x%x}\n", bp->b_dirtyoff, bp->b_dirtyend, bp->b_validoff, bp->b_validend); -#ifdef FFS_SOFTUPDATES - if (full) - softdep_print(bp, full, pr); -#endif } const char *vtypes[] = { VTYPE_NAMES }; diff --git a/sys/kern/vfs_sync.c b/sys/kern/vfs_sync.c index 326fe9e9f..8108e6d5a 100644 --- a/sys/kern/vfs_sync.c +++ b/sys/kern/vfs_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_sync.c,v 1.69 2023/05/25 07:45:33 claudio Exp $ */ +/* $OpenBSD: vfs_sync.c,v 1.70 2024/02/03 18:51:58 beck Exp $ */ /* * Portions of this code are: @@ -50,10 +50,6 @@ #include #include -#ifdef FFS_SOFTUPDATES -int softdep_process_worklist(struct mount *); -#endif - /* * The workitem queue. */ @@ -62,9 +58,6 @@ int softdep_process_worklist(struct mount *); int syncer_maxdelay = SYNCER_MAXDELAY; /* maximum delay time */ int syncdelay = SYNCER_DEFAULT; /* time to delay syncing vnodes */ -int rushjob = 0; /* number of slots to run ASAP */ -int stat_rush_requests = 0; /* number of rush requests */ - int syncer_delayno = 0; long syncer_mask; LIST_HEAD(synclist, vnode); @@ -198,28 +191,6 @@ syncer_thread(void *arg) splx(s); -#ifdef FFS_SOFTUPDATES - /* - * Do soft update processing. - */ - softdep_process_worklist(NULL); -#endif - - /* - * The variable rushjob allows the kernel to speed up the - * processing of the filesystem syncer process. A rushjob - * value of N tells the filesystem syncer to process the next - * N seconds worth of work on its queue ASAP. Currently rushjob - * is used by the soft update code to speed up the filesystem - * syncer process when the incore state is getting so far - * ahead of the disk that the kernel memory pool is being - * threatened with exhaustion. - */ - if (rushjob > 0) { - rushjob -= 1; - continue; - } - /* * If it has taken us less than a second to process the * current work, then wait. Otherwise start right over @@ -236,24 +207,6 @@ syncer_thread(void *arg) } } -/* - * Request the syncer daemon to speed up its work. - * We never push it to speed up more than half of its - * normal turn time, otherwise it could take over the cpu. - */ -int -speedup_syncer(void) -{ - if (syncerproc) - wakeup_one(&syncer_chan); - if (rushjob < syncdelay / 2) { - rushjob += 1; - stat_rush_requests += 1; - return 1; - } - return 0; -} - /* Routine to create and manage a filesystem syncer vnode. */ int sync_fsync(void *); int sync_inactive(void *); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 43462b149..6eb0796ce 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_syscalls.c,v 1.362 2023/07/05 15:13:28 beck Exp $ */ +/* $OpenBSD: vfs_syscalls.c,v 1.363 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ /* @@ -2894,10 +2894,6 @@ sys_fsync(struct proc *p, void *v, register_t *retval) vp = fp->f_data; vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, p); -#ifdef FFS_SOFTUPDATES - if (error == 0 && vp->v_mount && (vp->v_mount->mnt_flag & MNT_SOFTDEP)) - error = softdep_fsync(vp); -#endif VOP_UNLOCK(vp); FRELE(fp, p); diff --git a/sys/miscfs/fifofs/fifo_vnops.c b/sys/miscfs/fifofs/fifo_vnops.c index 985b0e4ca..545837282 100644 --- a/sys/miscfs/fifofs/fifo_vnops.c +++ b/sys/miscfs/fifofs/fifo_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fifo_vnops.c,v 1.102 2023/03/08 04:43:08 guenther Exp $ */ +/* $OpenBSD: fifo_vnops.c,v 1.103 2024/02/03 22:50:09 mvs Exp $ */ /* $NetBSD: fifo_vnops.c,v 1.18 1996/03/16 23:52:42 christos Exp $ */ /* @@ -105,16 +105,18 @@ int filt_fiforead(struct knote *kn, long hint); void filt_fifowdetach(struct knote *kn); int filt_fifowrite(struct knote *kn, long hint); int filt_fifoexcept(struct knote *kn, long hint); -int filt_fifomodify(struct kevent *kev, struct knote *kn); -int filt_fifoprocess(struct knote *kn, struct kevent *kev); +int filt_fiformodify(struct kevent *kev, struct knote *kn); +int filt_fiforprocess(struct knote *kn, struct kevent *kev); +int filt_fifowmodify(struct kevent *kev, struct knote *kn); +int filt_fifowprocess(struct knote *kn, struct kevent *kev); const struct filterops fiforead_filtops = { .f_flags = FILTEROP_ISFD | FILTEROP_MPSAFE, .f_attach = NULL, .f_detach = filt_fifordetach, .f_event = filt_fiforead, - .f_modify = filt_fifomodify, - .f_process = filt_fifoprocess, + .f_modify = filt_fiformodify, + .f_process = filt_fiforprocess, }; const struct filterops fifowrite_filtops = { @@ -122,8 +124,8 @@ const struct filterops fifowrite_filtops = { .f_attach = NULL, .f_detach = filt_fifowdetach, .f_event = filt_fifowrite, - .f_modify = filt_fifomodify, - .f_process = filt_fifoprocess, + .f_modify = filt_fifowmodify, + .f_process = filt_fifowprocess, }; const struct filterops fifoexcept_filtops = { @@ -131,8 +133,8 @@ const struct filterops fifoexcept_filtops = { .f_attach = NULL, .f_detach = filt_fifordetach, .f_event = filt_fifoexcept, - .f_modify = filt_fifomodify, - .f_process = filt_fifoprocess, + .f_modify = filt_fiformodify, + .f_process = filt_fiforprocess, }; /* @@ -517,6 +519,7 @@ filt_fiforead(struct knote *kn, long hint) int rv; soassertlocked(so); + MUTEX_ASSERT_LOCKED(&so->so_rcv.sb_mtx); kn->kn_data = so->so_rcv.sb_cc; if (so->so_rcv.sb_state & SS_CANTRCVMORE) { @@ -551,6 +554,7 @@ filt_fifowrite(struct knote *kn, long hint) int rv; soassertlocked(so); + MUTEX_ASSERT_LOCKED(&so->so_snd.sb_mtx); kn->kn_data = sbspace(so, &so->so_snd); if (so->so_snd.sb_state & SS_CANTSENDMORE) { @@ -571,6 +575,7 @@ filt_fifoexcept(struct knote *kn, long hint) int rv = 0; soassertlocked(so); + MUTEX_ASSERT_LOCKED(&so->so_rcv.sb_mtx); if (kn->kn_flags & __EV_POLL) { if (so->so_state & SS_ISDISCONNECTED) { @@ -585,26 +590,60 @@ filt_fifoexcept(struct knote *kn, long hint) } int -filt_fifomodify(struct kevent *kev, struct knote *kn) +filt_fiformodify(struct kevent *kev, struct knote *kn) { struct socket *so = kn->kn_hook; int rv; solock(so); + mtx_enter(&so->so_rcv.sb_mtx); rv = knote_modify(kev, kn); + mtx_leave(&so->so_rcv.sb_mtx); sounlock(so); return (rv); } int -filt_fifoprocess(struct knote *kn, struct kevent *kev) +filt_fiforprocess(struct knote *kn, struct kevent *kev) { struct socket *so = kn->kn_hook; int rv; solock(so); + mtx_enter(&so->so_rcv.sb_mtx); rv = knote_process(kn, kev); + mtx_leave(&so->so_rcv.sb_mtx); + sounlock(so); + + return (rv); +} + +int +filt_fifowmodify(struct kevent *kev, struct knote *kn) +{ + struct socket *so = kn->kn_hook; + int rv; + + solock(so); + mtx_enter(&so->so_snd.sb_mtx); + rv = knote_modify(kev, kn); + mtx_leave(&so->so_snd.sb_mtx); + sounlock(so); + + return (rv); +} + +int +filt_fifowprocess(struct knote *kn, struct kevent *kev) +{ + struct socket *so = kn->kn_hook; + int rv; + + solock(so); + mtx_enter(&so->so_snd.sb_mtx); + rv = knote_process(kn, kev); + mtx_leave(&so->so_snd.sb_mtx); sounlock(so); return (rv); diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index c3388702b..f8f6cd61e 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.92 2023/09/16 09:33:27 mpi Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.93 2024/02/03 22:50:09 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -67,6 +67,7 @@ const struct pr_usrreqs divert_usrreqs = { .pru_detach = divert_detach, .pru_lock = divert_lock, .pru_unlock = divert_unlock, + .pru_locked = divert_locked, .pru_bind = divert_bind, .pru_shutdown = divert_shutdown, .pru_send = divert_send, @@ -313,6 +314,14 @@ divert_unlock(struct socket *so) mtx_leave(&inp->inp_mtx); } +int +divert_locked(struct socket *so) +{ + struct inpcb *inp = sotoinpcb(so); + + return mtx_owned(&inp->inp_mtx); +} + int divert_bind(struct socket *so, struct mbuf *addr, struct proc *p) { diff --git a/sys/netinet/ip_divert.h b/sys/netinet/ip_divert.h index 141886415..2c09d5175 100644 --- a/sys/netinet/ip_divert.h +++ b/sys/netinet/ip_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.h,v 1.24 2022/10/17 14:49:02 mvs Exp $ */ +/* $OpenBSD: ip_divert.h,v 1.25 2024/02/03 22:50:09 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -74,6 +74,7 @@ int divert_attach(struct socket *, int, int); int divert_detach(struct socket *); void divert_lock(struct socket *); void divert_unlock(struct socket *); +int divert_locked(struct socket *); int divert_bind(struct socket *, struct mbuf *, struct proc *); int divert_shutdown(struct socket *); int divert_send(struct socket *, struct mbuf *, struct mbuf *, diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 789796633..663671d1a 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.110 2023/11/26 22:08:10 bluhm Exp $ */ +/* $OpenBSD: ip_var.h,v 1.111 2024/02/03 22:50:09 mvs Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -260,6 +260,7 @@ int rip_attach(struct socket *, int, int); int rip_detach(struct socket *); void rip_lock(struct socket *); void rip_unlock(struct socket *); +int rip_locked(struct socket *); int rip_bind(struct socket *, struct mbuf *, struct proc *); int rip_connect(struct socket *, struct mbuf *); int rip_disconnect(struct socket *); diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 5ba59f461..1c8cb5480 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.154 2024/01/21 01:17:20 bluhm Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.155 2024/02/03 22:50:09 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -108,6 +108,7 @@ const struct pr_usrreqs rip_usrreqs = { .pru_detach = rip_detach, .pru_lock = rip_lock, .pru_unlock = rip_unlock, + .pru_locked = rip_locked, .pru_bind = rip_bind, .pru_connect = rip_connect, .pru_disconnect = rip_disconnect, @@ -524,6 +525,14 @@ rip_unlock(struct socket *so) mtx_leave(&inp->inp_mtx); } +int +rip_locked(struct socket *so) +{ + struct inpcb *inp = sotoinpcb(so); + + return mtx_owned(&inp->inp_mtx); +} + int rip_bind(struct socket *so, struct mbuf *nam, struct proc *p) { diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 6a58bb916..18b0ae983 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.316 2024/01/28 20:34:25 bluhm Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.317 2024/02/03 22:50:09 mvs Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -127,6 +127,7 @@ const struct pr_usrreqs udp_usrreqs = { .pru_detach = udp_detach, .pru_lock = udp_lock, .pru_unlock = udp_unlock, + .pru_locked = udp_locked, .pru_bind = udp_bind, .pru_connect = udp_connect, .pru_disconnect = udp_disconnect, @@ -143,6 +144,7 @@ const struct pr_usrreqs udp6_usrreqs = { .pru_detach = udp_detach, .pru_lock = udp_lock, .pru_unlock = udp_unlock, + .pru_locked = udp_locked, .pru_bind = udp_bind, .pru_connect = udp_connect, .pru_disconnect = udp_disconnect, @@ -1156,6 +1158,14 @@ udp_unlock(struct socket *so) mtx_leave(&inp->inp_mtx); } +int +udp_locked(struct socket *so) +{ + struct inpcb *inp = sotoinpcb(so); + + return mtx_owned(&inp->inp_mtx); +} + int udp_bind(struct socket *so, struct mbuf *addr, struct proc *p) { diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 80df3318f..5731cf4ef 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_var.h,v 1.50 2024/01/10 16:44:30 bluhm Exp $ */ +/* $OpenBSD: udp_var.h,v 1.51 2024/02/03 22:50:09 mvs Exp $ */ /* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */ /* @@ -147,6 +147,7 @@ int udp_attach(struct socket *, int, int); int udp_detach(struct socket *); void udp_lock(struct socket *); void udp_unlock(struct socket *); +int udp_locked(struct socket *); int udp_bind(struct socket *, struct mbuf *, struct proc *); int udp_connect(struct socket *, struct mbuf *); int udp_disconnect(struct socket *); diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 896441742..551df0e50 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.91 2024/01/01 18:52:09 bluhm Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.92 2024/02/03 22:50:09 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -69,6 +69,7 @@ const struct pr_usrreqs divert6_usrreqs = { .pru_detach = divert_detach, .pru_lock = divert_lock, .pru_unlock = divert_unlock, + .pru_locked = divert_locked, .pru_bind = divert_bind, .pru_shutdown = divert_shutdown, .pru_send = divert6_send, diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 5b02315f9..759a677b3 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_mroute.c,v 1.138 2023/12/06 09:27:17 bluhm Exp $ */ +/* $OpenBSD: ip6_mroute.c,v 1.139 2024/02/03 22:50:09 mvs Exp $ */ /* $NetBSD: ip6_mroute.c,v 1.59 2003/12/10 09:28:38 itojun Exp $ */ /* $KAME: ip6_mroute.c,v 1.45 2001/03/25 08:38:51 itojun Exp $ */ @@ -861,12 +861,12 @@ socket6_send(struct socket *so, struct mbuf *mm, struct sockaddr_in6 *src) mtx_enter(&inp->inp_mtx); ret = sbappendaddr(so, &so->so_rcv, sin6tosa(src), mm, NULL); + if (ret != 0) + sorwakeup(so); mtx_leave(&inp->inp_mtx); - if (ret != 0) { - sorwakeup(so); + if (ret != 0) return 0; - } } m_freem(mm); return -1; diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index ebfde7344..887bd95fe 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_var.h,v 1.109 2023/12/03 20:36:24 bluhm Exp $ */ +/* $OpenBSD: ip6_var.h,v 1.110 2024/02/03 22:50:09 mvs Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -353,6 +353,7 @@ int rip6_attach(struct socket *, int, int); int rip6_detach(struct socket *); void rip6_lock(struct socket *); void rip6_unlock(struct socket *); +int rip6_locked(struct socket *); int rip6_bind(struct socket *, struct mbuf *, struct proc *); int rip6_connect(struct socket *, struct mbuf *); int rip6_disconnect(struct socket *); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 1b784248f..4ae5ff2ba 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.179 2024/01/21 01:17:20 bluhm Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.180 2024/02/03 22:50:09 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -110,6 +110,7 @@ const struct pr_usrreqs rip6_usrreqs = { .pru_detach = rip6_detach, .pru_lock = rip6_lock, .pru_unlock = rip6_unlock, + .pru_locked = rip6_locked, .pru_bind = rip6_bind, .pru_connect = rip6_connect, .pru_disconnect = rip6_disconnect, @@ -653,6 +654,14 @@ rip6_unlock(struct socket *so) mtx_leave(&inp->inp_mtx); } +int +rip6_locked(struct socket *so) +{ + struct inpcb *inp = sotoinpcb(so); + + return mtx_owned(&inp->inp_mtx); +} + int rip6_bind(struct socket *so, struct mbuf *nam, struct proc *p) { diff --git a/sys/sys/buf.h b/sys/sys/buf.h index b8d887ad1..d12337738 100644 --- a/sys/sys/buf.h +++ b/sys/sys/buf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.h,v 1.113 2022/09/01 05:24:51 jsg Exp $ */ +/* $OpenBSD: buf.h,v 1.114 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: buf.h,v 1.25 1997/04/09 21:12:17 mycroft Exp $ */ /* @@ -51,12 +51,6 @@ struct vnode; LIST_HEAD(bufhead, buf); -/* - * To avoid including - */ - -LIST_HEAD(workhead, worklist); - /* * Buffer queues */ @@ -122,20 +116,6 @@ union bufq_data { struct bufq_nscan bufq_data_nscan; }; -/* - * These are currently used only by the soft dependency code, hence - * are stored once in a global variable. If other subsystems wanted - * to use these hooks, a pointer to a set of bio_ops could be added - * to each buffer. - */ -extern struct bio_ops { - void (*io_start)(struct buf *); - void (*io_complete)(struct buf *); - void (*io_deallocate)(struct buf *); - void (*io_movedeps)(struct buf *, struct buf *); - int (*io_countdeps)(struct buf *, int, int); -} bioops; - /* The buffer header describes an I/O operation in the kernel. */ struct buf { RBT_ENTRY(buf) b_rbbufs; /* vnode "hash" tree */ @@ -172,7 +152,6 @@ struct buf { int b_dirtyend; /* Offset of end of dirty region. */ int b_validoff; /* Offset in buffer of valid region. */ int b_validend; /* Offset of end of valid region. */ - struct workhead b_dep; /* List of filesystem dependencies. */ }; TAILQ_HEAD(bufqueue, buf); @@ -324,43 +303,6 @@ void buf_daemon(void *); void buf_replacevnode(struct buf *, struct vnode *); int bread_cluster(struct vnode *, daddr_t, int, struct buf **); -static __inline void -buf_start(struct buf *bp) -{ - if (bioops.io_start) - (*bioops.io_start)(bp); -} - -static __inline void -buf_complete(struct buf *bp) -{ - if (bioops.io_complete) - (*bioops.io_complete)(bp); -} - -static __inline void -buf_deallocate(struct buf *bp) -{ - if (bioops.io_deallocate) - (*bioops.io_deallocate)(bp); -} - -static __inline void -buf_movedeps(struct buf *bp, struct buf *bp2) -{ - if (bioops.io_movedeps) - (*bioops.io_movedeps)(bp, bp2); -} - -static __inline int -buf_countdeps(struct buf *bp, int i, int islocked) -{ - if (bioops.io_countdeps) - return ((*bioops.io_countdeps)(bp, i, islocked)); - else - return (0); -} - __END_DECLS #endif /* _KERNEL */ #endif /* !_SYS_BUF_H_ */ diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 3fc2ac05a..5a446c640 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mount.h,v 1.150 2023/07/05 15:13:28 beck Exp $ */ +/* $OpenBSD: mount.h,v 1.151 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: mount.h,v 1.48 1996/02/18 11:55:47 fvdl Exp $ */ /* @@ -610,7 +610,6 @@ int vfs_export(struct mount *, struct netexport *, struct export_args *); struct netcred *vfs_export_lookup(struct mount *, struct netexport *, struct mbuf *); int vfs_allocate_syncvnode(struct mount *); -int speedup_syncer(void); int vfs_syncwait(struct proc *, int); /* sync and wait for complete */ void vfs_shutdown(struct proc *); /* unmount and sync file systems */ diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h index 8bb039aeb..a90714c82 100644 --- a/sys/sys/mutex.h +++ b/sys/sys/mutex.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.h,v 1.19 2023/12/01 14:37:22 bluhm Exp $ */ +/* $OpenBSD: mutex.h,v 1.20 2024/02/03 22:50:09 mvs Exp $ */ /* * Copyright (c) 2004 Artur Grabowski @@ -127,6 +127,9 @@ void mtx_leave(struct mutex *); #define mtx_init(m, ipl) mtx_init_flags(m, ipl, NULL, 0) +#define mtx_owned(mtx) \ + (((mtx)->mtx_owner == curcpu()) || panicstr || db_active) + #ifdef WITNESS void _mtx_init_flags(struct mutex *, int, const char *, int, diff --git a/sys/sys/proc.h b/sys/sys/proc.h index e85d965dd..4a65bf379 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.355 2024/01/19 01:43:27 bluhm Exp $ */ +/* $OpenBSD: proc.h,v 1.356 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -436,7 +436,6 @@ struct proc { #define P_CONTINUED 0x00800000 /* Proc has continued from a stopped state. */ #define P_THREAD 0x04000000 /* Only a thread, not a real process */ #define P_SUSPSIG 0x08000000 /* Stopped from signal. */ -#define P_SOFTDEP 0x10000000 /* Stuck processing softdep worklist */ #define P_CPUPEG 0x40000000 /* Do not move to another cpu. */ #define P_BITS \ diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 786930624..582f5ad7e 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.64 2024/01/11 14:15:12 bluhm Exp $ */ +/* $OpenBSD: protosw.h,v 1.65 2024/02/03 22:50:09 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -69,6 +69,7 @@ struct pr_usrreqs { int (*pru_detach)(struct socket *); void (*pru_lock)(struct socket *); void (*pru_unlock)(struct socket *); + int (*pru_locked)(struct socket *so); int (*pru_bind)(struct socket *, struct mbuf *, struct proc *); int (*pru_listen)(struct socket *); int (*pru_connect)(struct socket *, struct mbuf *); @@ -296,6 +297,14 @@ pru_unlock(struct socket *so) (*so->so_proto->pr_usrreqs->pru_unlock)(so); } +static inline int +pru_locked(struct socket *so) +{ + if (so->so_proto->pr_usrreqs->pru_locked) + return (*so->so_proto->pr_usrreqs->pru_locked)(so); + return (0); +} + static inline int pru_bind(struct socket *so, struct mbuf *nam, struct proc *p) { diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 41403c00d..f57773e63 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socketvar.h,v 1.121 2024/01/11 14:15:12 bluhm Exp $ */ +/* $OpenBSD: socketvar.h,v 1.122 2024/02/03 22:50:09 mvs Exp $ */ /* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */ /*- @@ -40,6 +40,7 @@ #include /* for struct sigio_ref */ #include #include +#include #include #include @@ -105,6 +106,7 @@ struct socket { * Variables for socket buffering. */ struct sockbuf { + struct mutex sb_mtx; /* The following fields are all zeroed on flush. */ #define sb_startzero sb_cc u_long sb_cc; /* actual chars in buffer */ @@ -174,6 +176,7 @@ struct socket { #include void soassertlocked(struct socket *); +void soassertlocked_readonly(struct socket *); static inline void soref(struct socket *so) @@ -200,9 +203,16 @@ sorele(struct socket *so) static inline int sb_notify(struct socket *so, struct sockbuf *sb) { + int rv; + soassertlocked(so); - return ((sb->sb_flags & (SB_WAIT|SB_ASYNC|SB_SPLICE)) != 0 || + + mtx_enter(&sb->sb_mtx); + rv = ((sb->sb_flags & (SB_WAIT|SB_ASYNC|SB_SPLICE)) != 0 || !klist_empty(&sb->sb_klist)); + mtx_leave(&sb->sb_mtx); + + return rv; } /* @@ -211,10 +221,12 @@ sb_notify(struct socket *so, struct sockbuf *sb) * still be negative (cc > hiwat or mbcnt > mbmax). Should detect * overflow and return 0. */ + static inline long sbspace(struct socket *so, struct sockbuf *sb) { - soassertlocked(so); + soassertlocked_readonly(so); + return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt); } @@ -230,7 +242,7 @@ sbspace(struct socket *so, struct sockbuf *sb) static inline int soreadable(struct socket *so) { - soassertlocked(so); + soassertlocked_readonly(so); if (isspliced(so)) return 0; return (so->so_rcv.sb_state & SS_CANTRCVMORE) || so->so_qlen || @@ -241,7 +253,7 @@ soreadable(struct socket *so) static inline int sowriteable(struct socket *so) { - soassertlocked(so); + soassertlocked_readonly(so); return ((sbspace(so, &so->so_snd) >= so->so_snd.sb_lowat && ((so->so_state & SS_ISCONNECTED) || (so->so_proto->pr_flags & PR_CONNREQUIRED)==0)) || diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 994ceb623..23eebf371 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vnode.h,v 1.169 2023/09/08 20:00:28 mvs Exp $ */ +/* $OpenBSD: vnode.h,v 1.170 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: vnode.h,v 1.38 1996/02/29 20:59:05 cgd Exp $ */ /* @@ -643,7 +643,6 @@ void vn_syncer_add_to_worklist(struct vnode *, int); /* misc */ int vn_isdisk(struct vnode *, int *); -int softdep_fsync(struct vnode *); int getvnode(struct proc *, int, struct file **); /* uvm */ diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index f25e235bd..14822193a 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_alloc.c,v 1.114 2021/03/11 13:31:35 jsg Exp $ */ +/* $OpenBSD: ffs_alloc.c,v 1.115 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: ffs_alloc.c,v 1.11 1996/05/11 18:27:09 mycroft Exp $ */ /* @@ -291,8 +291,7 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t bpref, int osize, goto nospace; (void) uvm_vnp_uncache(ITOV(ip)); - if (!DOINGSOFTDEP(ITOV(ip))) - ffs_blkfree(ip, bprev, (long)osize); + ffs_blkfree(ip, bprev, (long)osize); if (nsize < request) ffs_blkfree(ip, bno + numfrags(fs, nsize), (long)(request - nsize)); @@ -921,8 +920,6 @@ ffs_fragextend(struct inode *ip, u_int cg, daddr_t bprev, int osize, int nsize) fs->fs_cs(fs, cg).cs_nffree--; } fs->fs_fmod = 1; - if (DOINGSOFTDEP(ITOV(ip))) - softdep_setup_blkmapdep(bp, fs, bprev); bdwrite(bp); return (bprev); @@ -1015,8 +1012,6 @@ ffs_alloccg(struct inode *ip, u_int cg, daddr_t bpref, int size) cgp->cg_frsum[allocsiz - frags]++; blkno = cgbase(fs, cg) + bno; - if (DOINGSOFTDEP(ITOV(ip))) - softdep_setup_blkmapdep(bp, fs, blkno); bdwrite(bp); return (blkno); } @@ -1082,9 +1077,6 @@ gotit: fs->fs_fmod = 1; blkno = cgbase(fs, cgp->cg_cgx) + bno; - if (DOINGSOFTDEP(ITOV(ip))) - softdep_setup_blkmapdep(bp, fs, blkno); - return (blkno); } @@ -1220,9 +1212,6 @@ gotit: } #endif /* FFS2 */ - if (DOINGSOFTDEP(ITOV(ip))) - softdep_setup_inomapdep(bp, ip, cg * fs->fs_ipg + ipref); - setbit(cg_inosused(cgp), ipref); /* Update the counters we keep on free inodes */ @@ -1363,13 +1352,6 @@ ffs_blkfree(struct inode *ip, daddr_t bno, long size) int ffs_inode_free(struct inode *pip, ufsino_t ino, mode_t mode) { - struct vnode *pvp = ITOV(pip); - - if (DOINGSOFTDEP(pvp)) { - softdep_freefile(pvp, ino, mode); - return (0); - } - return (ffs_freefile(pip, ino, mode)); } diff --git a/sys/ufs/ffs/ffs_balloc.c b/sys/ufs/ffs/ffs_balloc.c index 823342a65..50918cff5 100644 --- a/sys/ufs/ffs/ffs_balloc.c +++ b/sys/ufs/ffs/ffs_balloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_balloc.c,v 1.45 2019/07/19 00:24:31 cheloha Exp $ */ +/* $OpenBSD: ffs_balloc.c,v 1.46 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: ffs_balloc.c,v 1.3 1996/02/09 22:22:21 christos Exp $ */ /* @@ -107,10 +107,6 @@ ffs1_balloc(struct inode *ip, off_t startoffset, int size, struct ucred *cred, osize, (int)fs->fs_bsize, cred, bpp, &newb); if (error) return (error); - if (DOINGSOFTDEP(vp)) - softdep_setup_allocdirect(ip, nb, newb, - ip->i_ffs1_db[nb], fs->fs_bsize, osize, - bpp ? *bpp : NULL); ip->i_ffs1_size = lblktosize(fs, nb + 1); uvm_vnp_setsize(vp, ip->i_ffs1_size); @@ -179,10 +175,6 @@ ffs1_balloc(struct inode *ip, off_t startoffset, int size, struct ucred *cred, osize, nsize, cred, bpp, &newb); if (error) return (error); - if (DOINGSOFTDEP(vp)) - softdep_setup_allocdirect(ip, lbn, - newb, nb, nsize, osize, - bpp ? *bpp : NULL); } } else { /* @@ -207,9 +199,6 @@ ffs1_balloc(struct inode *ip, off_t startoffset, int size, struct ucred *cred, if (flags & B_CLRBUF) clrbuf(*bpp); } - if (DOINGSOFTDEP(vp)) - softdep_setup_allocdirect(ip, lbn, newb, 0, - nsize, 0, bpp ? *bpp : NULL); } ip->i_ffs1_db[lbn] = newb; ip->i_flag |= IN_CHANGE | IN_UPDATE; @@ -247,18 +236,12 @@ ffs1_balloc(struct inode *ip, off_t startoffset, int size, struct ucred *cred, bp->b_blkno = fsbtodb(fs, nb); clrbuf(bp); - if (DOINGSOFTDEP(vp)) { - softdep_setup_allocdirect(ip, NDADDR + indirs[0].in_off, - newb, 0, fs->fs_bsize, 0, bp); - bdwrite(bp); - } else { - /* - * Write synchronously so that indirect blocks - * never point at garbage. - */ - if ((error = bwrite(bp)) != 0) - goto fail; - } + /* + * Write synchronously so that indirect blocks + * never point at garbage. + */ + if ((error = bwrite(bp)) != 0) + goto fail; allocib = &ip->i_ffs1_ib[indirs[0].in_off]; *allocib = nb; ip->i_flag |= IN_CHANGE | IN_UPDATE; @@ -296,19 +279,13 @@ ffs1_balloc(struct inode *ip, off_t startoffset, int size, struct ucred *cred, nbp->b_blkno = fsbtodb(fs, nb); clrbuf(nbp); - if (DOINGSOFTDEP(vp)) { - softdep_setup_allocindir_meta(nbp, ip, bp, - indirs[i - 1].in_off, nb); - bdwrite(nbp); - } else { - /* - * Write synchronously so that indirect blocks - * never point at garbage. - */ - if ((error = bwrite(nbp)) != 0) { - brelse(bp); - goto fail; - } + /* + * Write synchronously so that indirect blocks + * never point at garbage. + */ + if ((error = bwrite(nbp)) != 0) { + brelse(bp); + goto fail; } bap[indirs[i - 1].in_off] = nb; if (allocib == NULL && unwindidx < 0) @@ -343,9 +320,6 @@ ffs1_balloc(struct inode *ip, off_t startoffset, int size, struct ucred *cred, clrbuf(nbp); *bpp = nbp; } - if (DOINGSOFTDEP(vp)) - softdep_setup_allocindir_page(ip, lbn, bp, - indirs[i].in_off, nb, 0, bpp ? *bpp : NULL); bap[indirs[i].in_off] = nb; /* * If required, write synchronously, otherwise use @@ -473,11 +447,6 @@ ffs2_balloc(struct inode *ip, off_t off, int size, struct ucred *cred, if (error) return (error); - if (DOINGSOFTDEP(vp)) - softdep_setup_allocdirect(ip, nb, newb, - ip->i_ffs2_db[nb], fs->fs_bsize, osize, - bpp ? *bpp : NULL); - ip->i_ffs2_size = lblktosize(fs, nb + 1); uvm_vnp_setsize(vp, ip->i_ffs2_size); ip->i_ffs2_db[nb] = newb; @@ -550,11 +519,6 @@ ffs2_balloc(struct inode *ip, off_t off, int size, struct ucred *cred, bpp, &newb); if (error) return (error); - - if (DOINGSOFTDEP(vp)) - softdep_setup_allocdirect(ip, lbn, - newb, nb, nsize, osize, - bpp ? *bpp : NULL); } } else { /* @@ -580,10 +544,6 @@ ffs2_balloc(struct inode *ip, off_t off, int size, struct ucred *cred, clrbuf(bp); *bpp = bp; } - - if (DOINGSOFTDEP(vp)) - softdep_setup_allocdirect(ip, lbn, newb, 0, - nsize, 0, bpp ? *bpp : NULL); } ip->i_ffs2_db[lbn] = newb; @@ -626,19 +586,13 @@ ffs2_balloc(struct inode *ip, off_t off, int size, struct ucred *cred, bp->b_blkno = fsbtodb(fs, nb); clrbuf(bp); - if (DOINGSOFTDEP(vp)) { - softdep_setup_allocdirect(ip, NDADDR + indirs[0].in_off, - newb, 0, fs->fs_bsize, 0, bp); - bdwrite(bp); - } else { - /* - * Write synchronously so that indirect blocks never - * point at garbage. - */ - error = bwrite(bp); - if (error) - goto fail; - } + /* + * Write synchronously so that indirect blocks never + * point at garbage. + */ + error = bwrite(bp); + if (error) + goto fail; unwindidx = 0; allocib = &ip->i_ffs2_ib[indirs[0].in_off]; @@ -685,20 +639,14 @@ ffs2_balloc(struct inode *ip, off_t off, int size, struct ucred *cred, nbp->b_blkno = fsbtodb(fs, nb); clrbuf(nbp); - if (DOINGSOFTDEP(vp)) { - softdep_setup_allocindir_meta(nbp, ip, bp, - indirs[i - 1].in_off, nb); - bdwrite(nbp); - } else { - /* - * Write synchronously so that indirect blocks never - * point at garbage. - */ - error = bwrite(nbp); - if (error) { - brelse(bp); - goto fail; - } + /* + * Write synchronously so that indirect blocks never + * point at garbage. + */ + error = bwrite(nbp); + if (error) { + brelse(bp); + goto fail; } if (unwindidx < 0) @@ -740,10 +688,6 @@ ffs2_balloc(struct inode *ip, off_t off, int size, struct ucred *cred, *bpp = nbp; } - if (DOINGSOFTDEP(vp)) - softdep_setup_allocindir_page(ip, lbn, bp, - indirs[num].in_off, nb, 0, bpp ? *bpp : NULL); - bap[indirs[num].in_off] = nb; if (allocib == NULL && unwindidx < 0) @@ -830,11 +774,6 @@ fail: } } - if (DOINGSOFTDEP(vp) && unwindidx == 0) { - ip->i_flag |= IN_CHANGE | IN_UPDATE; - ffs_update(ip, 1); - } - /* * Now that any dependencies that we created have been * resolved, we can undo the partial allocation. @@ -842,8 +781,6 @@ fail: if (unwindidx == 0) { *allocib = 0; ip->i_flag |= IN_CHANGE | IN_UPDATE; - if (DOINGSOFTDEP(vp)) - ffs_update(ip, 1); } else { r = bread(vp, indirs[unwindidx].in_lbn, (int)fs->fs_bsize, &bp); diff --git a/sys/ufs/ffs/ffs_extern.h b/sys/ufs/ffs/ffs_extern.h index 921f905c1..5e365ba03 100644 --- a/sys/ufs/ffs/ffs_extern.h +++ b/sys/ufs/ffs/ffs_extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_extern.h,v 1.45 2020/01/20 23:21:56 claudio Exp $ */ +/* $OpenBSD: ffs_extern.h,v 1.46 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: ffs_extern.h,v 1.4 1996/02/09 22:22:22 christos Exp $ */ /* @@ -36,7 +36,6 @@ #define FFS_CLUSTERWRITE 2 /* cluster writing enabled */ #define FFS_REALLOCBLKS 3 /* block reallocation enabled */ #define FFS_ASYNCFREE 4 /* asynchronous block freeing enabled */ -#define FFS_MAX_SOFTDEPS 5 /* maximum structs before slowdown */ #define FFS_SD_TICKDELAY 6 /* ticks to pause during slowdown */ #define FFS_SD_WORKLIST_PUSH 7 /* # of worklist cleanups */ #define FFS_SD_BLK_LIMIT_PUSH 8 /* # of times block limit neared */ @@ -59,7 +58,6 @@ { 0, 0 }, \ { 0, 0 }, \ { 0, 0 }, \ - { "max_softdeps", CTLTYPE_INT }, \ { "sd_tickdelay", CTLTYPE_INT }, \ { "sd_worklist_push", CTLTYPE_INT }, \ { "sd_blk_limit_push", CTLTYPE_INT }, \ @@ -167,28 +165,6 @@ int ffsfifo_reclaim(void *); struct vop_vfree_args; struct vop_fsync_args; -void softdep_initialize(void); -int softdep_process_worklist(struct mount *); -int softdep_mount(struct vnode *, struct mount *, struct fs *, - struct ucred *); -int softdep_flushworklist(struct mount *, int *, struct proc *); -int softdep_flushfiles(struct mount *, int, struct proc *); -void softdep_update_inodeblock(struct inode *, struct buf *, int); -void softdep_load_inodeblock(struct inode *); -void softdep_freefile(struct vnode *, ufsino_t, mode_t); -void softdep_setup_freeblocks(struct inode *, off_t); -void softdep_setup_inomapdep(struct buf *, struct inode *, ufsino_t); -void softdep_setup_blkmapdep(struct buf *, struct fs *, daddr_t); -void softdep_setup_allocdirect(struct inode *, daddr_t, daddr_t, - daddr_t, long, long, struct buf *); -void softdep_setup_allocindir_meta(struct buf *, struct inode *, - struct buf *, int, daddr_t); -void softdep_setup_allocindir_page(struct inode *, daddr_t, - struct buf *, int, daddr_t, daddr_t, struct buf *); -void softdep_fsync_mountdev(struct vnode *, int); -int softdep_sync_metadata(struct vop_fsync_args *); -int softdep_fsync(struct vnode *); - extern struct pool ffs_ino_pool; /* memory pool for inodes */ extern struct pool ffs_dinode1_pool; /* memory pool for UFS1 dinodes */ #ifdef FFS2 diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c index d95983cf5..78f82cdb2 100644 --- a/sys/ufs/ffs/ffs_inode.c +++ b/sys/ufs/ffs/ffs_inode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_inode.c,v 1.82 2024/01/09 03:15:59 guenther Exp $ */ +/* $OpenBSD: ffs_inode.c,v 1.83 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: ffs_inode.c,v 1.10 1996/05/11 18:27:19 mycroft Exp $ */ /* @@ -95,9 +95,7 @@ ffs_update(struct inode *ip, int waitfor) return (error); } - if (DOINGSOFTDEP(vp)) - softdep_update_inodeblock(ip, bp, waitfor); - else if (ip->i_effnlink != DIP(ip, nlink)) + if (ip->i_effnlink != DIP(ip, nlink)) panic("ffs_update: bad link cnt"); #ifdef FFS2 @@ -174,30 +172,6 @@ ffs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) oip->i_ci.ci_lasta = oip->i_ci.ci_clen = oip->i_ci.ci_cstart = oip->i_ci.ci_lastw = 0; - if (DOINGSOFTDEP(ovp)) { - if (length > 0 || softdep_slowdown(ovp)) { - /* - * If a file is only partially truncated, then - * we have to clean up the data structures - * describing the allocation past the truncation - * point. Finding and deallocating those structures - * is a lot of work. Since partial truncation occurs - * rarely, we solve the problem by syncing the file - * so that it will have no data structures left. - */ - if ((error = VOP_FSYNC(ovp, cred, MNT_WAIT, - curproc)) != 0) - return (error); - } else { - (void)ufs_quota_free_blocks(oip, DIP(oip, blocks), - NOCRED); - softdep_setup_freeblocks(oip, length); - vinvalbuf(ovp, 0, cred, curproc, 0, INFSLP); - oip->i_flag |= IN_CHANGE | IN_UPDATE; - return (UFS_UPDATE(oip, 0)); - } - } - osize = DIP(oip, size); /* * Lengthen the size of the file. We must ensure that the @@ -244,18 +218,6 @@ ffs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) cred, aflags, &bp); if (error) return (error); - /* - * When we are doing soft updates and the UFS_BALLOC - * above fills in a direct block hole with a full sized - * block that will be truncated down to a fragment below, - * we must flush out the block dependency with an FSYNC - * so that we do not get a soft updates inconsistency - * when we create the fragment below. - */ - if (DOINGSOFTDEP(ovp) && lbn < NDADDR && - fragroundup(fs, blkoff(fs, length)) < fs->fs_bsize && - (error = VOP_FSYNC(ovp, cred, MNT_WAIT, curproc)) != 0) - return (error); DIP_ASSIGN(oip, size, length); size = blksize(fs, oip, lbn); (void) uvm_vnp_uncache(ovp); diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 2c7d9458d..e69de29bb 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -1,5766 +0,0 @@ -/* $OpenBSD: ffs_softdep.c,v 1.152 2023/07/05 15:13:28 beck Exp $ */ - -/* - * Copyright 1998, 2000 Marshall Kirk McKusick. All Rights Reserved. - * - * The soft updates code is derived from the appendix of a University - * of Michigan technical report (Gregory R. Ganger and Yale N. Patt, - * "Soft Updates: A Solution to the Metadata Update Problem in File - * Systems", CSE-TR-254-95, August 1995). - * - * Further information about soft updates can be obtained from: - * - * Marshall Kirk McKusick http://www.mckusick.com/softdep/ - * 1614 Oxford Street mckusick@mckusick.com - * Berkeley, CA 94709-1608 +1-510-843-9542 - * USA - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY MARSHALL KIRK MCKUSICK ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL MARSHALL KIRK MCKUSICK BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)ffs_softdep.c 9.59 (McKusick) 6/21/00 - * $FreeBSD: src/sys/ufs/ffs/ffs_softdep.c,v 1.86 2001/02/04 16:08:18 phk Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STATIC - -/* - * Mapping of dependency structure types to malloc types. - */ -#define D_PAGEDEP 0 -#define D_INODEDEP 1 -#define D_NEWBLK 2 -#define D_BMSAFEMAP 3 -#define D_ALLOCDIRECT 4 -#define D_INDIRDEP 5 -#define D_ALLOCINDIR 6 -#define D_FREEFRAG 7 -#define D_FREEBLKS 8 -#define D_FREEFILE 9 -#define D_DIRADD 10 -#define D_MKDIR 11 -#define D_DIRREM 12 -#define D_NEWDIRBLK 13 -#define D_LAST 13 -/* - * Names of softdep types. - */ -const char *softdep_typenames[] = { - "pagedep", - "inodedep", - "newblk", - "bmsafemap", - "allocdirect", - "indirdep", - "allocindir", - "freefrag", - "freeblks", - "freefile", - "diradd", - "mkdir", - "dirrem", - "newdirblk", -}; -#define TYPENAME(type) \ - ((unsigned)(type) <= D_LAST ? softdep_typenames[type] : "???") -/* - * Finding the current process. - */ -#define CURPROC curproc -/* - * End system adaptation definitions. - */ - -/* - * Internal function prototypes. - */ -STATIC void softdep_error(char *, int); -STATIC void drain_output(struct vnode *, int); -STATIC int getdirtybuf(struct buf *, int); -STATIC void clear_remove(struct proc *); -STATIC void clear_inodedeps(struct proc *); -STATIC int flush_pagedep_deps(struct vnode *, struct mount *, - struct diraddhd *); -STATIC int flush_inodedep_deps(struct fs *, ufsino_t); -STATIC int handle_written_filepage(struct pagedep *, struct buf *); -STATIC void diradd_inode_written(struct diradd *, struct inodedep *); -STATIC int handle_written_inodeblock(struct inodedep *, struct buf *); -STATIC void handle_allocdirect_partdone(struct allocdirect *); -STATIC void handle_allocindir_partdone(struct allocindir *); -STATIC void initiate_write_filepage(struct pagedep *, struct buf *); -STATIC void handle_written_mkdir(struct mkdir *, int); -STATIC void initiate_write_inodeblock_ufs1(struct inodedep *, struct buf *); -#ifdef FFS2 -STATIC void initiate_write_inodeblock_ufs2(struct inodedep *, struct buf *); -#endif -STATIC void handle_workitem_freefile(struct freefile *); -STATIC void handle_workitem_remove(struct dirrem *); -STATIC struct dirrem *newdirrem(struct buf *, struct inode *, - struct inode *, int, struct dirrem **); -STATIC void free_diradd(struct diradd *); -STATIC void free_allocindir(struct allocindir *, struct inodedep *); -STATIC void free_newdirblk(struct newdirblk *); -STATIC int indir_trunc(struct inode *, daddr_t, int, daddr_t, long *); -STATIC void deallocate_dependencies(struct buf *, struct inodedep *); -STATIC void free_allocdirect(struct allocdirectlst *, - struct allocdirect *, int); -STATIC int check_inode_unwritten(struct inodedep *); -STATIC int free_inodedep(struct inodedep *); -STATIC void handle_workitem_freeblocks(struct freeblks *); -STATIC void merge_inode_lists(struct inodedep *); -STATIC void setup_allocindir_phase2(struct buf *, struct inode *, - struct allocindir *); -STATIC struct allocindir *newallocindir(struct inode *, int, daddr_t, - daddr_t); -STATIC void handle_workitem_freefrag(struct freefrag *); -STATIC struct freefrag *newfreefrag(struct inode *, daddr_t, long); -STATIC void allocdirect_merge(struct allocdirectlst *, - struct allocdirect *, struct allocdirect *); -STATIC struct bmsafemap *bmsafemap_lookup(struct buf *); -STATIC int newblk_lookup(struct fs *, daddr_t, int, - struct newblk **); -STATIC int inodedep_lookup(struct fs *, ufsino_t, int, struct inodedep **); -STATIC int pagedep_lookup(struct inode *, daddr_t, int, struct pagedep **); -STATIC void pause_timer(void *); -STATIC int request_cleanup(int, int); -STATIC int process_worklist_item(struct mount *, int *, int); -STATIC void add_to_worklist(struct worklist *); - -/* - * Exported softdep operations. - */ -void softdep_disk_io_initiation(struct buf *); -void softdep_disk_write_complete(struct buf *); -void softdep_deallocate_dependencies(struct buf *); -void softdep_move_dependencies(struct buf *, struct buf *); -int softdep_count_dependencies(struct buf *bp, int, int); - -/* - * Locking primitives. - * - * For a uniprocessor, all we need to do is protect against disk - * interrupts. For a multiprocessor, this lock would have to be - * a mutex. A single mutex is used throughout this file, though - * finer grain locking could be used if contention warranted it. - * - * For a multiprocessor, the sleep call would accept a lock and - * release it after the sleep processing was complete. In a uniprocessor - * implementation there is no such interlock, so we simple mark - * the places where it needs to be done with the `interlocked' form - * of the lock calls. Since the uniprocessor sleep already interlocks - * the spl, there is nothing that really needs to be done. - */ -#ifndef /* NOT */ DEBUG -STATIC struct lockit { - int lkt_spl; -} lk = { 0 }; -#define ACQUIRE_LOCK(lk) (lk)->lkt_spl = splbio() -#define FREE_LOCK(lk) splx((lk)->lkt_spl) -#define ACQUIRE_LOCK_INTERLOCKED(lk,s) (lk)->lkt_spl = (s) -#define FREE_LOCK_INTERLOCKED(lk) ((lk)->lkt_spl) - -#else /* DEBUG */ -STATIC struct lockit { - int lkt_spl; - pid_t lkt_held; - int lkt_line; -} lk = { 0, -1 }; -STATIC int lockcnt; - -STATIC void acquire_lock(struct lockit *, int); -STATIC void free_lock(struct lockit *, int); -STATIC void acquire_lock_interlocked(struct lockit *, int, int); -STATIC int free_lock_interlocked(struct lockit *, int); - -#define ACQUIRE_LOCK(lk) acquire_lock(lk, __LINE__) -#define FREE_LOCK(lk) free_lock(lk, __LINE__) -#define ACQUIRE_LOCK_INTERLOCKED(lk,s) acquire_lock_interlocked(lk, (s), __LINE__) -#define FREE_LOCK_INTERLOCKED(lk) free_lock_interlocked(lk, __LINE__) - -STATIC void -acquire_lock(struct lockit *lk, int line) -{ - pid_t holder; - int original_line; - - if (lk->lkt_held != -1) { - holder = lk->lkt_held; - original_line = lk->lkt_line; - FREE_LOCK(lk); - if (holder == CURPROC->p_tid) - panic("softdep_lock: locking against myself, acquired at line %d, relocked at line %d", original_line, line); - else - panic("softdep_lock: lock held by %d, acquired at line %d, relocked at line %d", holder, original_line, line); - } - lk->lkt_spl = splbio(); - lk->lkt_held = CURPROC->p_tid; - lk->lkt_line = line; - lockcnt++; -} - -STATIC void -free_lock(struct lockit *lk, int line) -{ - - if (lk->lkt_held == -1) - panic("softdep_unlock: lock not held at line %d", line); - lk->lkt_held = -1; - splx(lk->lkt_spl); -} - -STATIC void -acquire_lock_interlocked(struct lockit *lk, int s, int line) -{ - pid_t holder; - int original_line; - - if (lk->lkt_held != -1) { - holder = lk->lkt_held; - original_line = lk->lkt_line; - FREE_LOCK_INTERLOCKED(lk); - if (holder == CURPROC->p_tid) - panic("softdep_lock: locking against myself, acquired at line %d, relocked at line %d", original_line, line); - else - panic("softdep_lock: lock held by %d, acquired at line %d, relocked at line %d", holder, original_line, line); - } - lk->lkt_held = CURPROC->p_tid; - lk->lkt_line = line; - lk->lkt_spl = s; - lockcnt++; -} - -STATIC int -free_lock_interlocked(struct lockit *lk, int line) -{ - - if (lk->lkt_held == -1) - panic("softdep_unlock_interlocked: lock not held at line %d", line); - lk->lkt_held = -1; - - return (lk->lkt_spl); -} -#endif /* DEBUG */ - -/* - * Place holder for real semaphores. - */ -struct sema { - int value; - pid_t holder; - char *name; - int prio; -}; -STATIC void sema_init(struct sema *, char *, int); -STATIC int sema_get(struct sema *, struct lockit *); -STATIC void sema_release(struct sema *); - -STATIC void -sema_init(struct sema *semap, char *name, int prio) -{ - - semap->holder = -1; - semap->value = 0; - semap->name = name; - semap->prio = prio; -} - -STATIC int -sema_get(struct sema *semap, struct lockit *interlock) -{ - int s; - - if (semap->value++ > 0) { - if (interlock != NULL) - s = FREE_LOCK_INTERLOCKED(interlock); - tsleep_nsec(semap, semap->prio, semap->name, INFSLP); - if (interlock != NULL) { - ACQUIRE_LOCK_INTERLOCKED(interlock, s); - FREE_LOCK(interlock); - } - return (0); - } - semap->holder = CURPROC->p_tid; - if (interlock != NULL) - FREE_LOCK(interlock); - return (1); -} - -STATIC void -sema_release(struct sema *semap) -{ - - if (semap->value <= 0 || semap->holder != CURPROC->p_tid) { -#ifdef DEBUG - if (lk.lkt_held != -1) - FREE_LOCK(&lk); -#endif - panic("sema_release: not held"); - } - if (--semap->value > 0) { - semap->value = 0; - wakeup(semap); - } - semap->holder = -1; -} - -/* - * Memory management. - */ -STATIC struct pool pagedep_pool; -STATIC struct pool inodedep_pool; -STATIC struct pool newblk_pool; -STATIC struct pool bmsafemap_pool; -STATIC struct pool allocdirect_pool; -STATIC struct pool indirdep_pool; -STATIC struct pool allocindir_pool; -STATIC struct pool freefrag_pool; -STATIC struct pool freeblks_pool; -STATIC struct pool freefile_pool; -STATIC struct pool diradd_pool; -STATIC struct pool mkdir_pool; -STATIC struct pool dirrem_pool; -STATIC struct pool newdirblk_pool; - -static __inline void -softdep_free(struct worklist *item, int type) -{ - - switch (type) { - case D_PAGEDEP: - pool_put(&pagedep_pool, item); - break; - - case D_INODEDEP: - pool_put(&inodedep_pool, item); - break; - - case D_BMSAFEMAP: - pool_put(&bmsafemap_pool, item); - break; - - case D_ALLOCDIRECT: - pool_put(&allocdirect_pool, item); - break; - - case D_INDIRDEP: - pool_put(&indirdep_pool, item); - break; - - case D_ALLOCINDIR: - pool_put(&allocindir_pool, item); - break; - - case D_FREEFRAG: - pool_put(&freefrag_pool, item); - break; - - case D_FREEBLKS: - pool_put(&freeblks_pool, item); - break; - - case D_FREEFILE: - pool_put(&freefile_pool, item); - break; - - case D_DIRADD: - pool_put(&diradd_pool, item); - break; - - case D_MKDIR: - pool_put(&mkdir_pool, item); - break; - - case D_DIRREM: - pool_put(&dirrem_pool, item); - break; - - case D_NEWDIRBLK: - pool_put(&newdirblk_pool, item); - break; - - default: -#ifdef DEBUG - if (lk.lkt_held != -1) - FREE_LOCK(&lk); -#endif - panic("softdep_free: unknown type %d", type); - } -} - -struct workhead softdep_freequeue; - -static __inline void -softdep_freequeue_add(struct worklist *item) -{ - int s; - - s = splbio(); - LIST_INSERT_HEAD(&softdep_freequeue, item, wk_list); - splx(s); -} - -static __inline void -softdep_freequeue_process(void) -{ - struct worklist *wk; - - splassert(IPL_BIO); - - while ((wk = LIST_FIRST(&softdep_freequeue)) != NULL) { - LIST_REMOVE(wk, wk_list); - FREE_LOCK(&lk); - softdep_free(wk, wk->wk_type); - ACQUIRE_LOCK(&lk); - } -} - -/* - * Worklist queue management. - * These routines require that the lock be held. - */ -#ifndef /* NOT */ DEBUG -#define WORKLIST_INSERT(head, item) do { \ - (item)->wk_state |= ONWORKLIST; \ - LIST_INSERT_HEAD(head, item, wk_list); \ -} while (0) -#define WORKLIST_REMOVE(item) do { \ - (item)->wk_state &= ~ONWORKLIST; \ - LIST_REMOVE(item, wk_list); \ -} while (0) -#define WORKITEM_FREE(item, type) softdep_freequeue_add((struct worklist *)item) - -#else /* DEBUG */ -STATIC void worklist_insert(struct workhead *, struct worklist *); -STATIC void worklist_remove(struct worklist *); -STATIC void workitem_free(struct worklist *); - -#define WORKLIST_INSERT(head, item) worklist_insert(head, item) -#define WORKLIST_REMOVE(item) worklist_remove(item) -#define WORKITEM_FREE(item, type) workitem_free((struct worklist *)item) - -STATIC void -worklist_insert(struct workhead *head, struct worklist *item) -{ - - if (lk.lkt_held == -1) - panic("worklist_insert: lock not held"); - if (item->wk_state & ONWORKLIST) { - FREE_LOCK(&lk); - panic("worklist_insert: already on list"); - } - item->wk_state |= ONWORKLIST; - LIST_INSERT_HEAD(head, item, wk_list); -} - -STATIC void -worklist_remove(struct worklist *item) -{ - - if (lk.lkt_held == -1) - panic("worklist_remove: lock not held"); - if ((item->wk_state & ONWORKLIST) == 0) { - FREE_LOCK(&lk); - panic("worklist_remove: not on list"); - } - item->wk_state &= ~ONWORKLIST; - LIST_REMOVE(item, wk_list); -} - -STATIC void -workitem_free(struct worklist *item) -{ - - if (item->wk_state & ONWORKLIST) { - if (lk.lkt_held != -1) - FREE_LOCK(&lk); - panic("workitem_free: still on list"); - } - softdep_freequeue_add(item); -} -#endif /* DEBUG */ - -/* - * Workitem queue management - */ -STATIC struct workhead softdep_workitem_pending; -STATIC struct worklist *worklist_tail; -STATIC int num_on_worklist; /* number of worklist items to be processed */ -STATIC int softdep_worklist_busy; /* 1 => trying to do unmount */ -STATIC int softdep_worklist_req; /* serialized waiters */ -STATIC int max_softdeps; /* maximum number of structs before slowdown */ -STATIC int tickdelay = 2; /* number of ticks to pause during slowdown */ -STATIC int proc_waiting; /* tracks whether we have a timeout posted */ -STATIC int *stat_countp; /* statistic to count in proc_waiting timeout */ -STATIC struct timeout proc_waiting_timeout; -STATIC struct proc *filesys_syncer; /* proc of filesystem syncer process */ -STATIC int req_clear_inodedeps; /* syncer process flush some inodedeps */ -#define FLUSH_INODES 1 -STATIC int req_clear_remove; /* syncer process flush some freeblks */ -#define FLUSH_REMOVE 2 -/* - * runtime statistics - */ -STATIC int stat_worklist_push; /* number of worklist cleanups */ -STATIC int stat_blk_limit_push; /* number of times block limit neared */ -STATIC int stat_ino_limit_push; /* number of times inode limit neared */ -STATIC int stat_blk_limit_hit; /* number of times block slowdown imposed */ -STATIC int stat_ino_limit_hit; /* number of times inode slowdown imposed */ -STATIC int stat_sync_limit_hit; /* number of synchronous slowdowns imposed */ -STATIC int stat_indir_blk_ptrs; /* bufs redirtied as indir ptrs not written */ -STATIC int stat_inode_bitmap; /* bufs redirtied as inode bitmap not written */ -STATIC int stat_direct_blk_ptrs;/* bufs redirtied as direct ptrs not written */ -STATIC int stat_dir_entry; /* bufs redirtied as dir entry cannot write */ - -/* - * Add an item to the end of the work queue. - * This routine requires that the lock be held. - * This is the only routine that adds items to the list. - * The following routine is the only one that removes items - * and does so in order from first to last. - */ -STATIC void -add_to_worklist(struct worklist *wk) -{ - - if (wk->wk_state & ONWORKLIST) { -#ifdef DEBUG - if (lk.lkt_held != -1) - FREE_LOCK(&lk); -#endif - panic("add_to_worklist: already on list"); - } - wk->wk_state |= ONWORKLIST; - if (LIST_FIRST(&softdep_workitem_pending) == NULL) - LIST_INSERT_HEAD(&softdep_workitem_pending, wk, wk_list); - else - LIST_INSERT_AFTER(worklist_tail, wk, wk_list); - worklist_tail = wk; - num_on_worklist += 1; -} - -/* - * Process that runs once per second to handle items in the background queue. - * - * Note that we ensure that everything is done in the order in which they - * appear in the queue. The code below depends on this property to ensure - * that blocks of a file are freed before the inode itself is freed. This - * ordering ensures that no new triples will be generated - * until all the old ones have been purged from the dependency lists. - */ -int -softdep_process_worklist(struct mount *matchmnt) -{ - struct proc *p = CURPROC; - int matchcnt, loopcount; - struct timeval starttime; - - /* - * First process any items on the delayed-free queue. - */ - ACQUIRE_LOCK(&lk); - softdep_freequeue_process(); - FREE_LOCK(&lk); - - /* - * Record the process identifier of our caller so that we can give - * this process preferential treatment in request_cleanup below. - * We can't do this in softdep_initialize, because the syncer doesn't - * have to run then. - * NOTE! This function _could_ be called with a curproc != syncerproc. - */ - filesys_syncer = syncerproc; - matchcnt = 0; - - /* - * There is no danger of having multiple processes run this - * code, but we have to single-thread it when softdep_flushfiles() - * is in operation to get an accurate count of the number of items - * related to its mount point that are in the list. - */ - if (matchmnt == NULL) { - if (softdep_worklist_busy < 0) - return(-1); - softdep_worklist_busy += 1; - } - - /* - * If requested, try removing inode or removal dependencies. - */ - if (req_clear_inodedeps) { - clear_inodedeps(p); - req_clear_inodedeps -= 1; - wakeup_one(&proc_waiting); - } - if (req_clear_remove) { - clear_remove(p); - req_clear_remove -= 1; - wakeup_one(&proc_waiting); - } - loopcount = 1; - getmicrouptime(&starttime); - while (num_on_worklist > 0) { - if (process_worklist_item(matchmnt, &matchcnt, LK_NOWAIT) == 0) - break; - - /* - * If a umount operation wants to run the worklist - * accurately, abort. - */ - if (softdep_worklist_req && matchmnt == NULL) { - matchcnt = -1; - break; - } - - /* - * If requested, try removing inode or removal dependencies. - */ - if (req_clear_inodedeps) { - clear_inodedeps(p); - req_clear_inodedeps -= 1; - wakeup_one(&proc_waiting); - } - if (req_clear_remove) { - clear_remove(p); - req_clear_remove -= 1; - wakeup_one(&proc_waiting); - } - /* - * We do not generally want to stop for buffer space, but if - * we are really being a buffer hog, we will stop and wait. - */ -#if 0 - if (loopcount++ % 128 == 0) - bwillwrite(); -#endif - /* - * Never allow processing to run for more than one - * second. Otherwise the other syncer tasks may get - * excessively backlogged. - */ - { - struct timeval diff; - struct timeval tv; - - getmicrouptime(&tv); - timersub(&tv, &starttime, &diff); - if (diff.tv_sec != 0 && matchmnt == NULL) { - matchcnt = -1; - break; - } - } - - /* - * Process any new items on the delayed-free queue. - */ - ACQUIRE_LOCK(&lk); - softdep_freequeue_process(); - FREE_LOCK(&lk); - } - if (matchmnt == NULL) { - softdep_worklist_busy -= 1; - if (softdep_worklist_req && softdep_worklist_busy == 0) - wakeup(&softdep_worklist_req); - } - return (matchcnt); -} - -/* - * Process one item on the worklist. - */ -STATIC int -process_worklist_item(struct mount *matchmnt, int *matchcnt, int flags) -{ - struct worklist *wk, *wkend; - struct dirrem *dirrem; - struct mount *mp; - struct vnode *vp; - - ACQUIRE_LOCK(&lk); - /* - * Normally we just process each item on the worklist in order. - * However, if we are in a situation where we cannot lock any - * inodes, we have to skip over any dirrem requests whose - * vnodes are resident and locked. - */ - LIST_FOREACH(wk, &softdep_workitem_pending, wk_list) { - if ((flags & LK_NOWAIT) == 0 || wk->wk_type != D_DIRREM) - break; - dirrem = WK_DIRREM(wk); - vp = ufs_ihashlookup(VFSTOUFS(dirrem->dm_mnt)->um_dev, - dirrem->dm_oldinum); - if (vp == NULL || !VOP_ISLOCKED(vp)) - break; - } - if (wk == NULL) { - FREE_LOCK(&lk); - return (0); - } - /* - * Remove the item to be processed. If we are removing the last - * item on the list, we need to recalculate the tail pointer. - * As this happens rarely and usually when the list is short, - * we just run down the list to find it rather than tracking it - * in the above loop. - */ - WORKLIST_REMOVE(wk); - if (wk == worklist_tail) { - LIST_FOREACH(wkend, &softdep_workitem_pending, wk_list) - if (LIST_NEXT(wkend, wk_list) == NULL) - break; - worklist_tail = wkend; - } - num_on_worklist -= 1; - FREE_LOCK(&lk); - switch (wk->wk_type) { - - case D_DIRREM: - /* removal of a directory entry */ - mp = WK_DIRREM(wk)->dm_mnt; -#if 0 - if (vn_write_suspend_wait(NULL, mp, V_NOWAIT)) - panic("%s: dirrem on suspended filesystem", - "process_worklist_item"); -#endif - if (matchmnt != NULL && mp == matchmnt) - *matchcnt += 1; - handle_workitem_remove(WK_DIRREM(wk)); - break; - - case D_FREEBLKS: - /* releasing blocks and/or fragments from a file */ - mp = WK_FREEBLKS(wk)->fb_mnt; -#if 0 - if (vn_write_suspend_wait(NULL, mp, V_NOWAIT)) - panic("%s: freeblks on suspended filesystem", - "process_worklist_item"); -#endif - if (matchmnt != NULL && mp == matchmnt) - *matchcnt += 1; - handle_workitem_freeblocks(WK_FREEBLKS(wk)); - break; - - case D_FREEFRAG: - /* releasing a fragment when replaced as a file grows */ - mp = WK_FREEFRAG(wk)->ff_mnt; -#if 0 - if (vn_write_suspend_wait(NULL, mp, V_NOWAIT)) - panic("%s: freefrag on suspended filesystem", - "process_worklist_item"); -#endif - if (matchmnt != NULL && mp == matchmnt) - *matchcnt += 1; - handle_workitem_freefrag(WK_FREEFRAG(wk)); - break; - - case D_FREEFILE: - /* releasing an inode when its link count drops to 0 */ - mp = WK_FREEFILE(wk)->fx_mnt; -#if 0 - if (vn_write_suspend_wait(NULL, mp, V_NOWAIT)) - panic("%s: freefile on suspended filesystem", - "process_worklist_item"); -#endif - if (matchmnt != NULL && mp == matchmnt) - *matchcnt += 1; - handle_workitem_freefile(WK_FREEFILE(wk)); - break; - - default: - panic("%s_process_worklist: Unknown type %s", - "softdep", TYPENAME(wk->wk_type)); - /* NOTREACHED */ - } - return (1); -} - -/* - * Move dependencies from one buffer to another. - */ -void -softdep_move_dependencies(struct buf *oldbp, struct buf *newbp) -{ - struct worklist *wk, *wktail; - - if (LIST_FIRST(&newbp->b_dep) != NULL) - panic("softdep_move_dependencies: need merge code"); - wktail = NULL; - ACQUIRE_LOCK(&lk); - while ((wk = LIST_FIRST(&oldbp->b_dep)) != NULL) { - LIST_REMOVE(wk, wk_list); - if (wktail == NULL) - LIST_INSERT_HEAD(&newbp->b_dep, wk, wk_list); - else - LIST_INSERT_AFTER(wktail, wk, wk_list); - wktail = wk; - } - FREE_LOCK(&lk); -} - -/* - * Purge the work list of all items associated with a particular mount point. - */ -int -softdep_flushworklist(struct mount *oldmnt, int *countp, struct proc *p) -{ - struct vnode *devvp; - int count, error = 0; - - /* - * Await our turn to clear out the queue, then serialize access. - */ - while (softdep_worklist_busy) { - softdep_worklist_req += 1; - tsleep_nsec(&softdep_worklist_req, PRIBIO, "softflush", INFSLP); - softdep_worklist_req -= 1; - } - softdep_worklist_busy = -1; - /* - * Alternately flush the block device associated with the mount - * point and process any dependencies that the flushing - * creates. We continue until no more worklist dependencies - * are found. - */ - *countp = 0; - devvp = VFSTOUFS(oldmnt)->um_devvp; - while ((count = softdep_process_worklist(oldmnt)) > 0) { - *countp += count; - vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); - error = VOP_FSYNC(devvp, p->p_ucred, MNT_WAIT, p); - VOP_UNLOCK(devvp); - if (error) - break; - } - softdep_worklist_busy = 0; - if (softdep_worklist_req) - wakeup(&softdep_worklist_req); - return (error); -} - -/* - * Flush all vnodes and worklist items associated with a specified mount point. - */ -int -softdep_flushfiles(struct mount *oldmnt, int flags, struct proc *p) -{ - int error, count, loopcnt; - - /* - * Alternately flush the vnodes associated with the mount - * point and process any dependencies that the flushing - * creates. In theory, this loop can happen at most twice, - * but we give it a few extra just to be sure. - */ - for (loopcnt = 10; loopcnt > 0; loopcnt--) { - /* - * Do another flush in case any vnodes were brought in - * as part of the cleanup operations. - */ - if ((error = ffs_flushfiles(oldmnt, flags, p)) != 0) - break; - if ((error = softdep_flushworklist(oldmnt, &count, p)) != 0 || - count == 0) - break; - } - /* - * If the reboot process sleeps during the loop, the update - * process may call softdep_process_worklist() and create - * new dirty vnodes at the mount point. Call ffs_flushfiles() - * again after the loop has flushed all soft dependencies. - */ - if (error == 0) - error = ffs_flushfiles(oldmnt, flags, p); - /* - * If we are unmounting then it is an error to fail. If we - * are simply trying to downgrade to read-only, then filesystem - * activity can keep us busy forever, so we just fail with EBUSY. - */ - if (loopcnt == 0) { - error = EBUSY; - } - return (error); -} - -/* - * Structure hashing. - * - * There are three types of structures that can be looked up: - * 1) pagedep structures identified by mount point, inode number, - * and logical block. - * 2) inodedep structures identified by mount point and inode number. - * 3) newblk structures identified by mount point and - * physical block number. - * - * The "pagedep" and "inodedep" dependency structures are hashed - * separately from the file blocks and inodes to which they correspond. - * This separation helps when the in-memory copy of an inode or - * file block must be replaced. It also obviates the need to access - * an inode or file page when simply updating (or de-allocating) - * dependency structures. Lookup of newblk structures is needed to - * find newly allocated blocks when trying to associate them with - * their allocdirect or allocindir structure. - * - * The lookup routines optionally create and hash a new instance when - * an existing entry is not found. - */ -#define DEPALLOC 0x0001 /* allocate structure if lookup fails */ -#define NODELAY 0x0002 /* cannot do background work */ - -SIPHASH_KEY softdep_hashkey; - -/* - * Structures and routines associated with pagedep caching. - */ -LIST_HEAD(pagedep_hashhead, pagedep) *pagedep_hashtbl; -u_long pagedep_hash; /* size of hash table - 1 */ -STATIC struct sema pagedep_in_progress; - -/* - * Look up a pagedep. Return 1 if found, 0 if not found or found - * when asked to allocate but not associated with any buffer. - * If not found, allocate if DEPALLOC flag is passed. - * Found or allocated entry is returned in pagedeppp. - * This routine must be called with splbio interrupts blocked. - */ -STATIC int -pagedep_lookup(struct inode *ip, daddr_t lbn, int flags, - struct pagedep **pagedeppp) -{ - SIPHASH_CTX ctx; - struct pagedep *pagedep; - struct pagedep_hashhead *pagedephd; - struct mount *mp; - int i; - - splassert(IPL_BIO); - -#ifdef DEBUG - if (lk.lkt_held == -1) - panic("pagedep_lookup: lock not held"); -#endif - mp = ITOV(ip)->v_mount; - - SipHash24_Init(&ctx, &softdep_hashkey); - SipHash24_Update(&ctx, &mp, sizeof(mp)); - SipHash24_Update(&ctx, &ip->i_number, sizeof(ip->i_number)); - SipHash24_Update(&ctx, &lbn, sizeof(lbn)); - pagedephd = &pagedep_hashtbl[SipHash24_End(&ctx) & pagedep_hash]; -top: - LIST_FOREACH(pagedep, pagedephd, pd_hash) - if (ip->i_number == pagedep->pd_ino && - lbn == pagedep->pd_lbn && - mp == pagedep->pd_mnt) - break; - if (pagedep) { - *pagedeppp = pagedep; - if ((flags & DEPALLOC) != 0 && - (pagedep->pd_state & ONWORKLIST) == 0) - return (0); - return (1); - } - if ((flags & DEPALLOC) == 0) { - *pagedeppp = NULL; - return (0); - } - if (sema_get(&pagedep_in_progress, &lk) == 0) { - ACQUIRE_LOCK(&lk); - goto top; - } - pagedep = pool_get(&pagedep_pool, PR_WAITOK | PR_ZERO); - pagedep->pd_list.wk_type = D_PAGEDEP; - pagedep->pd_mnt = mp; - pagedep->pd_ino = ip->i_number; - pagedep->pd_lbn = lbn; - LIST_INIT(&pagedep->pd_dirremhd); - LIST_INIT(&pagedep->pd_pendinghd); - for (i = 0; i < DAHASHSZ; i++) - LIST_INIT(&pagedep->pd_diraddhd[i]); - ACQUIRE_LOCK(&lk); - LIST_INSERT_HEAD(pagedephd, pagedep, pd_hash); - sema_release(&pagedep_in_progress); - *pagedeppp = pagedep; - return (0); -} - -/* - * Structures and routines associated with inodedep caching. - */ -LIST_HEAD(inodedep_hashhead, inodedep) *inodedep_hashtbl; -STATIC u_long inodedep_hash; /* size of hash table - 1 */ -STATIC long num_inodedep; /* number of inodedep allocated */ -STATIC struct sema inodedep_in_progress; - -/* - * Look up a inodedep. Return 1 if found, 0 if not found. - * If not found, allocate if DEPALLOC flag is passed. - * Found or allocated entry is returned in inodedeppp. - * This routine must be called with splbio interrupts blocked. - */ -STATIC int -inodedep_lookup(struct fs *fs, ufsino_t inum, int flags, - struct inodedep **inodedeppp) -{ - SIPHASH_CTX ctx; - struct inodedep *inodedep; - struct inodedep_hashhead *inodedephd; - int firsttry; - - splassert(IPL_BIO); - -#ifdef DEBUG - if (lk.lkt_held == -1) - panic("inodedep_lookup: lock not held"); -#endif - firsttry = 1; - SipHash24_Init(&ctx, &softdep_hashkey); - SipHash24_Update(&ctx, &fs, sizeof(fs)); - SipHash24_Update(&ctx, &inum, sizeof(inum)); - inodedephd = &inodedep_hashtbl[SipHash24_End(&ctx) & inodedep_hash]; -top: - LIST_FOREACH(inodedep, inodedephd, id_hash) - if (inum == inodedep->id_ino && fs == inodedep->id_fs) - break; - if (inodedep) { - *inodedeppp = inodedep; - return (1); - } - if ((flags & DEPALLOC) == 0) { - *inodedeppp = NULL; - return (0); - } - /* - * If we are over our limit, try to improve the situation. - */ - if (num_inodedep > max_softdeps && firsttry && (flags & NODELAY) == 0 && - request_cleanup(FLUSH_INODES, 1)) { - firsttry = 0; - goto top; - } - if (sema_get(&inodedep_in_progress, &lk) == 0) { - ACQUIRE_LOCK(&lk); - goto top; - } - num_inodedep += 1; - inodedep = pool_get(&inodedep_pool, PR_WAITOK); - inodedep->id_list.wk_type = D_INODEDEP; - inodedep->id_fs = fs; - inodedep->id_ino = inum; - inodedep->id_state = ALLCOMPLETE; - inodedep->id_nlinkdelta = 0; - inodedep->id_savedino1 = NULL; - inodedep->id_savedsize = -1; - inodedep->id_buf = NULL; - LIST_INIT(&inodedep->id_pendinghd); - LIST_INIT(&inodedep->id_inowait); - LIST_INIT(&inodedep->id_bufwait); - TAILQ_INIT(&inodedep->id_inoupdt); - TAILQ_INIT(&inodedep->id_newinoupdt); - ACQUIRE_LOCK(&lk); - LIST_INSERT_HEAD(inodedephd, inodedep, id_hash); - sema_release(&inodedep_in_progress); - *inodedeppp = inodedep; - return (0); -} - -/* - * Structures and routines associated with newblk caching. - */ -LIST_HEAD(newblk_hashhead, newblk) *newblk_hashtbl; -u_long newblk_hash; /* size of hash table - 1 */ -STATIC struct sema newblk_in_progress; - -/* - * Look up a newblk. Return 1 if found, 0 if not found. - * If not found, allocate if DEPALLOC flag is passed. - * Found or allocated entry is returned in newblkpp. - */ -STATIC int -newblk_lookup(struct fs *fs, daddr_t newblkno, int flags, - struct newblk **newblkpp) -{ - SIPHASH_CTX ctx; - struct newblk *newblk; - struct newblk_hashhead *newblkhd; - - SipHash24_Init(&ctx, &softdep_hashkey); - SipHash24_Update(&ctx, &fs, sizeof(fs)); - SipHash24_Update(&ctx, &newblkno, sizeof(newblkno)); - newblkhd = &newblk_hashtbl[SipHash24_End(&ctx) & newblk_hash]; -top: - LIST_FOREACH(newblk, newblkhd, nb_hash) - if (newblkno == newblk->nb_newblkno && fs == newblk->nb_fs) - break; - if (newblk) { - *newblkpp = newblk; - return (1); - } - if ((flags & DEPALLOC) == 0) { - *newblkpp = NULL; - return (0); - } - if (sema_get(&newblk_in_progress, NULL) == 0) - goto top; - newblk = pool_get(&newblk_pool, PR_WAITOK); - newblk->nb_state = 0; - newblk->nb_fs = fs; - newblk->nb_newblkno = newblkno; - LIST_INSERT_HEAD(newblkhd, newblk, nb_hash); - sema_release(&newblk_in_progress); - *newblkpp = newblk; - return (0); -} - -/* - * Executed during filesystem system initialization before - * mounting any file systems. - */ -void -softdep_initialize(void) -{ - - bioops.io_start = softdep_disk_io_initiation; - bioops.io_complete = softdep_disk_write_complete; - bioops.io_deallocate = softdep_deallocate_dependencies; - bioops.io_movedeps = softdep_move_dependencies; - bioops.io_countdeps = softdep_count_dependencies; - - LIST_INIT(&mkdirlisthd); - LIST_INIT(&softdep_workitem_pending); -#ifdef KMEMSTATS - max_softdeps = min (initialvnodes * 8, - kmemstats[M_INODEDEP].ks_limit / (2 * sizeof(struct inodedep))); -#else - max_softdeps = initialvnodes * 4; -#endif - arc4random_buf(&softdep_hashkey, sizeof(softdep_hashkey)); - pagedep_hashtbl = hashinit(initialvnodes / 5, M_PAGEDEP, M_WAITOK, - &pagedep_hash); - sema_init(&pagedep_in_progress, "pagedep", PRIBIO); - inodedep_hashtbl = hashinit(initialvnodes, M_INODEDEP, M_WAITOK, - &inodedep_hash); - sema_init(&inodedep_in_progress, "inodedep", PRIBIO); - newblk_hashtbl = hashinit(64, M_NEWBLK, M_WAITOK, &newblk_hash); - sema_init(&newblk_in_progress, "newblk", PRIBIO); - timeout_set(&proc_waiting_timeout, pause_timer, NULL); - pool_init(&pagedep_pool, sizeof(struct pagedep), 0, IPL_NONE, - PR_WAITOK, "pagedep", NULL); - pool_init(&inodedep_pool, sizeof(struct inodedep), 0, IPL_NONE, - PR_WAITOK, "inodedep", NULL); - pool_init(&newblk_pool, sizeof(struct newblk), 0, IPL_NONE, - PR_WAITOK, "newblk", NULL); - pool_init(&bmsafemap_pool, sizeof(struct bmsafemap), 0, IPL_NONE, - PR_WAITOK, "bmsafemap", NULL); - pool_init(&allocdirect_pool, sizeof(struct allocdirect), 0, IPL_NONE, - PR_WAITOK, "allocdir", NULL); - pool_init(&indirdep_pool, sizeof(struct indirdep), 0, IPL_NONE, - PR_WAITOK, "indirdep", NULL); - pool_init(&allocindir_pool, sizeof(struct allocindir), 0, IPL_NONE, - PR_WAITOK, "allocindir", NULL); - pool_init(&freefrag_pool, sizeof(struct freefrag), 0, IPL_NONE, - PR_WAITOK, "freefrag", NULL); - pool_init(&freeblks_pool, sizeof(struct freeblks), 0, IPL_NONE, - PR_WAITOK, "freeblks", NULL); - pool_init(&freefile_pool, sizeof(struct freefile), 0, IPL_NONE, - PR_WAITOK, "freefile", NULL); - pool_init(&diradd_pool, sizeof(struct diradd), 0, IPL_NONE, - PR_WAITOK, "diradd", NULL); - pool_init(&mkdir_pool, sizeof(struct mkdir), 0, IPL_NONE, - PR_WAITOK, "mkdir", NULL); - pool_init(&dirrem_pool, sizeof(struct dirrem), 0, IPL_NONE, - PR_WAITOK, "dirrem", NULL); - pool_init(&newdirblk_pool, sizeof(struct newdirblk), 0, IPL_NONE, - PR_WAITOK, "newdirblk", NULL); -} - -/* - * Called at mount time to notify the dependency code that a - * filesystem wishes to use it. - */ -int -softdep_mount(struct vnode *devvp, struct mount *mp, struct fs *fs, - struct ucred *cred) -{ - struct csum_total cstotal; - struct cg *cgp; - struct buf *bp; - int error, cyl; - - KASSERTMSG(1, "softdep_mount should not have been called"); - - /* - * When doing soft updates, the counters in the - * superblock may have gotten out of sync, so we have - * to scan the cylinder groups and recalculate them. - */ - if ((fs->fs_flags & FS_UNCLEAN) == 0) - return (0); - memset(&cstotal, 0, sizeof(cstotal)); - for (cyl = 0; cyl < fs->fs_ncg; cyl++) { - if ((error = bread(devvp, fsbtodb(fs, cgtod(fs, cyl)), - fs->fs_cgsize, &bp)) != 0) { - brelse(bp); - return (error); - } - cgp = (struct cg *)bp->b_data; - cstotal.cs_nffree += cgp->cg_cs.cs_nffree; - cstotal.cs_nbfree += cgp->cg_cs.cs_nbfree; - cstotal.cs_nifree += cgp->cg_cs.cs_nifree; - cstotal.cs_ndir += cgp->cg_cs.cs_ndir; - fs->fs_cs(fs, cyl) = cgp->cg_cs; - brelse(bp); - } -#ifdef DEBUG - if (memcmp(&cstotal, &fs->fs_cstotal, sizeof(cstotal))) - printf("ffs_mountfs: superblock updated for soft updates\n"); -#endif - memcpy(&fs->fs_cstotal, &cstotal, sizeof(cstotal)); - return (0); -} - -/* - * Protecting the freemaps (or bitmaps). - * - * To eliminate the need to execute fsck before mounting a file system - * after a power failure, one must (conservatively) guarantee that the - * on-disk copy of the bitmaps never indicate that a live inode or block is - * free. So, when a block or inode is allocated, the bitmap should be - * updated (on disk) before any new pointers. When a block or inode is - * freed, the bitmap should not be updated until all pointers have been - * reset. The latter dependency is handled by the delayed de-allocation - * approach described below for block and inode de-allocation. The former - * dependency is handled by calling the following procedure when a block or - * inode is allocated. When an inode is allocated an "inodedep" is created - * with its DEPCOMPLETE flag cleared until its bitmap is written to disk. - * Each "inodedep" is also inserted into the hash indexing structure so - * that any additional link additions can be made dependent on the inode - * allocation. - * - * The ufs file system maintains a number of free block counts (e.g., per - * cylinder group, per cylinder and per pair) - * in addition to the bitmaps. These counts are used to improve efficiency - * during allocation and therefore must be consistent with the bitmaps. - * There is no convenient way to guarantee post-crash consistency of these - * counts with simple update ordering, for two main reasons: (1) The counts - * and bitmaps for a single cylinder group block are not in the same disk - * sector. If a disk write is interrupted (e.g., by power failure), one may - * be written and the other not. (2) Some of the counts are located in the - * superblock rather than the cylinder group block. So, we focus our soft - * updates implementation on protecting the bitmaps. When mounting a - * filesystem, we recompute the auxiliary counts from the bitmaps. - */ - -/* - * Called just after updating the cylinder group block to allocate an inode. - */ -/* buffer for cylgroup block with inode map */ -/* inode related to allocation */ -/* new inode number being allocated */ -void -softdep_setup_inomapdep(struct buf *bp, struct inode *ip, ufsino_t newinum) -{ - struct inodedep *inodedep; - struct bmsafemap *bmsafemap; - - /* - * Create a dependency for the newly allocated inode. - * Panic if it already exists as something is seriously wrong. - * Otherwise add it to the dependency list for the buffer holding - * the cylinder group map from which it was allocated. - */ - ACQUIRE_LOCK(&lk); - if (inodedep_lookup(ip->i_fs, newinum, DEPALLOC | NODELAY, &inodedep) - != 0) { - FREE_LOCK(&lk); - panic("softdep_setup_inomapdep: found inode"); - } - inodedep->id_buf = bp; - inodedep->id_state &= ~DEPCOMPLETE; - bmsafemap = bmsafemap_lookup(bp); - LIST_INSERT_HEAD(&bmsafemap->sm_inodedephd, inodedep, id_deps); - FREE_LOCK(&lk); -} - -/* - * Called just after updating the cylinder group block to - * allocate block or fragment. - */ -/* buffer for cylgroup block with block map */ -/* filesystem doing allocation */ -/* number of newly allocated block */ -void -softdep_setup_blkmapdep(struct buf *bp, struct fs *fs, daddr_t newblkno) -{ - struct newblk *newblk; - struct bmsafemap *bmsafemap; - - /* - * Create a dependency for the newly allocated block. - * Add it to the dependency list for the buffer holding - * the cylinder group map from which it was allocated. - */ - if (newblk_lookup(fs, newblkno, DEPALLOC, &newblk) != 0) - panic("softdep_setup_blkmapdep: found block"); - ACQUIRE_LOCK(&lk); - newblk->nb_bmsafemap = bmsafemap = bmsafemap_lookup(bp); - LIST_INSERT_HEAD(&bmsafemap->sm_newblkhd, newblk, nb_deps); - FREE_LOCK(&lk); -} - -/* - * Find the bmsafemap associated with a cylinder group buffer. - * If none exists, create one. The buffer must be locked when - * this routine is called and this routine must be called with - * splbio interrupts blocked. - */ -STATIC struct bmsafemap * -bmsafemap_lookup(struct buf *bp) -{ - struct bmsafemap *bmsafemap; - struct worklist *wk; - - splassert(IPL_BIO); - -#ifdef DEBUG - if (lk.lkt_held == -1) - panic("bmsafemap_lookup: lock not held"); -#endif - LIST_FOREACH(wk, &bp->b_dep, wk_list) - if (wk->wk_type == D_BMSAFEMAP) - return (WK_BMSAFEMAP(wk)); - FREE_LOCK(&lk); - bmsafemap = pool_get(&bmsafemap_pool, PR_WAITOK); - bmsafemap->sm_list.wk_type = D_BMSAFEMAP; - bmsafemap->sm_list.wk_state = 0; - bmsafemap->sm_buf = bp; - LIST_INIT(&bmsafemap->sm_allocdirecthd); - LIST_INIT(&bmsafemap->sm_allocindirhd); - LIST_INIT(&bmsafemap->sm_inodedephd); - LIST_INIT(&bmsafemap->sm_newblkhd); - ACQUIRE_LOCK(&lk); - WORKLIST_INSERT(&bp->b_dep, &bmsafemap->sm_list); - return (bmsafemap); -} - -/* - * Direct block allocation dependencies. - * - * When a new block is allocated, the corresponding disk locations must be - * initialized (with zeros or new data) before the on-disk inode points to - * them. Also, the freemap from which the block was allocated must be - * updated (on disk) before the inode's pointer. These two dependencies are - * independent of each other and are needed for all file blocks and indirect - * blocks that are pointed to directly by the inode. Just before the - * "in-core" version of the inode is updated with a newly allocated block - * number, a procedure (below) is called to setup allocation dependency - * structures. These structures are removed when the corresponding - * dependencies are satisfied or when the block allocation becomes obsolete - * (i.e., the file is deleted, the block is de-allocated, or the block is a - * fragment that gets upgraded). All of these cases are handled in - * procedures described later. - * - * When a file extension causes a fragment to be upgraded, either to a larger - * fragment or to a full block, the on-disk location may change (if the - * previous fragment could not simply be extended). In this case, the old - * fragment must be de-allocated, but not until after the inode's pointer has - * been updated. In most cases, this is handled by later procedures, which - * will construct a "freefrag" structure to be added to the workitem queue - * when the inode update is complete (or obsolete). The main exception to - * this is when an allocation occurs while a pending allocation dependency - * (for the same block pointer) remains. This case is handled in the main - * allocation dependency setup procedure by immediately freeing the - * unreferenced fragments. - */ -/* inode to which block is being added */ -/* block pointer within inode */ -/* disk block number being added */ -/* previous block number, 0 unless frag */ -/* size of new block */ -/* size of new block */ -/* bp for allocated block */ -void -softdep_setup_allocdirect(struct inode *ip, daddr_t lbn, daddr_t newblkno, - daddr_t oldblkno, long newsize, long oldsize, struct buf *bp) -{ - struct allocdirect *adp, *oldadp; - struct allocdirectlst *adphead; - struct bmsafemap *bmsafemap; - struct inodedep *inodedep; - struct pagedep *pagedep; - struct newblk *newblk; - - adp = pool_get(&allocdirect_pool, PR_WAITOK | PR_ZERO); - adp->ad_list.wk_type = D_ALLOCDIRECT; - adp->ad_lbn = lbn; - adp->ad_newblkno = newblkno; - adp->ad_oldblkno = oldblkno; - adp->ad_newsize = newsize; - adp->ad_oldsize = oldsize; - adp->ad_state = ATTACHED; - LIST_INIT(&adp->ad_newdirblk); - if (newblkno == oldblkno) - adp->ad_freefrag = NULL; - else - adp->ad_freefrag = newfreefrag(ip, oldblkno, oldsize); - - if (newblk_lookup(ip->i_fs, newblkno, 0, &newblk) == 0) - panic("softdep_setup_allocdirect: lost block"); - - ACQUIRE_LOCK(&lk); - inodedep_lookup(ip->i_fs, ip->i_number, DEPALLOC | NODELAY, &inodedep); - adp->ad_inodedep = inodedep; - - if (newblk->nb_state == DEPCOMPLETE) { - adp->ad_state |= DEPCOMPLETE; - adp->ad_buf = NULL; - } else { - bmsafemap = newblk->nb_bmsafemap; - adp->ad_buf = bmsafemap->sm_buf; - LIST_REMOVE(newblk, nb_deps); - LIST_INSERT_HEAD(&bmsafemap->sm_allocdirecthd, adp, ad_deps); - } - LIST_REMOVE(newblk, nb_hash); - pool_put(&newblk_pool, newblk); - - if (bp == NULL) { - /* - * XXXUBC - Yes, I know how to fix this, but not right now. - */ - panic("softdep_setup_allocdirect: Bonk art in the head"); - } - WORKLIST_INSERT(&bp->b_dep, &adp->ad_list); - if (lbn >= NDADDR) { - /* allocating an indirect block */ - if (oldblkno != 0) { - FREE_LOCK(&lk); - panic("softdep_setup_allocdirect: non-zero indir"); - } - } else { - /* - * Allocating a direct block. - * - * If we are allocating a directory block, then we must - * allocate an associated pagedep to track additions and - * deletions. - */ - if ((DIP(ip, mode) & IFMT) == IFDIR && - pagedep_lookup(ip, lbn, DEPALLOC, &pagedep) == 0) - WORKLIST_INSERT(&bp->b_dep, &pagedep->pd_list); - } - /* - * The list of allocdirects must be kept in sorted and ascending - * order so that the rollback routines can quickly determine the - * first uncommitted block (the size of the file stored on disk - * ends at the end of the lowest committed fragment, or if there - * are no fragments, at the end of the highest committed block). - * Since files generally grow, the typical case is that the new - * block is to be added at the end of the list. We speed this - * special case by checking against the last allocdirect in the - * list before laboriously traversing the list looking for the - * insertion point. - */ - adphead = &inodedep->id_newinoupdt; - oldadp = TAILQ_LAST(adphead, allocdirectlst); - if (oldadp == NULL || oldadp->ad_lbn <= lbn) { - /* insert at end of list */ - TAILQ_INSERT_TAIL(adphead, adp, ad_next); - if (oldadp != NULL && oldadp->ad_lbn == lbn) - allocdirect_merge(adphead, adp, oldadp); - FREE_LOCK(&lk); - return; - } - TAILQ_FOREACH(oldadp, adphead, ad_next) { - if (oldadp->ad_lbn >= lbn) - break; - } - if (oldadp == NULL) { - FREE_LOCK(&lk); - panic("softdep_setup_allocdirect: lost entry"); - } - /* insert in middle of list */ - TAILQ_INSERT_BEFORE(oldadp, adp, ad_next); - if (oldadp->ad_lbn == lbn) - allocdirect_merge(adphead, adp, oldadp); - FREE_LOCK(&lk); -} - -/* - * Replace an old allocdirect dependency with a newer one. - * This routine must be called with splbio interrupts blocked. - */ -/* head of list holding allocdirects */ -/* allocdirect being added */ -/* existing allocdirect being checked */ -STATIC void -allocdirect_merge(struct allocdirectlst *adphead, struct allocdirect *newadp, - struct allocdirect *oldadp) -{ - struct worklist *wk; - struct freefrag *freefrag; - struct newdirblk *newdirblk; - - splassert(IPL_BIO); - -#ifdef DEBUG - if (lk.lkt_held == -1) - panic("allocdirect_merge: lock not held"); -#endif - if (newadp->ad_oldblkno != oldadp->ad_newblkno || - newadp->ad_oldsize != oldadp->ad_newsize || - newadp->ad_lbn >= NDADDR) { - FREE_LOCK(&lk); - panic("allocdirect_merge: old %lld != new %lld || lbn %lld >= " - "%d", (long long)newadp->ad_oldblkno, - (long long)oldadp->ad_newblkno, (long long)newadp->ad_lbn, - NDADDR); - } - newadp->ad_oldblkno = oldadp->ad_oldblkno; - newadp->ad_oldsize = oldadp->ad_oldsize; - /* - * If the old dependency had a fragment to free or had never - * previously had a block allocated, then the new dependency - * can immediately post its freefrag and adopt the old freefrag. - * This action is done by swapping the freefrag dependencies. - * The new dependency gains the old one's freefrag, and the - * old one gets the new one and then immediately puts it on - * the worklist when it is freed by free_allocdirect. It is - * not possible to do this swap when the old dependency had a - * non-zero size but no previous fragment to free. This condition - * arises when the new block is an extension of the old block. - * Here, the first part of the fragment allocated to the new - * dependency is part of the block currently claimed on disk by - * the old dependency, so cannot legitimately be freed until the - * conditions for the new dependency are fulfilled. - */ - if (oldadp->ad_freefrag != NULL || oldadp->ad_oldblkno == 0) { - freefrag = newadp->ad_freefrag; - newadp->ad_freefrag = oldadp->ad_freefrag; - oldadp->ad_freefrag = freefrag; - } - /* - * If we are tracking a new directory-block allocation, - * move it from the old allocdirect to the new allocdirect. - */ - if ((wk = LIST_FIRST(&oldadp->ad_newdirblk)) != NULL) { - newdirblk = WK_NEWDIRBLK(wk); - WORKLIST_REMOVE(&newdirblk->db_list); - if (LIST_FIRST(&oldadp->ad_newdirblk) != NULL) - panic("allocdirect_merge: extra newdirblk"); - WORKLIST_INSERT(&newadp->ad_newdirblk, &newdirblk->db_list); - } - free_allocdirect(adphead, oldadp, 0); -} - -/* - * Allocate a new freefrag structure if needed. - */ -STATIC struct freefrag * -newfreefrag(struct inode *ip, daddr_t blkno, long size) -{ - struct freefrag *freefrag; - struct fs *fs; - - if (blkno == 0) - return (NULL); - fs = ip->i_fs; - if (fragnum(fs, blkno) + numfrags(fs, size) > fs->fs_frag) - panic("newfreefrag: frag size"); - freefrag = pool_get(&freefrag_pool, PR_WAITOK); - freefrag->ff_list.wk_type = D_FREEFRAG; - freefrag->ff_state = DIP(ip, uid) & ~ONWORKLIST; /* used below */ - freefrag->ff_inum = ip->i_number; - freefrag->ff_mnt = ITOV(ip)->v_mount; - freefrag->ff_devvp = ip->i_devvp; - freefrag->ff_blkno = blkno; - freefrag->ff_fragsize = size; - return (freefrag); -} - -/* - * This workitem de-allocates fragments that were replaced during - * file block allocation. - */ -STATIC void -handle_workitem_freefrag(struct freefrag *freefrag) -{ - struct inode tip; - struct ufs1_dinode dtip1; - - tip.i_vnode = NULL; - tip.i_din1 = &dtip1; - tip.i_fs = VFSTOUFS(freefrag->ff_mnt)->um_fs; - tip.i_ump = VFSTOUFS(freefrag->ff_mnt); - tip.i_dev = freefrag->ff_devvp->v_rdev; - tip.i_number = freefrag->ff_inum; - tip.i_ffs1_uid = freefrag->ff_state & ~ONWORKLIST; /* set above */ - ffs_blkfree(&tip, freefrag->ff_blkno, freefrag->ff_fragsize); - pool_put(&freefrag_pool, freefrag); -} - -/* - * Indirect block allocation dependencies. - * - * The same dependencies that exist for a direct block also exist when - * a new block is allocated and pointed to by an entry in a block of - * indirect pointers. The undo/redo states described above are also - * used here. Because an indirect block contains many pointers that - * may have dependencies, a second copy of the entire in-memory indirect - * block is kept. The buffer cache copy is always completely up-to-date. - * The second copy, which is used only as a source for disk writes, - * contains only the safe pointers (i.e., those that have no remaining - * update dependencies). The second copy is freed when all pointers - * are safe. The cache is not allowed to replace indirect blocks with - * pending update dependencies. If a buffer containing an indirect - * block with dependencies is written, these routines will mark it - * dirty again. It can only be successfully written once all the - * dependencies are removed. The ffs_fsync routine in conjunction with - * softdep_sync_metadata work together to get all the dependencies - * removed so that a file can be successfully written to disk. Three - * procedures are used when setting up indirect block pointer - * dependencies. The division is necessary because of the organization - * of the "balloc" routine and because of the distinction between file - * pages and file metadata blocks. - */ - -/* - * Allocate a new allocindir structure. - */ -/* inode for file being extended */ -/* offset of pointer in indirect block */ -/* disk block number being added */ -/* previous block number, 0 if none */ -STATIC struct allocindir * -newallocindir(struct inode *ip, int ptrno, daddr_t newblkno, - daddr_t oldblkno) -{ - struct allocindir *aip; - - aip = pool_get(&allocindir_pool, PR_WAITOK | PR_ZERO); - aip->ai_list.wk_type = D_ALLOCINDIR; - aip->ai_state = ATTACHED; - aip->ai_offset = ptrno; - aip->ai_newblkno = newblkno; - aip->ai_oldblkno = oldblkno; - aip->ai_freefrag = newfreefrag(ip, oldblkno, ip->i_fs->fs_bsize); - return (aip); -} - -/* - * Called just before setting an indirect block pointer - * to a newly allocated file page. - */ -/* inode for file being extended */ -/* allocated block number within file */ -/* buffer with indirect blk referencing page */ -/* offset of pointer in indirect block */ -/* disk block number being added */ -/* previous block number, 0 if none */ -/* buffer holding allocated page */ -void -softdep_setup_allocindir_page(struct inode *ip, daddr_t lbn, struct buf *bp, - int ptrno, daddr_t newblkno, daddr_t oldblkno, struct buf *nbp) -{ - struct allocindir *aip; - struct pagedep *pagedep; - - aip = newallocindir(ip, ptrno, newblkno, oldblkno); - ACQUIRE_LOCK(&lk); - /* - * If we are allocating a directory page, then we must - * allocate an associated pagedep to track additions and - * deletions. - */ - if ((DIP(ip, mode) & IFMT) == IFDIR && - pagedep_lookup(ip, lbn, DEPALLOC, &pagedep) == 0) - WORKLIST_INSERT(&nbp->b_dep, &pagedep->pd_list); - if (nbp == NULL) { - /* - * XXXUBC - Yes, I know how to fix this, but not right now. - */ - panic("softdep_setup_allocindir_page: Bonk art in the head"); - } - WORKLIST_INSERT(&nbp->b_dep, &aip->ai_list); - FREE_LOCK(&lk); - setup_allocindir_phase2(bp, ip, aip); -} - -/* - * Called just before setting an indirect block pointer to a - * newly allocated indirect block. - */ -/* newly allocated indirect block */ -/* inode for file being extended */ -/* indirect block referencing allocated block */ -/* offset of pointer in indirect block */ -/* disk block number being added */ -void -softdep_setup_allocindir_meta(struct buf *nbp, struct inode *ip, - struct buf *bp, int ptrno, daddr_t newblkno) -{ - struct allocindir *aip; - - aip = newallocindir(ip, ptrno, newblkno, 0); - ACQUIRE_LOCK(&lk); - WORKLIST_INSERT(&nbp->b_dep, &aip->ai_list); - FREE_LOCK(&lk); - setup_allocindir_phase2(bp, ip, aip); -} - -/* - * Called to finish the allocation of the "aip" allocated - * by one of the two routines above. - */ -/* in-memory copy of the indirect block */ -/* inode for file being extended */ -/* allocindir allocated by the above routines */ -STATIC void -setup_allocindir_phase2(struct buf *bp, struct inode *ip, - struct allocindir *aip) -{ - struct worklist *wk; - struct indirdep *indirdep, *newindirdep; - struct bmsafemap *bmsafemap; - struct allocindir *oldaip; - struct freefrag *freefrag; - struct newblk *newblk; - - if (bp->b_lblkno >= 0) - panic("setup_allocindir_phase2: not indir blk"); - for (indirdep = NULL, newindirdep = NULL; ; ) { - ACQUIRE_LOCK(&lk); - LIST_FOREACH(wk, &bp->b_dep, wk_list) { - if (wk->wk_type != D_INDIRDEP) - continue; - indirdep = WK_INDIRDEP(wk); - break; - } - if (indirdep == NULL && newindirdep) { - indirdep = newindirdep; - WORKLIST_INSERT(&bp->b_dep, &indirdep->ir_list); - newindirdep = NULL; - } - FREE_LOCK(&lk); - if (indirdep) { - if (newblk_lookup(ip->i_fs, aip->ai_newblkno, 0, - &newblk) == 0) - panic("setup_allocindir: lost block"); - ACQUIRE_LOCK(&lk); - if (newblk->nb_state == DEPCOMPLETE) { - aip->ai_state |= DEPCOMPLETE; - aip->ai_buf = NULL; - } else { - bmsafemap = newblk->nb_bmsafemap; - aip->ai_buf = bmsafemap->sm_buf; - LIST_REMOVE(newblk, nb_deps); - LIST_INSERT_HEAD(&bmsafemap->sm_allocindirhd, - aip, ai_deps); - } - LIST_REMOVE(newblk, nb_hash); - pool_put(&newblk_pool, newblk); - aip->ai_indirdep = indirdep; - /* - * Check to see if there is an existing dependency - * for this block. If there is, merge the old - * dependency into the new one. - */ - if (aip->ai_oldblkno == 0) - oldaip = NULL; - else - - LIST_FOREACH(oldaip, &indirdep->ir_deplisthd, ai_next) - if (oldaip->ai_offset == aip->ai_offset) - break; - freefrag = NULL; - if (oldaip != NULL) { - if (oldaip->ai_newblkno != aip->ai_oldblkno) { - FREE_LOCK(&lk); - panic("setup_allocindir_phase2: blkno"); - } - aip->ai_oldblkno = oldaip->ai_oldblkno; - freefrag = aip->ai_freefrag; - aip->ai_freefrag = oldaip->ai_freefrag; - oldaip->ai_freefrag = NULL; - free_allocindir(oldaip, NULL); - } - LIST_INSERT_HEAD(&indirdep->ir_deplisthd, aip, ai_next); - if (ip->i_ump->um_fstype == UM_UFS1) - ((int32_t *)indirdep->ir_savebp->b_data) - [aip->ai_offset] = aip->ai_oldblkno; - else - ((int64_t *)indirdep->ir_savebp->b_data) - [aip->ai_offset] = aip->ai_oldblkno; - FREE_LOCK(&lk); - if (freefrag != NULL) - handle_workitem_freefrag(freefrag); - } - if (newindirdep) { - if (indirdep->ir_savebp != NULL) - brelse(newindirdep->ir_savebp); - WORKITEM_FREE(newindirdep, D_INDIRDEP); - } - if (indirdep) - break; - newindirdep = pool_get(&indirdep_pool, PR_WAITOK); - newindirdep->ir_list.wk_type = D_INDIRDEP; - newindirdep->ir_state = ATTACHED; - if (ip->i_ump->um_fstype == UM_UFS1) - newindirdep->ir_state |= UFS1FMT; - LIST_INIT(&newindirdep->ir_deplisthd); - LIST_INIT(&newindirdep->ir_donehd); - if (bp->b_blkno == bp->b_lblkno) { - VOP_BMAP(bp->b_vp, bp->b_lblkno, NULL, &bp->b_blkno, - NULL); - } - newindirdep->ir_savebp = - getblk(ip->i_devvp, bp->b_blkno, bp->b_bcount, 0, INFSLP); -#if 0 - BUF_KERNPROC(newindirdep->ir_savebp); -#endif - memcpy(newindirdep->ir_savebp->b_data, bp->b_data, bp->b_bcount); - } -} - -/* - * Block de-allocation dependencies. - * - * When blocks are de-allocated, the on-disk pointers must be nullified before - * the blocks are made available for use by other files. (The true - * requirement is that old pointers must be nullified before new on-disk - * pointers are set. We chose this slightly more stringent requirement to - * reduce complexity.) Our implementation handles this dependency by updating - * the inode (or indirect block) appropriately but delaying the actual block - * de-allocation (i.e., freemap and free space count manipulation) until - * after the updated versions reach stable storage. After the disk is - * updated, the blocks can be safely de-allocated whenever it is convenient. - * This implementation handles only the common case of reducing a file's - * length to zero. Other cases are handled by the conventional synchronous - * write approach. - * - * The ffs implementation with which we worked double-checks - * the state of the block pointers and file size as it reduces - * a file's length. Some of this code is replicated here in our - * soft updates implementation. The freeblks->fb_chkcnt field is - * used to transfer a part of this information to the procedure - * that eventually de-allocates the blocks. - * - * This routine should be called from the routine that shortens - * a file's length, before the inode's size or block pointers - * are modified. It will save the block pointer information for - * later release and zero the inode so that the calling routine - * can release it. - */ -/* The inode whose length is to be reduced */ -/* The new length for the file */ -void -softdep_setup_freeblocks(struct inode *ip, off_t length) -{ - struct freeblks *freeblks; - struct inodedep *inodedep; - struct allocdirect *adp; - struct vnode *vp; - struct buf *bp; - struct fs *fs; - int i, delay, error; - - fs = ip->i_fs; - if (length != 0) - panic("softdep_setup_freeblocks: non-zero length"); - freeblks = pool_get(&freeblks_pool, PR_WAITOK | PR_ZERO); - freeblks->fb_list.wk_type = D_FREEBLKS; - freeblks->fb_state = ATTACHED; - freeblks->fb_uid = DIP(ip, uid); - freeblks->fb_previousinum = ip->i_number; - freeblks->fb_devvp = ip->i_devvp; - freeblks->fb_mnt = ITOV(ip)->v_mount; - freeblks->fb_oldsize = DIP(ip, size); - freeblks->fb_newsize = length; - freeblks->fb_chkcnt = DIP(ip, blocks); - - for (i = 0; i < NDADDR; i++) { - freeblks->fb_dblks[i] = DIP(ip, db[i]); - DIP_ASSIGN(ip, db[i], 0); - } - - for (i = 0; i < NIADDR; i++) { - freeblks->fb_iblks[i] = DIP(ip, ib[i]); - DIP_ASSIGN(ip, ib[i], 0); - } - - DIP_ASSIGN(ip, blocks, 0); - DIP_ASSIGN(ip, size, 0); - - /* - * Push the zero'ed inode to its disk buffer so that we are free - * to delete its dependencies below. Once the dependencies are gone - * the buffer can be safely released. - */ - if ((error = bread(ip->i_devvp, - fsbtodb(fs, ino_to_fsba(fs, ip->i_number)), - (int)fs->fs_bsize, &bp)) != 0) - softdep_error("softdep_setup_freeblocks", error); - - if (ip->i_ump->um_fstype == UM_UFS1) - *((struct ufs1_dinode *) bp->b_data + - ino_to_fsbo(fs, ip->i_number)) = *ip->i_din1; - else - *((struct ufs2_dinode *) bp->b_data + - ino_to_fsbo(fs, ip->i_number)) = *ip->i_din2; - - /* - * Find and eliminate any inode dependencies. - */ - ACQUIRE_LOCK(&lk); - (void) inodedep_lookup(fs, ip->i_number, DEPALLOC, &inodedep); - if ((inodedep->id_state & IOSTARTED) != 0) { - FREE_LOCK(&lk); - panic("softdep_setup_freeblocks: inode busy"); - } - /* - * Add the freeblks structure to the list of operations that - * must await the zero'ed inode being written to disk. If we - * still have a bitmap dependency (delay == 0), then the inode - * has never been written to disk, so we can process the - * freeblks below once we have deleted the dependencies. - */ - delay = (inodedep->id_state & DEPCOMPLETE); - if (delay) - WORKLIST_INSERT(&inodedep->id_bufwait, &freeblks->fb_list); - /* - * Because the file length has been truncated to zero, any - * pending block allocation dependency structures associated - * with this inode are obsolete and can simply be de-allocated. - * We must first merge the two dependency lists to get rid of - * any duplicate freefrag structures, then purge the merged list. - * If we still have a bitmap dependency, then the inode has never - * been written to disk, so we can free any fragments without delay. - */ - merge_inode_lists(inodedep); - while ((adp = TAILQ_FIRST(&inodedep->id_inoupdt)) != NULL) - free_allocdirect(&inodedep->id_inoupdt, adp, delay); - FREE_LOCK(&lk); - bdwrite(bp); - /* - * We must wait for any I/O in progress to finish so that - * all potential buffers on the dirty list will be visible. - * Once they are all there, walk the list and get rid of - * any dependencies. - */ - vp = ITOV(ip); - ACQUIRE_LOCK(&lk); - drain_output(vp, 1); - while ((bp = LIST_FIRST(&vp->v_dirtyblkhd))) { - if (getdirtybuf(bp, MNT_WAIT) <= 0) - break; - (void) inodedep_lookup(fs, ip->i_number, 0, &inodedep); - deallocate_dependencies(bp, inodedep); - bp->b_flags |= B_INVAL | B_NOCACHE; - FREE_LOCK(&lk); - brelse(bp); - ACQUIRE_LOCK(&lk); - } - if (inodedep_lookup(fs, ip->i_number, 0, &inodedep) != 0) - (void) free_inodedep(inodedep); - - if (delay) { - freeblks->fb_state |= DEPCOMPLETE; - /* - * If the inode with zeroed block pointers is now on disk we - * can start freeing blocks. Add freeblks to the worklist - * instead of calling handle_workitem_freeblocks() directly as - * it is more likely that additional IO is needed to complete - * the request than in the !delay case. - */ - if ((freeblks->fb_state & ALLCOMPLETE) == ALLCOMPLETE) - add_to_worklist(&freeblks->fb_list); - } - - FREE_LOCK(&lk); - /* - * If the inode has never been written to disk (delay == 0), - * then we can process the freeblks now that we have deleted - * the dependencies. - */ - if (!delay) - handle_workitem_freeblocks(freeblks); -} - -/* - * Reclaim any dependency structures from a buffer that is about to - * be reallocated to a new vnode. The buffer must be locked, thus, - * no I/O completion operations can occur while we are manipulating - * its associated dependencies. The mutex is held so that other I/O's - * associated with related dependencies do not occur. - */ -STATIC void -deallocate_dependencies(struct buf *bp, struct inodedep *inodedep) -{ - struct worklist *wk; - struct indirdep *indirdep; - struct allocindir *aip; - struct pagedep *pagedep; - struct dirrem *dirrem; - struct diradd *dap; - int i; - - while ((wk = LIST_FIRST(&bp->b_dep)) != NULL) { - switch (wk->wk_type) { - - case D_INDIRDEP: - indirdep = WK_INDIRDEP(wk); - /* - * None of the indirect pointers will ever be visible, - * so they can simply be tossed. GOINGAWAY ensures - * that allocated pointers will be saved in the buffer - * cache until they are freed. Note that they will - * only be able to be found by their physical address - * since the inode mapping the logical address will - * be gone. The save buffer used for the safe copy - * was allocated in setup_allocindir_phase2 using - * the physical address so it could be used for this - * purpose. Hence we swap the safe copy with the real - * copy, allowing the safe copy to be freed and holding - * on to the real copy for later use in indir_trunc. - */ - if (indirdep->ir_state & GOINGAWAY) { - FREE_LOCK(&lk); - panic("deallocate_dependencies: already gone"); - } - indirdep->ir_state |= GOINGAWAY; - while ((aip = LIST_FIRST(&indirdep->ir_deplisthd))) - free_allocindir(aip, inodedep); - if (bp->b_lblkno >= 0 || - bp->b_blkno != indirdep->ir_savebp->b_lblkno) { - FREE_LOCK(&lk); - panic("deallocate_dependencies: not indir"); - } - memcpy(indirdep->ir_savebp->b_data, bp->b_data, - bp->b_bcount); - WORKLIST_REMOVE(wk); - WORKLIST_INSERT(&indirdep->ir_savebp->b_dep, wk); - continue; - - case D_PAGEDEP: - pagedep = WK_PAGEDEP(wk); - /* - * None of the directory additions will ever be - * visible, so they can simply be tossed. - */ - for (i = 0; i < DAHASHSZ; i++) - while ((dap = - LIST_FIRST(&pagedep->pd_diraddhd[i]))) - free_diradd(dap); - while ((dap = LIST_FIRST(&pagedep->pd_pendinghd))) - free_diradd(dap); - /* - * Copy any directory remove dependencies to the list - * to be processed after the zero'ed inode is written. - * If the inode has already been written, then they - * can be dumped directly onto the work list. - */ - while ((dirrem = LIST_FIRST(&pagedep->pd_dirremhd))) { - LIST_REMOVE(dirrem, dm_next); - dirrem->dm_dirinum = pagedep->pd_ino; - if (inodedep == NULL || - (inodedep->id_state & ALLCOMPLETE) == - ALLCOMPLETE) - add_to_worklist(&dirrem->dm_list); - else - WORKLIST_INSERT(&inodedep->id_bufwait, - &dirrem->dm_list); - } - if ((pagedep->pd_state & NEWBLOCK) != 0) { - LIST_FOREACH(wk, &inodedep->id_bufwait, wk_list) - if (wk->wk_type == D_NEWDIRBLK && - WK_NEWDIRBLK(wk)->db_pagedep == - pagedep) - break; - if (wk != NULL) { - WORKLIST_REMOVE(wk); - free_newdirblk(WK_NEWDIRBLK(wk)); - } else { - FREE_LOCK(&lk); - panic("deallocate_dependencies: " - "lost pagedep"); - } - } - WORKLIST_REMOVE(&pagedep->pd_list); - LIST_REMOVE(pagedep, pd_hash); - WORKITEM_FREE(pagedep, D_PAGEDEP); - continue; - - case D_ALLOCINDIR: - free_allocindir(WK_ALLOCINDIR(wk), inodedep); - continue; - - case D_ALLOCDIRECT: - case D_INODEDEP: - FREE_LOCK(&lk); - panic("deallocate_dependencies: Unexpected type %s", - TYPENAME(wk->wk_type)); - /* NOTREACHED */ - - default: - FREE_LOCK(&lk); - panic("deallocate_dependencies: Unknown type %s", - TYPENAME(wk->wk_type)); - /* NOTREACHED */ - } - } -} - -/* - * Free an allocdirect. Generate a new freefrag work request if appropriate. - * This routine must be called with splbio interrupts blocked. - */ -STATIC void -free_allocdirect(struct allocdirectlst *adphead, struct allocdirect *adp, - int delay) -{ - struct newdirblk *newdirblk; - struct worklist *wk; - - splassert(IPL_BIO); - -#ifdef DEBUG - if (lk.lkt_held == -1) - panic("free_allocdirect: lock not held"); -#endif - if ((adp->ad_state & DEPCOMPLETE) == 0) - LIST_REMOVE(adp, ad_deps); - TAILQ_REMOVE(adphead, adp, ad_next); - if ((adp->ad_state & COMPLETE) == 0) - WORKLIST_REMOVE(&adp->ad_list); - if (adp->ad_freefrag != NULL) { - if (delay) - WORKLIST_INSERT(&adp->ad_inodedep->id_bufwait, - &adp->ad_freefrag->ff_list); - else - add_to_worklist(&adp->ad_freefrag->ff_list); - } - if ((wk = LIST_FIRST(&adp->ad_newdirblk)) != NULL) { - newdirblk = WK_NEWDIRBLK(wk); - WORKLIST_REMOVE(&newdirblk->db_list); - if (LIST_FIRST(&adp->ad_newdirblk) != NULL) - panic("free_allocdirect: extra newdirblk"); - if (delay) - WORKLIST_INSERT(&adp->ad_inodedep->id_bufwait, - &newdirblk->db_list); - else - free_newdirblk(newdirblk); - } - WORKITEM_FREE(adp, D_ALLOCDIRECT); -} - -/* - * Free a newdirblk. Clear the NEWBLOCK flag on its associated pagedep. - * This routine must be called with splbio interrupts blocked. - */ -void -free_newdirblk(struct newdirblk *newdirblk) -{ - struct pagedep *pagedep; - struct diradd *dap; - int i; - - splassert(IPL_BIO); - -#ifdef DEBUG - if (lk.lkt_held == -1) - panic("free_newdirblk: lock not held"); -#endif - /* - * If the pagedep is still linked onto the directory buffer - * dependency chain, then some of the entries on the - * pd_pendinghd list may not be committed to disk yet. In - * this case, we will simply clear the NEWBLOCK flag and - * let the pd_pendinghd list be processed when the pagedep - * is next written. If the pagedep is no longer on the buffer - * dependency chain, then all the entries on the pd_pending - * list are committed to disk and we can free them here. - */ - pagedep = newdirblk->db_pagedep; - pagedep->pd_state &= ~NEWBLOCK; - if ((pagedep->pd_state & ONWORKLIST) == 0) - while ((dap = LIST_FIRST(&pagedep->pd_pendinghd)) != NULL) - free_diradd(dap); - /* - * If no dependencies remain, the pagedep will be freed. - */ - for (i = 0; i < DAHASHSZ; i++) - if (LIST_FIRST(&pagedep->pd_diraddhd[i]) != NULL) - break; - if (i == DAHASHSZ && (pagedep->pd_state & ONWORKLIST) == 0) { - LIST_REMOVE(pagedep, pd_hash); - WORKITEM_FREE(pagedep, D_PAGEDEP); - } - WORKITEM_FREE(newdirblk, D_NEWDIRBLK); -} - -/* - * Prepare an inode to be freed. The actual free operation is not - * done until the zero'ed inode has been written to disk. - */ -void -softdep_freefile(struct vnode *pvp, ufsino_t ino, mode_t mode) -{ - struct inode *ip = VTOI(pvp); - struct inodedep *inodedep; - struct freefile *freefile; - - /* - * This sets up the inode de-allocation dependency. - */ - freefile = pool_get(&freefile_pool, PR_WAITOK); - freefile->fx_list.wk_type = D_FREEFILE; - freefile->fx_list.wk_state = 0; - freefile->fx_mode = mode; - freefile->fx_oldinum = ino; - freefile->fx_devvp = ip->i_devvp; - freefile->fx_mnt = ITOV(ip)->v_mount; - - /* - * If the inodedep does not exist, then the zero'ed inode has - * been written to disk. If the allocated inode has never been - * written to disk, then the on-disk inode is zero'ed. In either - * case we can free the file immediately. - */ - ACQUIRE_LOCK(&lk); - if (inodedep_lookup(ip->i_fs, ino, 0, &inodedep) == 0 || - check_inode_unwritten(inodedep)) { - FREE_LOCK(&lk); - handle_workitem_freefile(freefile); - return; - } - WORKLIST_INSERT(&inodedep->id_inowait, &freefile->fx_list); - FREE_LOCK(&lk); -} - -/* - * Check to see if an inode has never been written to disk. If - * so free the inodedep and return success, otherwise return failure. - * This routine must be called with splbio interrupts blocked. - * - * If we still have a bitmap dependency, then the inode has never - * been written to disk. Drop the dependency as it is no longer - * necessary since the inode is being deallocated. We set the - * ALLCOMPLETE flags since the bitmap now properly shows that the - * inode is not allocated. Even if the inode is actively being - * written, it has been rolled back to its zero'ed state, so we - * are ensured that a zero inode is what is on the disk. For short - * lived files, this change will usually result in removing all the - * dependencies from the inode so that it can be freed immediately. - */ -STATIC int -check_inode_unwritten(struct inodedep *inodedep) -{ - splassert(IPL_BIO); - - if ((inodedep->id_state & DEPCOMPLETE) != 0 || - LIST_FIRST(&inodedep->id_pendinghd) != NULL || - LIST_FIRST(&inodedep->id_bufwait) != NULL || - LIST_FIRST(&inodedep->id_inowait) != NULL || - TAILQ_FIRST(&inodedep->id_inoupdt) != NULL || - TAILQ_FIRST(&inodedep->id_newinoupdt) != NULL || - inodedep->id_nlinkdelta != 0) - return (0); - inodedep->id_state |= ALLCOMPLETE; - LIST_REMOVE(inodedep, id_deps); - inodedep->id_buf = NULL; - if (inodedep->id_state & ONWORKLIST) - WORKLIST_REMOVE(&inodedep->id_list); - if (inodedep->id_savedino1 != NULL) { - free(inodedep->id_savedino1, M_INODEDEP, inodedep->id_unsize); - inodedep->id_savedino1 = NULL; - } - if (free_inodedep(inodedep) == 0) { - FREE_LOCK(&lk); - panic("check_inode_unwritten: busy inode"); - } - return (1); -} - -/* - * Try to free an inodedep structure. Return 1 if it could be freed. - */ -STATIC int -free_inodedep(struct inodedep *inodedep) -{ - - if ((inodedep->id_state & ONWORKLIST) != 0 || - (inodedep->id_state & ALLCOMPLETE) != ALLCOMPLETE || - LIST_FIRST(&inodedep->id_pendinghd) != NULL || - LIST_FIRST(&inodedep->id_bufwait) != NULL || - LIST_FIRST(&inodedep->id_inowait) != NULL || - TAILQ_FIRST(&inodedep->id_inoupdt) != NULL || - TAILQ_FIRST(&inodedep->id_newinoupdt) != NULL || - inodedep->id_nlinkdelta != 0 || inodedep->id_savedino1 != NULL) - return (0); - LIST_REMOVE(inodedep, id_hash); - WORKITEM_FREE(inodedep, D_INODEDEP); - num_inodedep -= 1; - return (1); -} - -/* - * This workitem routine performs the block de-allocation. - * The workitem is added to the pending list after the updated - * inode block has been written to disk. As mentioned above, - * checks regarding the number of blocks de-allocated (compared - * to the number of blocks allocated for the file) are also - * performed in this function. - */ -STATIC void -handle_workitem_freeblocks(struct freeblks *freeblks) -{ - struct inode tip; - daddr_t bn; - union { - struct ufs1_dinode di1; - struct ufs2_dinode di2; - } di; - struct fs *fs; - int i, level, bsize; - long nblocks, blocksreleased = 0; - int error, allerror = 0; - daddr_t baselbns[NIADDR], tmpval; - - if (VFSTOUFS(freeblks->fb_mnt)->um_fstype == UM_UFS1) - tip.i_din1 = &di.di1; - else - tip.i_din2 = &di.di2; - - tip.i_fs = fs = VFSTOUFS(freeblks->fb_mnt)->um_fs; - tip.i_number = freeblks->fb_previousinum; - tip.i_ump = VFSTOUFS(freeblks->fb_mnt); - tip.i_dev = freeblks->fb_devvp->v_rdev; - DIP_ASSIGN(&tip, size, freeblks->fb_oldsize); - DIP_ASSIGN(&tip, uid, freeblks->fb_uid); - tip.i_vnode = NULL; - tmpval = 1; - baselbns[0] = NDADDR; - for (i = 1; i < NIADDR; i++) { - tmpval *= NINDIR(fs); - baselbns[i] = baselbns[i - 1] + tmpval; - } - nblocks = btodb(fs->fs_bsize); - blocksreleased = 0; - /* - * Indirect blocks first. - */ - for (level = (NIADDR - 1); level >= 0; level--) { - if ((bn = freeblks->fb_iblks[level]) == 0) - continue; - if ((error = indir_trunc(&tip, fsbtodb(fs, bn), level, - baselbns[level], &blocksreleased)) != 0) - allerror = error; - ffs_blkfree(&tip, bn, fs->fs_bsize); - blocksreleased += nblocks; - } - /* - * All direct blocks or frags. - */ - for (i = (NDADDR - 1); i >= 0; i--) { - if ((bn = freeblks->fb_dblks[i]) == 0) - continue; - bsize = blksize(fs, &tip, i); - ffs_blkfree(&tip, bn, bsize); - blocksreleased += btodb(bsize); - } - -#ifdef DIAGNOSTIC - if (freeblks->fb_chkcnt != blocksreleased) - printf("handle_workitem_freeblocks: block count\n"); - if (allerror) - softdep_error("handle_workitem_freeblks", allerror); -#endif /* DIAGNOSTIC */ - WORKITEM_FREE(freeblks, D_FREEBLKS); -} - -/* - * Release blocks associated with the inode ip and stored in the indirect - * block dbn. If level is greater than SINGLE, the block is an indirect block - * and recursive calls to indirtrunc must be used to cleanse other indirect - * blocks. - */ -STATIC int -indir_trunc(struct inode *ip, daddr_t dbn, int level, daddr_t lbn, - long *countp) -{ - struct buf *bp; - int32_t *bap1 = NULL; - int64_t nb, *bap2 = NULL; - struct fs *fs; - struct worklist *wk; - struct indirdep *indirdep; - int i, lbnadd, nblocks, ufs1fmt; - int error, allerror = 0; - - fs = ip->i_fs; - lbnadd = 1; - for (i = level; i > 0; i--) - lbnadd *= NINDIR(fs); - /* - * Get buffer of block pointers to be freed. This routine is not - * called until the zero'ed inode has been written, so it is safe - * to free blocks as they are encountered. Because the inode has - * been zero'ed, calls to bmap on these blocks will fail. So, we - * have to use the on-disk address and the block device for the - * filesystem to look them up. If the file was deleted before its - * indirect blocks were all written to disk, the routine that set - * us up (deallocate_dependencies) will have arranged to leave - * a complete copy of the indirect block in memory for our use. - * Otherwise we have to read the blocks in from the disk. - */ - ACQUIRE_LOCK(&lk); - if ((bp = incore(ip->i_devvp, dbn)) != NULL && - (wk = LIST_FIRST(&bp->b_dep)) != NULL) { - if (wk->wk_type != D_INDIRDEP || - (indirdep = WK_INDIRDEP(wk))->ir_savebp != bp || - (indirdep->ir_state & GOINGAWAY) == 0) { - FREE_LOCK(&lk); - panic("indir_trunc: lost indirdep"); - } - WORKLIST_REMOVE(wk); - WORKITEM_FREE(indirdep, D_INDIRDEP); - if (LIST_FIRST(&bp->b_dep) != NULL) { - FREE_LOCK(&lk); - panic("indir_trunc: dangling dep"); - } - FREE_LOCK(&lk); - } else { - FREE_LOCK(&lk); - error = bread(ip->i_devvp, dbn, (int)fs->fs_bsize, &bp); - if (error) - return (error); - } - /* - * Recursively free indirect blocks. - */ - if (ip->i_ump->um_fstype == UM_UFS1) { - ufs1fmt = 1; - bap1 = (int32_t *)bp->b_data; - } else { - ufs1fmt = 0; - bap2 = (int64_t *)bp->b_data; - } - nblocks = btodb(fs->fs_bsize); - for (i = NINDIR(fs) - 1; i >= 0; i--) { - if (ufs1fmt) - nb = bap1[i]; - else - nb = bap2[i]; - if (nb == 0) - continue; - if (level != 0) { - if ((error = indir_trunc(ip, fsbtodb(fs, nb), - level - 1, lbn + (i * lbnadd), countp)) != 0) - allerror = error; - } - ffs_blkfree(ip, nb, fs->fs_bsize); - *countp += nblocks; - } - bp->b_flags |= B_INVAL | B_NOCACHE; - brelse(bp); - return (allerror); -} - -/* - * Free an allocindir. - * This routine must be called with splbio interrupts blocked. - */ -STATIC void -free_allocindir(struct allocindir *aip, struct inodedep *inodedep) -{ - struct freefrag *freefrag; - - splassert(IPL_BIO); - -#ifdef DEBUG - if (lk.lkt_held == -1) - panic("free_allocindir: lock not held"); -#endif - if ((aip->ai_state & DEPCOMPLETE) == 0) - LIST_REMOVE(aip, ai_deps); - if (aip->ai_state & ONWORKLIST) - WORKLIST_REMOVE(&aip->ai_list); - LIST_REMOVE(aip, ai_next); - if ((freefrag = aip->ai_freefrag) != NULL) { - if (inodedep == NULL) - add_to_worklist(&freefrag->ff_list); - else - WORKLIST_INSERT(&inodedep->id_bufwait, - &freefrag->ff_list); - } - WORKITEM_FREE(aip, D_ALLOCINDIR); -} - -/* - * Directory entry addition dependencies. - * - * When adding a new directory entry, the inode (with its incremented link - * count) must be written to disk before the directory entry's pointer to it. - * Also, if the inode is newly allocated, the corresponding freemap must be - * updated (on disk) before the directory entry's pointer. These requirements - * are met via undo/redo on the directory entry's pointer, which consists - * simply of the inode number. - * - * As directory entries are added and deleted, the free space within a - * directory block can become fragmented. The ufs file system will compact - * a fragmented directory block to make space for a new entry. When this - * occurs, the offsets of previously added entries change. Any "diradd" - * dependency structures corresponding to these entries must be updated with - * the new offsets. - */ - -/* - * This routine is called after the in-memory inode's link - * count has been incremented, but before the directory entry's - * pointer to the inode has been set. - */ -/* buffer containing directory block */ -/* inode for directory */ -/* offset of new entry in directory */ -/* inode referenced by new directory entry */ -/* non-NULL => contents of new mkdir */ -/* entry is in a newly allocated block */ -int -softdep_setup_directory_add(struct buf *bp, struct inode *dp, off_t diroffset, - long newinum, struct buf *newdirbp, int isnewblk) -{ - int offset; /* offset of new entry within directory block */ - daddr_t lbn; /* block in directory containing new entry */ - struct fs *fs; - struct diradd *dap; - struct allocdirect *adp; - struct pagedep *pagedep; - struct inodedep *inodedep; - struct newdirblk *newdirblk = NULL; - struct mkdir *mkdir1, *mkdir2; - - - fs = dp->i_fs; - lbn = lblkno(fs, diroffset); - offset = blkoff(fs, diroffset); - dap = pool_get(&diradd_pool, PR_WAITOK | PR_ZERO); - dap->da_list.wk_type = D_DIRADD; - dap->da_offset = offset; - dap->da_newinum = newinum; - dap->da_state = ATTACHED; - if (isnewblk && lbn < NDADDR && fragoff(fs, diroffset) == 0) { - newdirblk = pool_get(&newdirblk_pool, PR_WAITOK); - newdirblk->db_list.wk_type = D_NEWDIRBLK; - newdirblk->db_state = 0; - } - if (newdirbp == NULL) { - dap->da_state |= DEPCOMPLETE; - ACQUIRE_LOCK(&lk); - } else { - dap->da_state |= MKDIR_BODY | MKDIR_PARENT; - mkdir1 = pool_get(&mkdir_pool, PR_WAITOK); - mkdir1->md_list.wk_type = D_MKDIR; - mkdir1->md_state = MKDIR_BODY; - mkdir1->md_diradd = dap; - mkdir2 = pool_get(&mkdir_pool, PR_WAITOK); - mkdir2->md_list.wk_type = D_MKDIR; - mkdir2->md_state = MKDIR_PARENT; - mkdir2->md_diradd = dap; - /* - * Dependency on "." and ".." being written to disk. - */ - mkdir1->md_buf = newdirbp; - ACQUIRE_LOCK(&lk); - LIST_INSERT_HEAD(&mkdirlisthd, mkdir1, md_mkdirs); - WORKLIST_INSERT(&newdirbp->b_dep, &mkdir1->md_list); - FREE_LOCK(&lk); - bdwrite(newdirbp); - /* - * Dependency on link count increase for parent directory - */ - ACQUIRE_LOCK(&lk); - if (inodedep_lookup(fs, dp->i_number, 0, &inodedep) == 0 - || (inodedep->id_state & ALLCOMPLETE) == ALLCOMPLETE) { - dap->da_state &= ~MKDIR_PARENT; - WORKITEM_FREE(mkdir2, D_MKDIR); - } else { - LIST_INSERT_HEAD(&mkdirlisthd, mkdir2, md_mkdirs); - WORKLIST_INSERT(&inodedep->id_bufwait,&mkdir2->md_list); - } - } - /* - * Link into parent directory pagedep to await its being written. - */ - if (pagedep_lookup(dp, lbn, DEPALLOC, &pagedep) == 0) - WORKLIST_INSERT(&bp->b_dep, &pagedep->pd_list); - dap->da_pagedep = pagedep; - LIST_INSERT_HEAD(&pagedep->pd_diraddhd[DIRADDHASH(offset)], dap, - da_pdlist); - /* - * Link into its inodedep. Put it on the id_bufwait list if the inode - * is not yet written. If it is written, do the post-inode write - * processing to put it on the id_pendinghd list. - */ - (void) inodedep_lookup(fs, newinum, DEPALLOC, &inodedep); - if ((inodedep->id_state & ALLCOMPLETE) == ALLCOMPLETE) - diradd_inode_written(dap, inodedep); - else - WORKLIST_INSERT(&inodedep->id_bufwait, &dap->da_list); - if (isnewblk) { - /* - * Directories growing into indirect blocks are rare - * enough and the frequency of new block allocation - * in those cases even more rare, that we choose not - * to bother tracking them. Rather we simply force the - * new directory entry to disk. - */ - if (lbn >= NDADDR) { - FREE_LOCK(&lk); - /* - * We only have a new allocation when at the - * beginning of a new block, not when we are - * expanding into an existing block. - */ - if (blkoff(fs, diroffset) == 0) - return (1); - return (0); - } - /* - * We only have a new allocation when at the beginning - * of a new fragment, not when we are expanding into an - * existing fragment. Also, there is nothing to do if we - * are already tracking this block. - */ - if (fragoff(fs, diroffset) != 0) { - FREE_LOCK(&lk); - return (0); - } - - if ((pagedep->pd_state & NEWBLOCK) != 0) { - WORKITEM_FREE(newdirblk, D_NEWDIRBLK); - FREE_LOCK(&lk); - return (0); - } - /* - * Find our associated allocdirect and have it track us. - */ - if (inodedep_lookup(fs, dp->i_number, 0, &inodedep) == 0) - panic("softdep_setup_directory_add: lost inodedep"); - adp = TAILQ_LAST(&inodedep->id_newinoupdt, allocdirectlst); - if (adp == NULL || adp->ad_lbn != lbn) { - FREE_LOCK(&lk); - panic("softdep_setup_directory_add: lost entry"); - } - pagedep->pd_state |= NEWBLOCK; - newdirblk->db_pagedep = pagedep; - WORKLIST_INSERT(&adp->ad_newdirblk, &newdirblk->db_list); - } - FREE_LOCK(&lk); - return (0); -} - -/* - * This procedure is called to change the offset of a directory - * entry when compacting a directory block which must be owned - * exclusively by the caller. Note that the actual entry movement - * must be done in this procedure to ensure that no I/O completions - * occur while the move is in progress. - */ -/* inode for directory */ -/* address of dp->i_offset */ -/* address of old directory location */ -/* address of new directory location */ -/* size of directory entry */ -void -softdep_change_directoryentry_offset(struct inode *dp, caddr_t base, - caddr_t oldloc, caddr_t newloc, int entrysize) -{ - int offset, oldoffset, newoffset; - struct pagedep *pagedep; - struct diradd *dap; - daddr_t lbn; - - ACQUIRE_LOCK(&lk); - lbn = lblkno(dp->i_fs, dp->i_offset); - offset = blkoff(dp->i_fs, dp->i_offset); - if (pagedep_lookup(dp, lbn, 0, &pagedep) == 0) - goto done; - oldoffset = offset + (oldloc - base); - newoffset = offset + (newloc - base); - - LIST_FOREACH(dap, &pagedep->pd_diraddhd[DIRADDHASH(oldoffset)], da_pdlist) { - if (dap->da_offset != oldoffset) - continue; - dap->da_offset = newoffset; - if (DIRADDHASH(newoffset) == DIRADDHASH(oldoffset)) - break; - LIST_REMOVE(dap, da_pdlist); - LIST_INSERT_HEAD(&pagedep->pd_diraddhd[DIRADDHASH(newoffset)], - dap, da_pdlist); - break; - } - if (dap == NULL) { - - LIST_FOREACH(dap, &pagedep->pd_pendinghd, da_pdlist) { - if (dap->da_offset == oldoffset) { - dap->da_offset = newoffset; - break; - } - } - } -done: - memmove(newloc, oldloc, entrysize); - FREE_LOCK(&lk); -} - -/* - * Free a diradd dependency structure. This routine must be called - * with splbio interrupts blocked. - */ -STATIC void -free_diradd(struct diradd *dap) -{ - struct dirrem *dirrem; - struct pagedep *pagedep; - struct inodedep *inodedep; - struct mkdir *mkdir, *nextmd; - - splassert(IPL_BIO); - -#ifdef DEBUG - if (lk.lkt_held == -1) - panic("free_diradd: lock not held"); -#endif - WORKLIST_REMOVE(&dap->da_list); - LIST_REMOVE(dap, da_pdlist); - if ((dap->da_state & DIRCHG) == 0) { - pagedep = dap->da_pagedep; - } else { - dirrem = dap->da_previous; - pagedep = dirrem->dm_pagedep; - dirrem->dm_dirinum = pagedep->pd_ino; - add_to_worklist(&dirrem->dm_list); - } - if (inodedep_lookup(VFSTOUFS(pagedep->pd_mnt)->um_fs, dap->da_newinum, - 0, &inodedep) != 0) - (void) free_inodedep(inodedep); - if ((dap->da_state & (MKDIR_PARENT | MKDIR_BODY)) != 0) { - for (mkdir = LIST_FIRST(&mkdirlisthd); mkdir; mkdir = nextmd) { - nextmd = LIST_NEXT(mkdir, md_mkdirs); - if (mkdir->md_diradd != dap) - continue; - dap->da_state &= ~mkdir->md_state; - WORKLIST_REMOVE(&mkdir->md_list); - LIST_REMOVE(mkdir, md_mkdirs); - WORKITEM_FREE(mkdir, D_MKDIR); - } - if ((dap->da_state & (MKDIR_PARENT | MKDIR_BODY)) != 0) { - FREE_LOCK(&lk); - panic("free_diradd: unfound ref"); - } - } - WORKITEM_FREE(dap, D_DIRADD); -} - -/* - * Directory entry removal dependencies. - * - * When removing a directory entry, the entry's inode pointer must be - * zero'ed on disk before the corresponding inode's link count is decremented - * (possibly freeing the inode for re-use). This dependency is handled by - * updating the directory entry but delaying the inode count reduction until - * after the directory block has been written to disk. After this point, the - * inode count can be decremented whenever it is convenient. - */ - -/* - * This routine should be called immediately after removing - * a directory entry. The inode's link count should not be - * decremented by the calling procedure -- the soft updates - * code will do this task when it is safe. - */ -/* buffer containing directory block */ -/* inode for the directory being modified */ -/* inode for directory entry being removed */ -/* indicates if doing RMDIR */ -void -softdep_setup_remove(struct buf *bp, struct inode *dp, struct inode *ip, - int isrmdir) -{ - struct dirrem *dirrem, *prevdirrem; - - /* - * Allocate a new dirrem if appropriate and ACQUIRE_LOCK. - */ - dirrem = newdirrem(bp, dp, ip, isrmdir, &prevdirrem); - - /* - * If the COMPLETE flag is clear, then there were no active - * entries and we want to roll back to a zeroed entry until - * the new inode is committed to disk. If the COMPLETE flag is - * set then we have deleted an entry that never made it to - * disk. If the entry we deleted resulted from a name change, - * then the old name still resides on disk. We cannot delete - * its inode (returned to us in prevdirrem) until the zeroed - * directory entry gets to disk. The new inode has never been - * referenced on the disk, so can be deleted immediately. - */ - if ((dirrem->dm_state & COMPLETE) == 0) { - LIST_INSERT_HEAD(&dirrem->dm_pagedep->pd_dirremhd, dirrem, - dm_next); - FREE_LOCK(&lk); - } else { - if (prevdirrem != NULL) - LIST_INSERT_HEAD(&dirrem->dm_pagedep->pd_dirremhd, - prevdirrem, dm_next); - dirrem->dm_dirinum = dirrem->dm_pagedep->pd_ino; - FREE_LOCK(&lk); - handle_workitem_remove(dirrem); - } -} - -STATIC long num_dirrem; /* number of dirrem allocated */ -/* - * Allocate a new dirrem if appropriate and return it along with - * its associated pagedep. Called without a lock, returns with lock. - */ -/* buffer containing directory block */ -/* inode for the directory being modified */ -/* inode for directory entry being removed */ -/* indicates if doing RMDIR */ -/* previously referenced inode, if any */ -STATIC struct dirrem * -newdirrem(struct buf *bp, struct inode *dp, struct inode *ip, int isrmdir, - struct dirrem **prevdirremp) -{ - int offset; - daddr_t lbn; - struct diradd *dap; - struct dirrem *dirrem; - struct pagedep *pagedep; - - /* - * Whiteouts have no deletion dependencies. - */ - if (ip == NULL) - panic("newdirrem: whiteout"); - /* - * If we are over our limit, try to improve the situation. - * Limiting the number of dirrem structures will also limit - * the number of freefile and freeblks structures. - */ - if (num_dirrem > max_softdeps / 2) - (void) request_cleanup(FLUSH_REMOVE, 0); - num_dirrem += 1; - dirrem = pool_get(&dirrem_pool, PR_WAITOK | PR_ZERO); - dirrem->dm_list.wk_type = D_DIRREM; - dirrem->dm_state = isrmdir ? RMDIR : 0; - dirrem->dm_mnt = ITOV(ip)->v_mount; - dirrem->dm_oldinum = ip->i_number; - *prevdirremp = NULL; - - ACQUIRE_LOCK(&lk); - lbn = lblkno(dp->i_fs, dp->i_offset); - offset = blkoff(dp->i_fs, dp->i_offset); - if (pagedep_lookup(dp, lbn, DEPALLOC, &pagedep) == 0) - WORKLIST_INSERT(&bp->b_dep, &pagedep->pd_list); - dirrem->dm_pagedep = pagedep; - /* - * Check for a diradd dependency for the same directory entry. - * If present, then both dependencies become obsolete and can - * be de-allocated. Check for an entry on both the pd_dirraddhd - * list and the pd_pendinghd list. - */ - - LIST_FOREACH(dap, &pagedep->pd_diraddhd[DIRADDHASH(offset)], da_pdlist) - if (dap->da_offset == offset) - break; - if (dap == NULL) { - - LIST_FOREACH(dap, &pagedep->pd_pendinghd, da_pdlist) - if (dap->da_offset == offset) - break; - if (dap == NULL) - return (dirrem); - } - /* - * Must be ATTACHED at this point. - */ - if ((dap->da_state & ATTACHED) == 0) { - FREE_LOCK(&lk); - panic("newdirrem: not ATTACHED"); - } - if (dap->da_newinum != ip->i_number) { - FREE_LOCK(&lk); - panic("newdirrem: inum %u should be %u", - ip->i_number, dap->da_newinum); - } - /* - * If we are deleting a changed name that never made it to disk, - * then return the dirrem describing the previous inode (which - * represents the inode currently referenced from this entry on disk). - */ - if ((dap->da_state & DIRCHG) != 0) { - *prevdirremp = dap->da_previous; - dap->da_state &= ~DIRCHG; - dap->da_pagedep = pagedep; - } - /* - * We are deleting an entry that never made it to disk. - * Mark it COMPLETE so we can delete its inode immediately. - */ - dirrem->dm_state |= COMPLETE; - free_diradd(dap); - return (dirrem); -} - -/* - * Directory entry change dependencies. - * - * Changing an existing directory entry requires that an add operation - * be completed first followed by a deletion. The semantics for the addition - * are identical to the description of adding a new entry above except - * that the rollback is to the old inode number rather than zero. Once - * the addition dependency is completed, the removal is done as described - * in the removal routine above. - */ - -/* - * This routine should be called immediately after changing - * a directory entry. The inode's link count should not be - * decremented by the calling procedure -- the soft updates - * code will perform this task when it is safe. - */ -/* buffer containing directory block */ -/* inode for the directory being modified */ -/* inode for directory entry being removed */ -/* new inode number for changed entry */ -/* indicates if doing RMDIR */ -void -softdep_setup_directory_change(struct buf *bp, struct inode *dp, - struct inode *ip, long newinum, int isrmdir) -{ - int offset; - struct diradd *dap; - struct dirrem *dirrem, *prevdirrem; - struct pagedep *pagedep; - struct inodedep *inodedep; - - offset = blkoff(dp->i_fs, dp->i_offset); - dap = pool_get(&diradd_pool, PR_WAITOK | PR_ZERO); - dap->da_list.wk_type = D_DIRADD; - dap->da_state = DIRCHG | ATTACHED | DEPCOMPLETE; - dap->da_offset = offset; - dap->da_newinum = newinum; - - /* - * Allocate a new dirrem and ACQUIRE_LOCK. - */ - dirrem = newdirrem(bp, dp, ip, isrmdir, &prevdirrem); - pagedep = dirrem->dm_pagedep; - /* - * The possible values for isrmdir: - * 0 - non-directory file rename - * 1 - directory rename within same directory - * inum - directory rename to new directory of given inode number - * When renaming to a new directory, we are both deleting and - * creating a new directory entry, so the link count on the new - * directory should not change. Thus we do not need the followup - * dirrem which is usually done in handle_workitem_remove. We set - * the DIRCHG flag to tell handle_workitem_remove to skip the - * followup dirrem. - */ - if (isrmdir > 1) - dirrem->dm_state |= DIRCHG; - - /* - * If the COMPLETE flag is clear, then there were no active - * entries and we want to roll back to the previous inode until - * the new inode is committed to disk. If the COMPLETE flag is - * set, then we have deleted an entry that never made it to disk. - * If the entry we deleted resulted from a name change, then the old - * inode reference still resides on disk. Any rollback that we do - * needs to be to that old inode (returned to us in prevdirrem). If - * the entry we deleted resulted from a create, then there is - * no entry on the disk, so we want to roll back to zero rather - * than the uncommitted inode. In either of the COMPLETE cases we - * want to immediately free the unwritten and unreferenced inode. - */ - if ((dirrem->dm_state & COMPLETE) == 0) { - dap->da_previous = dirrem; - } else { - if (prevdirrem != NULL) { - dap->da_previous = prevdirrem; - } else { - dap->da_state &= ~DIRCHG; - dap->da_pagedep = pagedep; - } - dirrem->dm_dirinum = pagedep->pd_ino; - add_to_worklist(&dirrem->dm_list); - } - /* - * Link into its inodedep. Put it on the id_bufwait list if the inode - * is not yet written. If it is written, do the post-inode write - * processing to put it on the id_pendinghd list. - */ - if (inodedep_lookup(dp->i_fs, newinum, DEPALLOC, &inodedep) == 0 || - (inodedep->id_state & ALLCOMPLETE) == ALLCOMPLETE) { - dap->da_state |= COMPLETE; - LIST_INSERT_HEAD(&pagedep->pd_pendinghd, dap, da_pdlist); - WORKLIST_INSERT(&inodedep->id_pendinghd, &dap->da_list); - } else { - LIST_INSERT_HEAD(&pagedep->pd_diraddhd[DIRADDHASH(offset)], - dap, da_pdlist); - WORKLIST_INSERT(&inodedep->id_bufwait, &dap->da_list); - } - FREE_LOCK(&lk); -} - -/* - * Called whenever the link count on an inode is changed. - * It creates an inode dependency so that the new reference(s) - * to the inode cannot be committed to disk until the updated - * inode has been written. - */ -/* the inode with the increased link count */ -/* do background work or not */ -void -softdep_change_linkcnt(struct inode *ip, int nodelay) -{ - struct inodedep *inodedep; - int flags; - - /* - * If requested, do not allow background work to happen. - */ - flags = DEPALLOC; - if (nodelay) - flags |= NODELAY; - - ACQUIRE_LOCK(&lk); - - (void) inodedep_lookup(ip->i_fs, ip->i_number, flags, &inodedep); - if (DIP(ip, nlink) < ip->i_effnlink) { - FREE_LOCK(&lk); - panic("softdep_change_linkcnt: bad delta"); - } - - inodedep->id_nlinkdelta = DIP(ip, nlink) - ip->i_effnlink; - - FREE_LOCK(&lk); -} - -/* - * This workitem decrements the inode's link count. - * If the link count reaches zero, the file is removed. - */ -STATIC void -handle_workitem_remove(struct dirrem *dirrem) -{ - struct proc *p = CURPROC; /* XXX */ - struct inodedep *inodedep; - struct vnode *vp; - struct inode *ip; - ufsino_t oldinum; - int error; - - if ((error = VFS_VGET(dirrem->dm_mnt, dirrem->dm_oldinum, &vp)) != 0) { - softdep_error("handle_workitem_remove: vget", error); - return; - } - ip = VTOI(vp); - ACQUIRE_LOCK(&lk); - if ((inodedep_lookup(ip->i_fs, dirrem->dm_oldinum, 0, &inodedep)) - == 0) { - FREE_LOCK(&lk); - panic("handle_workitem_remove: lost inodedep"); - } - /* - * Normal file deletion. - */ - if ((dirrem->dm_state & RMDIR) == 0) { - DIP_ADD(ip, nlink, -1); - ip->i_flag |= IN_CHANGE; - if (DIP(ip, nlink) < ip->i_effnlink) { - FREE_LOCK(&lk); - panic("handle_workitem_remove: bad file delta"); - } - inodedep->id_nlinkdelta = DIP(ip, nlink) - ip->i_effnlink; - FREE_LOCK(&lk); - vput(vp); - num_dirrem -= 1; - WORKITEM_FREE(dirrem, D_DIRREM); - return; - } - /* - * Directory deletion. Decrement reference count for both the - * just deleted parent directory entry and the reference for ".". - * Next truncate the directory to length zero. When the - * truncation completes, arrange to have the reference count on - * the parent decremented to account for the loss of "..". - */ - DIP_ADD(ip, nlink, -2); - ip->i_flag |= IN_CHANGE; - if (DIP(ip, nlink) < ip->i_effnlink) - panic("handle_workitem_remove: bad dir delta"); - inodedep->id_nlinkdelta = DIP(ip, nlink) - ip->i_effnlink; - FREE_LOCK(&lk); - if ((error = UFS_TRUNCATE(ip, (off_t)0, 0, p->p_ucred)) != 0) - softdep_error("handle_workitem_remove: truncate", error); - /* - * Rename a directory to a new parent. Since, we are both deleting - * and creating a new directory entry, the link count on the new - * directory should not change. Thus we skip the followup dirrem. - */ - if (dirrem->dm_state & DIRCHG) { - vput(vp); - num_dirrem -= 1; - WORKITEM_FREE(dirrem, D_DIRREM); - return; - } - /* - * If the inodedep does not exist, then the zero'ed inode has - * been written to disk. If the allocated inode has never been - * written to disk, then the on-disk inode is zero'ed. In either - * case we can remove the file immediately. - */ - ACQUIRE_LOCK(&lk); - dirrem->dm_state = 0; - oldinum = dirrem->dm_oldinum; - dirrem->dm_oldinum = dirrem->dm_dirinum; - if (inodedep_lookup(ip->i_fs, oldinum, 0, &inodedep) == 0 || - check_inode_unwritten(inodedep)) { - FREE_LOCK(&lk); - vput(vp); - handle_workitem_remove(dirrem); - return; - } - WORKLIST_INSERT(&inodedep->id_inowait, &dirrem->dm_list); - FREE_LOCK(&lk); - ip->i_flag |= IN_CHANGE; - UFS_UPDATE(VTOI(vp), 0); - vput(vp); -} - -/* - * Inode de-allocation dependencies. - * - * When an inode's link count is reduced to zero, it can be de-allocated. We - * found it convenient to postpone de-allocation until after the inode is - * written to disk with its new link count (zero). At this point, all of the - * on-disk inode's block pointers are nullified and, with careful dependency - * list ordering, all dependencies related to the inode will be satisfied and - * the corresponding dependency structures de-allocated. So, if/when the - * inode is reused, there will be no mixing of old dependencies with new - * ones. This artificial dependency is set up by the block de-allocation - * procedure above (softdep_setup_freeblocks) and completed by the - * following procedure. - */ -STATIC void -handle_workitem_freefile(struct freefile *freefile) -{ - struct fs *fs; - struct vnode vp; - struct inode tip; -#ifdef DEBUG - struct inodedep *idp; -#endif - int error; - - fs = VFSTOUFS(freefile->fx_mnt)->um_fs; -#ifdef DEBUG - ACQUIRE_LOCK(&lk); - error = inodedep_lookup(fs, freefile->fx_oldinum, 0, &idp); - FREE_LOCK(&lk); - if (error) - panic("handle_workitem_freefile: inodedep survived"); -#endif - tip.i_ump = VFSTOUFS(freefile->fx_mnt); - tip.i_dev = freefile->fx_devvp->v_rdev; - tip.i_fs = fs; - tip.i_vnode = &vp; - vp.v_data = &tip; - - if ((error = ffs_freefile(&tip, freefile->fx_oldinum, - freefile->fx_mode)) != 0) { - softdep_error("handle_workitem_freefile", error); - } - WORKITEM_FREE(freefile, D_FREEFILE); -} - -/* - * Disk writes. - * - * The dependency structures constructed above are most actively used when file - * system blocks are written to disk. No constraints are placed on when a - * block can be written, but unsatisfied update dependencies are made safe by - * modifying (or replacing) the source memory for the duration of the disk - * write. When the disk write completes, the memory block is again brought - * up-to-date. - * - * In-core inode structure reclamation. - * - * Because there are a finite number of "in-core" inode structures, they are - * reused regularly. By transferring all inode-related dependencies to the - * in-memory inode block and indexing them separately (via "inodedep"s), we - * can allow "in-core" inode structures to be reused at any time and avoid - * any increase in contention. - * - * Called just before entering the device driver to initiate a new disk I/O. - * The buffer must be locked, thus, no I/O completion operations can occur - * while we are manipulating its associated dependencies. - */ -/* structure describing disk write to occur */ -void -softdep_disk_io_initiation(struct buf *bp) -{ - struct worklist *wk, *nextwk; - struct indirdep *indirdep; - struct inodedep *inodedep; - struct buf *sbp; - - /* - * We only care about write operations. There should never - * be dependencies for reads. - */ - if (bp->b_flags & B_READ) - panic("softdep_disk_io_initiation: read"); - - ACQUIRE_LOCK(&lk); - - /* - * Do any necessary pre-I/O processing. - */ - for (wk = LIST_FIRST(&bp->b_dep); wk; wk = nextwk) { - nextwk = LIST_NEXT(wk, wk_list); - switch (wk->wk_type) { - - case D_PAGEDEP: - initiate_write_filepage(WK_PAGEDEP(wk), bp); - continue; - - case D_INODEDEP: - inodedep = WK_INODEDEP(wk); - if (inodedep->id_fs->fs_magic == FS_UFS1_MAGIC) - initiate_write_inodeblock_ufs1(inodedep, bp); -#ifdef FFS2 - else - initiate_write_inodeblock_ufs2(inodedep, bp); -#endif - continue; - - case D_INDIRDEP: - indirdep = WK_INDIRDEP(wk); - if (indirdep->ir_state & GOINGAWAY) - panic("disk_io_initiation: indirdep gone"); - /* - * If there are no remaining dependencies, this - * will be writing the real pointers, so the - * dependency can be freed. - */ - if (LIST_FIRST(&indirdep->ir_deplisthd) == NULL) { - sbp = indirdep->ir_savebp; - sbp->b_flags |= B_INVAL | B_NOCACHE; - /* inline expand WORKLIST_REMOVE(wk); */ - wk->wk_state &= ~ONWORKLIST; - LIST_REMOVE(wk, wk_list); - WORKITEM_FREE(indirdep, D_INDIRDEP); - FREE_LOCK(&lk); - brelse(sbp); - ACQUIRE_LOCK(&lk); - continue; - } - /* - * Replace up-to-date version with safe version. - */ - FREE_LOCK(&lk); - indirdep->ir_saveddata = malloc(bp->b_bcount, - M_INDIRDEP, M_WAITOK); - ACQUIRE_LOCK(&lk); - indirdep->ir_state &= ~ATTACHED; - indirdep->ir_state |= UNDONE; - memcpy(indirdep->ir_saveddata, bp->b_data, bp->b_bcount); - memcpy(bp->b_data, indirdep->ir_savebp->b_data, - bp->b_bcount); - continue; - - case D_MKDIR: - case D_BMSAFEMAP: - case D_ALLOCDIRECT: - case D_ALLOCINDIR: - continue; - - default: - FREE_LOCK(&lk); - panic("handle_disk_io_initiation: Unexpected type %s", - TYPENAME(wk->wk_type)); - /* NOTREACHED */ - } - } - - FREE_LOCK(&lk); -} - -/* - * Called from within the procedure above to deal with unsatisfied - * allocation dependencies in a directory. The buffer must be locked, - * thus, no I/O completion operations can occur while we are - * manipulating its associated dependencies. - */ -STATIC void -initiate_write_filepage(struct pagedep *pagedep, struct buf *bp) -{ - struct diradd *dap; - struct direct *ep; - int i; - - if (pagedep->pd_state & IOSTARTED) { - /* - * This can only happen if there is a driver that does not - * understand chaining. Here biodone will reissue the call - * to strategy for the incomplete buffers. - */ - printf("initiate_write_filepage: already started\n"); - return; - } - pagedep->pd_state |= IOSTARTED; - for (i = 0; i < DAHASHSZ; i++) { - LIST_FOREACH(dap, &pagedep->pd_diraddhd[i], da_pdlist) { - ep = (struct direct *) - ((char *)bp->b_data + dap->da_offset); - if (ep->d_ino != dap->da_newinum) { - FREE_LOCK(&lk); - panic("%s: dir inum %u != new %u", - "initiate_write_filepage", - ep->d_ino, dap->da_newinum); - } - if (dap->da_state & DIRCHG) - ep->d_ino = dap->da_previous->dm_oldinum; - else - ep->d_ino = 0; - dap->da_state &= ~ATTACHED; - dap->da_state |= UNDONE; - } - } -} - -/* - * Called from within the procedure above to deal with unsatisfied - * allocation dependencies in an inodeblock. The buffer must be - * locked, thus, no I/O completion operations can occur while we - * are manipulating its associated dependencies. - */ -/* The inode block */ -STATIC void -initiate_write_inodeblock_ufs1(struct inodedep *inodedep, struct buf *bp) -{ - struct allocdirect *adp, *lastadp; - struct ufs1_dinode *dp; - struct fs *fs; -#ifdef DIAGNOSTIC - daddr_t prevlbn = 0; - int32_t d1, d2; -#endif - int i, deplist; - - if (inodedep->id_state & IOSTARTED) { - FREE_LOCK(&lk); - panic("initiate_write_inodeblock: already started"); - } - inodedep->id_state |= IOSTARTED; - fs = inodedep->id_fs; - dp = (struct ufs1_dinode *)bp->b_data + - ino_to_fsbo(fs, inodedep->id_ino); - /* - * If the bitmap is not yet written, then the allocated - * inode cannot be written to disk. - */ - if ((inodedep->id_state & DEPCOMPLETE) == 0) { - if (inodedep->id_savedino1 != NULL) { - FREE_LOCK(&lk); - panic("initiate_write_inodeblock: already doing I/O"); - } - FREE_LOCK(&lk); - inodedep->id_savedino1 = malloc(sizeof(struct ufs1_dinode), - M_INODEDEP, M_WAITOK); - inodedep->id_unsize = sizeof(struct ufs1_dinode); - ACQUIRE_LOCK(&lk); - *inodedep->id_savedino1 = *dp; - memset(dp, 0, sizeof(struct ufs1_dinode)); - return; - } - /* - * If no dependencies, then there is nothing to roll back. - */ - inodedep->id_savedsize = dp->di_size; - if (TAILQ_FIRST(&inodedep->id_inoupdt) == NULL) - return; - /* - * Set the dependencies to busy. - */ - for (deplist = 0, adp = TAILQ_FIRST(&inodedep->id_inoupdt); adp; - adp = TAILQ_NEXT(adp, ad_next)) { -#ifdef DIAGNOSTIC - if (deplist != 0 && prevlbn >= adp->ad_lbn) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: lbn order"); - } - prevlbn = adp->ad_lbn; - if (adp->ad_lbn < NDADDR && - (d1 = dp->di_db[adp->ad_lbn]) != (d2 = adp->ad_newblkno)) { - FREE_LOCK(&lk); - panic("%s: direct pointer #%lld mismatch %d != %d", - "softdep_write_inodeblock", (long long)adp->ad_lbn, - d1, d2); - } - if (adp->ad_lbn >= NDADDR && - (d1 = dp->di_ib[adp->ad_lbn - NDADDR]) != - (d2 = adp->ad_newblkno)) { - FREE_LOCK(&lk); - panic("%s: indirect pointer #%lld mismatch %d != %d", - "softdep_write_inodeblock", (long long)(adp->ad_lbn - - NDADDR), d1, d2); - } - deplist |= 1 << adp->ad_lbn; - if ((adp->ad_state & ATTACHED) == 0) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: Unknown state 0x%x", - adp->ad_state); - } -#endif /* DIAGNOSTIC */ - adp->ad_state &= ~ATTACHED; - adp->ad_state |= UNDONE; - } - /* - * The on-disk inode cannot claim to be any larger than the last - * fragment that has been written. Otherwise, the on-disk inode - * might have fragments that were not the last block in the file - * which would corrupt the filesystem. - */ - for (lastadp = NULL, adp = TAILQ_FIRST(&inodedep->id_inoupdt); adp; - lastadp = adp, adp = TAILQ_NEXT(adp, ad_next)) { - if (adp->ad_lbn >= NDADDR) - break; - dp->di_db[adp->ad_lbn] = adp->ad_oldblkno; - /* keep going until hitting a rollback to a frag */ - if (adp->ad_oldsize == 0 || adp->ad_oldsize == fs->fs_bsize) - continue; - dp->di_size = fs->fs_bsize * adp->ad_lbn + adp->ad_oldsize; - for (i = adp->ad_lbn + 1; i < NDADDR; i++) { -#ifdef DIAGNOSTIC - if (dp->di_db[i] != 0 && (deplist & (1 << i)) == 0) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: lost dep1"); - } -#endif /* DIAGNOSTIC */ - dp->di_db[i] = 0; - } - for (i = 0; i < NIADDR; i++) { -#ifdef DIAGNOSTIC - if (dp->di_ib[i] != 0 && - (deplist & ((1 << NDADDR) << i)) == 0) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: lost dep2"); - } -#endif /* DIAGNOSTIC */ - dp->di_ib[i] = 0; - } - return; - } - /* - * If we have zero'ed out the last allocated block of the file, - * roll back the size to the last currently allocated block. - * We know that this last allocated block is a full-sized as - * we already checked for fragments in the loop above. - */ - if (lastadp != NULL && - dp->di_size <= (lastadp->ad_lbn + 1) * fs->fs_bsize) { - for (i = lastadp->ad_lbn; i >= 0; i--) - if (dp->di_db[i] != 0) - break; - dp->di_size = (i + 1) * fs->fs_bsize; - } - /* - * The only dependencies are for indirect blocks. - * - * The file size for indirect block additions is not guaranteed. - * Such a guarantee would be non-trivial to achieve. The conventional - * synchronous write implementation also does not make this guarantee. - * Fsck should catch and fix discrepancies. Arguably, the file size - * can be over-estimated without destroying integrity when the file - * moves into the indirect blocks (i.e., is large). If we want to - * postpone fsck, we are stuck with this argument. - */ - for (; adp; adp = TAILQ_NEXT(adp, ad_next)) - dp->di_ib[adp->ad_lbn - NDADDR] = 0; -} - -#ifdef FFS2 -/* - * Version of initiate_write_inodeblock that handles FFS2 dinodes. - */ -/* The inode block */ -STATIC void -initiate_write_inodeblock_ufs2(struct inodedep *inodedep, struct buf *bp) -{ - struct allocdirect *adp, *lastadp; - struct ufs2_dinode *dp; - struct fs *fs = inodedep->id_fs; -#ifdef DIAGNOSTIC - daddr_t prevlbn = -1, d1, d2; -#endif - int deplist, i; - - if (inodedep->id_state & IOSTARTED) - panic("initiate_write_inodeblock_ufs2: already started"); - inodedep->id_state |= IOSTARTED; - fs = inodedep->id_fs; - dp = (struct ufs2_dinode *)bp->b_data + - ino_to_fsbo(fs, inodedep->id_ino); - /* - * If the bitmap is not yet written, then the allocated - * inode cannot be written to disk. - */ - if ((inodedep->id_state & DEPCOMPLETE) == 0) { - if (inodedep->id_savedino2 != NULL) - panic("initiate_write_inodeblock_ufs2: I/O underway"); - inodedep->id_savedino2 = malloc(sizeof(struct ufs2_dinode), - M_INODEDEP, M_WAITOK); - inodedep->id_unsize = sizeof(struct ufs2_dinode); - *inodedep->id_savedino2 = *dp; - memset(dp, 0, sizeof(struct ufs2_dinode)); - return; - } - /* - * If no dependencies, then there is nothing to roll back. - */ - inodedep->id_savedsize = dp->di_size; - if (TAILQ_FIRST(&inodedep->id_inoupdt) == NULL) - return; - -#ifdef notyet - inodedep->id_savedextsize = dp->di_extsize; - if (TAILQ_FIRST(&inodedep->id_inoupdt) == NULL && - TAILQ_FIRST(&inodedep->id_extupdt) == NULL) - return; - /* - * Set the ext data dependencies to busy. - */ - for (deplist = 0, adp = TAILQ_FIRST(&inodedep->id_extupdt); adp; - adp = TAILQ_NEXT(adp, ad_next)) { -#ifdef DIAGNOSTIC - if (deplist != 0 && prevlbn >= adp->ad_lbn) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: lbn order"); - } - prevlbn = adp->ad_lbn; - if ((d1 = dp->di_extb[adp->ad_lbn]) != - (d2 = adp->ad_newblkno)) { - FREE_LOCK(&lk); - panic("%s: direct pointer #%lld mismatch %lld != %lld", - "softdep_write_inodeblock", (long long)adp->ad_lbn, - d1, d2); - } - deplist |= 1 << adp->ad_lbn; - if ((adp->ad_state & ATTACHED) == 0) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: Unknown state 0x%x", - adp->ad_state); - } -#endif /* DIAGNOSTIC */ - adp->ad_state &= ~ATTACHED; - adp->ad_state |= UNDONE; - } - /* - * The on-disk inode cannot claim to be any larger than the last - * fragment that has been written. Otherwise, the on-disk inode - * might have fragments that were not the last block in the ext - * data which would corrupt the filesystem. - */ - for (lastadp = NULL, adp = TAILQ_FIRST(&inodedep->id_extupdt); adp; - lastadp = adp, adp = TAILQ_NEXT(adp, ad_next)) { - dp->di_extb[adp->ad_lbn] = adp->ad_oldblkno; - /* keep going until hitting a rollback to a frag */ - if (adp->ad_oldsize == 0 || adp->ad_oldsize == fs->fs_bsize) - continue; - dp->di_extsize = fs->fs_bsize * adp->ad_lbn + adp->ad_oldsize; - for (i = adp->ad_lbn + 1; i < NXADDR; i++) { -#ifdef DIAGNOSTIC - if (dp->di_extb[i] != 0 && (deplist & (1 << i)) == 0) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: lost dep1"); - } -#endif /* DIAGNOSTIC */ - dp->di_extb[i] = 0; - } - lastadp = NULL; - break; - } - /* - * If we have zero'ed out the last allocated block of the ext - * data, roll back the size to the last currently allocated block. - * We know that this last allocated block is a full-sized as - * we already checked for fragments in the loop above. - */ - if (lastadp != NULL && - dp->di_extsize <= (lastadp->ad_lbn + 1) * fs->fs_bsize) { - for (i = lastadp->ad_lbn; i >= 0; i--) - if (dp->di_extb[i] != 0) - break; - dp->di_extsize = (i + 1) * fs->fs_bsize; - } -#endif /* notyet */ - - /* - * Set the file data dependencies to busy. - */ - for (deplist = 0, adp = TAILQ_FIRST(&inodedep->id_inoupdt); adp; - adp = TAILQ_NEXT(adp, ad_next)) { -#ifdef DIAGNOSTIC - if (deplist != 0 && prevlbn >= adp->ad_lbn) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: lbn order"); - } - prevlbn = adp->ad_lbn; - if (adp->ad_lbn < NDADDR && - (d1 = dp->di_db[adp->ad_lbn]) != (d2 = adp->ad_newblkno)) { - FREE_LOCK(&lk); - panic("%s: direct pointer #%lld mismatch %lld != %lld", - "softdep_write_inodeblock", (long long)adp->ad_lbn, - d1, d2); - } - if (adp->ad_lbn >= NDADDR && - (d1 = dp->di_ib[adp->ad_lbn - NDADDR]) != - (d2 = adp->ad_newblkno)) { - FREE_LOCK(&lk); - panic("%s: indirect pointer #%lld mismatch %lld != %lld", - "softdep_write_inodeblock", (long long)(adp->ad_lbn - - NDADDR), d1, d2); - } - deplist |= 1 << adp->ad_lbn; - if ((adp->ad_state & ATTACHED) == 0) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: Unknown state 0x%x", - adp->ad_state); - } -#endif /* DIAGNOSTIC */ - adp->ad_state &= ~ATTACHED; - adp->ad_state |= UNDONE; - } - /* - * The on-disk inode cannot claim to be any larger than the last - * fragment that has been written. Otherwise, the on-disk inode - * might have fragments that were not the last block in the file - * which would corrupt the filesystem. - */ - for (lastadp = NULL, adp = TAILQ_FIRST(&inodedep->id_inoupdt); adp; - lastadp = adp, adp = TAILQ_NEXT(adp, ad_next)) { - if (adp->ad_lbn >= NDADDR) - break; - dp->di_db[adp->ad_lbn] = adp->ad_oldblkno; - /* keep going until hitting a rollback to a frag */ - if (adp->ad_oldsize == 0 || adp->ad_oldsize == fs->fs_bsize) - continue; - dp->di_size = fs->fs_bsize * adp->ad_lbn + adp->ad_oldsize; - for (i = adp->ad_lbn + 1; i < NDADDR; i++) { -#ifdef DIAGNOSTIC - if (dp->di_db[i] != 0 && (deplist & (1 << i)) == 0) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: lost dep2"); - } -#endif /* DIAGNOSTIC */ - dp->di_db[i] = 0; - } - for (i = 0; i < NIADDR; i++) { -#ifdef DIAGNOSTIC - if (dp->di_ib[i] != 0 && - (deplist & ((1 << NDADDR) << i)) == 0) { - FREE_LOCK(&lk); - panic("softdep_write_inodeblock: lost dep3"); - } -#endif /* DIAGNOSTIC */ - dp->di_ib[i] = 0; - } - return; - } - /* - * If we have zero'ed out the last allocated block of the file, - * roll back the size to the last currently allocated block. - * We know that this last allocated block is a full-sized as - * we already checked for fragments in the loop above. - */ - if (lastadp != NULL && - dp->di_size <= (lastadp->ad_lbn + 1) * fs->fs_bsize) { - for (i = lastadp->ad_lbn; i >= 0; i--) - if (dp->di_db[i] != 0) - break; - dp->di_size = (i + 1) * fs->fs_bsize; - } - /* - * The only dependencies are for indirect blocks. - * - * The file size for indirect block additions is not guaranteed. - * Such a guarantee would be non-trivial to achieve. The conventional - * synchronous write implementation also does not make this guarantee. - * Fsck should catch and fix discrepancies. Arguably, the file size - * can be over-estimated without destroying integrity when the file - * moves into the indirect blocks (i.e., is large). If we want to - * postpone fsck, we are stuck with this argument. - */ - for (; adp; adp = TAILQ_NEXT(adp, ad_next)) - dp->di_ib[adp->ad_lbn - NDADDR] = 0; -} -#endif /* FFS2 */ - -/* - * This routine is called during the completion interrupt - * service routine for a disk write (from the procedure called - * by the device driver to inform the file system caches of - * a request completion). It should be called early in this - * procedure, before the block is made available to other - * processes or other routines are called. - */ -/* describes the completed disk write */ -void -softdep_disk_write_complete(struct buf *bp) -{ - struct worklist *wk; - struct workhead reattach; - struct newblk *newblk; - struct allocindir *aip; - struct allocdirect *adp; - struct indirdep *indirdep; - struct inodedep *inodedep; - struct bmsafemap *bmsafemap; - - /* - * If an error occurred while doing the write, then the data - * has not hit the disk and the dependencies cannot be unrolled. - */ - if ((bp->b_flags & B_ERROR) && !(bp->b_flags & B_INVAL)) - return; - -#ifdef DEBUG - if (lk.lkt_held != -1) - panic("softdep_disk_write_complete: lock is held"); - lk.lkt_held = -2; -#endif - LIST_INIT(&reattach); - while ((wk = LIST_FIRST(&bp->b_dep)) != NULL) { - WORKLIST_REMOVE(wk); - switch (wk->wk_type) { - - case D_PAGEDEP: - if (handle_written_filepage(WK_PAGEDEP(wk), bp)) - WORKLIST_INSERT(&reattach, wk); - continue; - - case D_INODEDEP: - if (handle_written_inodeblock(WK_INODEDEP(wk), bp)) - WORKLIST_INSERT(&reattach, wk); - continue; - - case D_BMSAFEMAP: - bmsafemap = WK_BMSAFEMAP(wk); - while ((newblk = LIST_FIRST(&bmsafemap->sm_newblkhd))) { - newblk->nb_state |= DEPCOMPLETE; - newblk->nb_bmsafemap = NULL; - LIST_REMOVE(newblk, nb_deps); - } - while ((adp = - LIST_FIRST(&bmsafemap->sm_allocdirecthd))) { - adp->ad_state |= DEPCOMPLETE; - adp->ad_buf = NULL; - LIST_REMOVE(adp, ad_deps); - handle_allocdirect_partdone(adp); - } - while ((aip = - LIST_FIRST(&bmsafemap->sm_allocindirhd))) { - aip->ai_state |= DEPCOMPLETE; - aip->ai_buf = NULL; - LIST_REMOVE(aip, ai_deps); - handle_allocindir_partdone(aip); - } - while ((inodedep = - LIST_FIRST(&bmsafemap->sm_inodedephd)) != NULL) { - inodedep->id_state |= DEPCOMPLETE; - LIST_REMOVE(inodedep, id_deps); - inodedep->id_buf = NULL; - } - WORKITEM_FREE(bmsafemap, D_BMSAFEMAP); - continue; - - case D_MKDIR: - handle_written_mkdir(WK_MKDIR(wk), MKDIR_BODY); - continue; - - case D_ALLOCDIRECT: - adp = WK_ALLOCDIRECT(wk); - adp->ad_state |= COMPLETE; - handle_allocdirect_partdone(adp); - continue; - - case D_ALLOCINDIR: - aip = WK_ALLOCINDIR(wk); - aip->ai_state |= COMPLETE; - handle_allocindir_partdone(aip); - continue; - - case D_INDIRDEP: - indirdep = WK_INDIRDEP(wk); - if (indirdep->ir_state & GOINGAWAY) - panic("disk_write_complete: indirdep gone"); - memcpy(bp->b_data, indirdep->ir_saveddata, bp->b_bcount); - free(indirdep->ir_saveddata, M_INDIRDEP, bp->b_bcount); - indirdep->ir_saveddata = NULL; - indirdep->ir_state &= ~UNDONE; - indirdep->ir_state |= ATTACHED; - while ((aip = LIST_FIRST(&indirdep->ir_donehd))) { - handle_allocindir_partdone(aip); - if (aip == LIST_FIRST(&indirdep->ir_donehd)) - panic("disk_write_complete: not gone"); - } - WORKLIST_INSERT(&reattach, wk); - if ((bp->b_flags & B_DELWRI) == 0) - stat_indir_blk_ptrs++; - buf_dirty(bp); - continue; - - default: - panic("handle_disk_write_complete: Unknown type %s", - TYPENAME(wk->wk_type)); - /* NOTREACHED */ - } - } - /* - * Reattach any requests that must be redone. - */ - while ((wk = LIST_FIRST(&reattach)) != NULL) { - WORKLIST_REMOVE(wk); - WORKLIST_INSERT(&bp->b_dep, wk); - } -#ifdef DEBUG - if (lk.lkt_held != -2) - panic("softdep_disk_write_complete: lock lost"); - lk.lkt_held = -1; -#endif -} - -/* - * Called from within softdep_disk_write_complete above. Note that - * this routine is always called from interrupt level with further - * splbio interrupts blocked. - */ -/* the completed allocdirect */ -STATIC void -handle_allocdirect_partdone(struct allocdirect *adp) -{ - struct allocdirect *listadp; - struct inodedep *inodedep; - long bsize, delay; - - splassert(IPL_BIO); - - if ((adp->ad_state & ALLCOMPLETE) != ALLCOMPLETE) - return; - if (adp->ad_buf != NULL) - panic("handle_allocdirect_partdone: dangling dep"); - - /* - * The on-disk inode cannot claim to be any larger than the last - * fragment that has been written. Otherwise, the on-disk inode - * might have fragments that were not the last block in the file - * which would corrupt the filesystem. Thus, we cannot free any - * allocdirects after one whose ad_oldblkno claims a fragment as - * these blocks must be rolled back to zero before writing the inode. - * We check the currently active set of allocdirects in id_inoupdt. - */ - inodedep = adp->ad_inodedep; - bsize = inodedep->id_fs->fs_bsize; - TAILQ_FOREACH(listadp, &inodedep->id_inoupdt, ad_next) { - /* found our block */ - if (listadp == adp) - break; - /* continue if ad_oldlbn is not a fragment */ - if (listadp->ad_oldsize == 0 || - listadp->ad_oldsize == bsize) - continue; - /* hit a fragment */ - return; - } - /* - * If we have reached the end of the current list without - * finding the just finished dependency, then it must be - * on the future dependency list. Future dependencies cannot - * be freed until they are moved to the current list. - */ - if (listadp == NULL) { -#ifdef DEBUG - TAILQ_FOREACH(listadp, &inodedep->id_newinoupdt, ad_next) - /* found our block */ - if (listadp == adp) - break; - if (listadp == NULL) - panic("handle_allocdirect_partdone: lost dep"); -#endif /* DEBUG */ - return; - } - /* - * If we have found the just finished dependency, then free - * it along with anything that follows it that is complete. - * If the inode still has a bitmap dependency, then it has - * never been written to disk, hence the on-disk inode cannot - * reference the old fragment so we can free it without delay. - */ - delay = (inodedep->id_state & DEPCOMPLETE); - for (; adp; adp = listadp) { - listadp = TAILQ_NEXT(adp, ad_next); - if ((adp->ad_state & ALLCOMPLETE) != ALLCOMPLETE) - return; - free_allocdirect(&inodedep->id_inoupdt, adp, delay); - } -} - -/* - * Called from within softdep_disk_write_complete above. Note that - * this routine is always called from interrupt level with further - * splbio interrupts blocked. - */ -/* the completed allocindir */ -STATIC void -handle_allocindir_partdone(struct allocindir *aip) -{ - struct indirdep *indirdep; - - splassert(IPL_BIO); - - if ((aip->ai_state & ALLCOMPLETE) != ALLCOMPLETE) - return; - if (aip->ai_buf != NULL) - panic("handle_allocindir_partdone: dangling dependency"); - indirdep = aip->ai_indirdep; - if (indirdep->ir_state & UNDONE) { - LIST_REMOVE(aip, ai_next); - LIST_INSERT_HEAD(&indirdep->ir_donehd, aip, ai_next); - return; - } - if (indirdep->ir_state & UFS1FMT) - ((int32_t *)indirdep->ir_savebp->b_data)[aip->ai_offset] = - aip->ai_newblkno; - else - ((int64_t *)indirdep->ir_savebp->b_data)[aip->ai_offset] = - aip->ai_newblkno; - LIST_REMOVE(aip, ai_next); - if (aip->ai_freefrag != NULL) - add_to_worklist(&aip->ai_freefrag->ff_list); - WORKITEM_FREE(aip, D_ALLOCINDIR); -} - -/* - * Called from within softdep_disk_write_complete above to restore - * in-memory inode block contents to their most up-to-date state. Note - * that this routine is always called from interrupt level with further - * splbio interrupts blocked. - */ -/* buffer containing the inode block */ -STATIC int -handle_written_inodeblock(struct inodedep *inodedep, struct buf *bp) -{ - struct worklist *wk, *filefree; - struct allocdirect *adp, *nextadp; - struct ufs1_dinode *dp1 = NULL; - struct ufs2_dinode *dp2 = NULL; - int hadchanges, fstype; - - splassert(IPL_BIO); - - if ((inodedep->id_state & IOSTARTED) == 0) - panic("handle_written_inodeblock: not started"); - inodedep->id_state &= ~IOSTARTED; - - if (inodedep->id_fs->fs_magic == FS_UFS1_MAGIC) { - fstype = UM_UFS1; - dp1 = (struct ufs1_dinode *) bp->b_data + - ino_to_fsbo(inodedep->id_fs, inodedep->id_ino); - } else { - fstype = UM_UFS2; - dp2 = (struct ufs2_dinode *) bp->b_data + - ino_to_fsbo(inodedep->id_fs, inodedep->id_ino); - } - - /* - * If we had to rollback the inode allocation because of - * bitmaps being incomplete, then simply restore it. - * Keep the block dirty so that it will not be reclaimed until - * all associated dependencies have been cleared and the - * corresponding updates written to disk. - */ - if (inodedep->id_savedino1 != NULL) { - if (fstype == UM_UFS1) - *dp1 = *inodedep->id_savedino1; - else - *dp2 = *inodedep->id_savedino2; - free(inodedep->id_savedino1, M_INODEDEP, inodedep->id_unsize); - inodedep->id_savedino1 = NULL; - if ((bp->b_flags & B_DELWRI) == 0) - stat_inode_bitmap++; - buf_dirty(bp); - return (1); - } - inodedep->id_state |= COMPLETE; - /* - * Roll forward anything that had to be rolled back before - * the inode could be updated. - */ - hadchanges = 0; - for (adp = TAILQ_FIRST(&inodedep->id_inoupdt); adp; adp = nextadp) { - nextadp = TAILQ_NEXT(adp, ad_next); - if (adp->ad_state & ATTACHED) - panic("handle_written_inodeblock: new entry"); - if (fstype == UM_UFS1) { - if (adp->ad_lbn < NDADDR) { - if (dp1->di_db[adp->ad_lbn] != adp->ad_oldblkno) - panic("%s: %s #%lld mismatch %d != " - "%lld", - "handle_written_inodeblock", - "direct pointer", - (long long)adp->ad_lbn, - dp1->di_db[adp->ad_lbn], - (long long)adp->ad_oldblkno); - dp1->di_db[adp->ad_lbn] = adp->ad_newblkno; - } else { - if (dp1->di_ib[adp->ad_lbn - NDADDR] != 0) - panic("%s: %s #%lld allocated as %d", - "handle_written_inodeblock", - "indirect pointer", - (long long)(adp->ad_lbn - NDADDR), - dp1->di_ib[adp->ad_lbn - NDADDR]); - dp1->di_ib[adp->ad_lbn - NDADDR] = - adp->ad_newblkno; - } - } else { - if (adp->ad_lbn < NDADDR) { - if (dp2->di_db[adp->ad_lbn] != adp->ad_oldblkno) - panic("%s: %s #%lld mismatch %lld != " - "%lld", "handle_written_inodeblock", - "direct pointer", - (long long)adp->ad_lbn, - dp2->di_db[adp->ad_lbn], - (long long)adp->ad_oldblkno); - dp2->di_db[adp->ad_lbn] = adp->ad_newblkno; - } else { - if (dp2->di_ib[adp->ad_lbn - NDADDR] != 0) - panic("%s: %s #%lld allocated as %lld", - "handle_written_inodeblock", - "indirect pointer", - (long long)(adp->ad_lbn - NDADDR), - dp2->di_ib[adp->ad_lbn - NDADDR]); - dp2->di_ib[adp->ad_lbn - NDADDR] = - adp->ad_newblkno; - } - } - adp->ad_state &= ~UNDONE; - adp->ad_state |= ATTACHED; - hadchanges = 1; - } - if (hadchanges && (bp->b_flags & B_DELWRI) == 0) - stat_direct_blk_ptrs++; - /* - * Reset the file size to its most up-to-date value. - */ - if (inodedep->id_savedsize == -1) - panic("handle_written_inodeblock: bad size"); - - if (fstype == UM_UFS1) { - if (dp1->di_size != inodedep->id_savedsize) { - dp1->di_size = inodedep->id_savedsize; - hadchanges = 1; - } - } else { - if (dp2->di_size != inodedep->id_savedsize) { - dp2->di_size = inodedep->id_savedsize; - hadchanges = 1; - } - } - inodedep->id_savedsize = -1; - /* - * If there were any rollbacks in the inode block, then it must be - * marked dirty so that its will eventually get written back in - * its correct form. - */ - if (hadchanges) - buf_dirty(bp); - /* - * Process any allocdirects that completed during the update. - */ - if ((adp = TAILQ_FIRST(&inodedep->id_inoupdt)) != NULL) - handle_allocdirect_partdone(adp); - /* - * Process deallocations that were held pending until the - * inode had been written to disk. Freeing of the inode - * is delayed until after all blocks have been freed to - * avoid creation of new triples - * before the old ones have been deleted. - */ - filefree = NULL; - while ((wk = LIST_FIRST(&inodedep->id_bufwait)) != NULL) { - WORKLIST_REMOVE(wk); - switch (wk->wk_type) { - - case D_FREEFILE: - /* - * We defer adding filefree to the worklist until - * all other additions have been made to ensure - * that it will be done after all the old blocks - * have been freed. - */ - if (filefree != NULL) - panic("handle_written_inodeblock: filefree"); - filefree = wk; - continue; - - case D_MKDIR: - handle_written_mkdir(WK_MKDIR(wk), MKDIR_PARENT); - continue; - - case D_DIRADD: - diradd_inode_written(WK_DIRADD(wk), inodedep); - continue; - - case D_FREEBLKS: - wk->wk_state |= COMPLETE; - if ((wk->wk_state & ALLCOMPLETE) != ALLCOMPLETE) - continue; - /* FALLTHROUGH */ - case D_FREEFRAG: - case D_DIRREM: - add_to_worklist(wk); - continue; - - case D_NEWDIRBLK: - free_newdirblk(WK_NEWDIRBLK(wk)); - continue; - - default: - panic("handle_written_inodeblock: Unknown type %s", - TYPENAME(wk->wk_type)); - /* NOTREACHED */ - } - } - if (filefree != NULL) { - if (free_inodedep(inodedep) == 0) - panic("handle_written_inodeblock: live inodedep"); - add_to_worklist(filefree); - return (0); - } - - /* - * If no outstanding dependencies, free it. - */ - if (free_inodedep(inodedep) || - TAILQ_FIRST(&inodedep->id_inoupdt) == NULL) - return (0); - return (hadchanges); -} - -/* - * Process a diradd entry after its dependent inode has been written. - * This routine must be called with splbio interrupts blocked. - */ -STATIC void -diradd_inode_written(struct diradd *dap, struct inodedep *inodedep) -{ - struct pagedep *pagedep; - - splassert(IPL_BIO); - - dap->da_state |= COMPLETE; - if ((dap->da_state & ALLCOMPLETE) == ALLCOMPLETE) { - if (dap->da_state & DIRCHG) - pagedep = dap->da_previous->dm_pagedep; - else - pagedep = dap->da_pagedep; - LIST_REMOVE(dap, da_pdlist); - LIST_INSERT_HEAD(&pagedep->pd_pendinghd, dap, da_pdlist); - } - WORKLIST_INSERT(&inodedep->id_pendinghd, &dap->da_list); -} - -/* - * Handle the completion of a mkdir dependency. - */ -STATIC void -handle_written_mkdir(struct mkdir *mkdir, int type) -{ - struct diradd *dap; - struct pagedep *pagedep; - - splassert(IPL_BIO); - - if (mkdir->md_state != type) - panic("handle_written_mkdir: bad type"); - dap = mkdir->md_diradd; - dap->da_state &= ~type; - if ((dap->da_state & (MKDIR_PARENT | MKDIR_BODY)) == 0) - dap->da_state |= DEPCOMPLETE; - if ((dap->da_state & ALLCOMPLETE) == ALLCOMPLETE) { - if (dap->da_state & DIRCHG) - pagedep = dap->da_previous->dm_pagedep; - else - pagedep = dap->da_pagedep; - LIST_REMOVE(dap, da_pdlist); - LIST_INSERT_HEAD(&pagedep->pd_pendinghd, dap, da_pdlist); - } - LIST_REMOVE(mkdir, md_mkdirs); - WORKITEM_FREE(mkdir, D_MKDIR); -} - -/* - * Called from within softdep_disk_write_complete above. - * A write operation was just completed. Removed inodes can - * now be freed and associated block pointers may be committed. - * Note that this routine is always called from interrupt level - * with further splbio interrupts blocked. - */ -/* buffer containing the written page */ -STATIC int -handle_written_filepage(struct pagedep *pagedep, struct buf *bp) -{ - struct dirrem *dirrem; - struct diradd *dap, *nextdap; - struct direct *ep; - int i, chgs; - - splassert(IPL_BIO); - - if ((pagedep->pd_state & IOSTARTED) == 0) - panic("handle_written_filepage: not started"); - pagedep->pd_state &= ~IOSTARTED; - /* - * Process any directory removals that have been committed. - */ - while ((dirrem = LIST_FIRST(&pagedep->pd_dirremhd)) != NULL) { - LIST_REMOVE(dirrem, dm_next); - dirrem->dm_dirinum = pagedep->pd_ino; - add_to_worklist(&dirrem->dm_list); - } - /* - * Free any directory additions that have been committed. - * If it is a newly allocated block, we have to wait until - * the on-disk directory inode claims the new block. - */ - if ((pagedep->pd_state & NEWBLOCK) == 0) - while ((dap = LIST_FIRST(&pagedep->pd_pendinghd)) != NULL) - free_diradd(dap); - /* - * Uncommitted directory entries must be restored. - */ - for (chgs = 0, i = 0; i < DAHASHSZ; i++) { - for (dap = LIST_FIRST(&pagedep->pd_diraddhd[i]); dap; - dap = nextdap) { - nextdap = LIST_NEXT(dap, da_pdlist); - if (dap->da_state & ATTACHED) - panic("handle_written_filepage: attached"); - ep = (struct direct *) - ((char *)bp->b_data + dap->da_offset); - ep->d_ino = dap->da_newinum; - dap->da_state &= ~UNDONE; - dap->da_state |= ATTACHED; - chgs = 1; - /* - * If the inode referenced by the directory has - * been written out, then the dependency can be - * moved to the pending list. - */ - if ((dap->da_state & ALLCOMPLETE) == ALLCOMPLETE) { - LIST_REMOVE(dap, da_pdlist); - LIST_INSERT_HEAD(&pagedep->pd_pendinghd, dap, - da_pdlist); - } - } - } - /* - * If there were any rollbacks in the directory, then it must be - * marked dirty so that its will eventually get written back in - * its correct form. - */ - if (chgs) { - if ((bp->b_flags & B_DELWRI) == 0) - stat_dir_entry++; - buf_dirty(bp); - return (1); - } - /* - * If we are not waiting for a new directory block to be - * claimed by its inode, then the pagedep will be freed. - * Otherwise it will remain to track any new entries on - * the page in case they are fsync'ed. - */ - if ((pagedep->pd_state & NEWBLOCK) == 0) { - LIST_REMOVE(pagedep, pd_hash); - WORKITEM_FREE(pagedep, D_PAGEDEP); - } - return (0); -} - -/* - * Writing back in-core inode structures. - * - * The file system only accesses an inode's contents when it occupies an - * "in-core" inode structure. These "in-core" structures are separate from - * the page frames used to cache inode blocks. Only the latter are - * transferred to/from the disk. So, when the updated contents of the - * "in-core" inode structure are copied to the corresponding in-memory inode - * block, the dependencies are also transferred. The following procedure is - * called when copying a dirty "in-core" inode to a cached inode block. - */ - -/* - * Called when an inode is loaded from disk. If the effective link count - * differed from the actual link count when it was last flushed, then we - * need to ensure that the correct effective link count is put back. - */ -/* the "in_core" copy of the inode */ -void -softdep_load_inodeblock(struct inode *ip) -{ - struct inodedep *inodedep; - - /* - * Check for alternate nlink count. - */ - ip->i_effnlink = DIP(ip, nlink); - ACQUIRE_LOCK(&lk); - if (inodedep_lookup(ip->i_fs, ip->i_number, 0, &inodedep) == 0) { - FREE_LOCK(&lk); - return; - } - ip->i_effnlink -= inodedep->id_nlinkdelta; - FREE_LOCK(&lk); -} - -/* - * This routine is called just before the "in-core" inode - * information is to be copied to the in-memory inode block. - * Recall that an inode block contains several inodes. If - * the force flag is set, then the dependencies will be - * cleared so that the update can always be made. Note that - * the buffer is locked when this routine is called, so we - * will never be in the middle of writing the inode block - * to disk. - */ -/* the "in_core" copy of the inode */ -/* the buffer containing the inode block */ -/* nonzero => update must be allowed */ -void -softdep_update_inodeblock(struct inode *ip, struct buf *bp, int waitfor) -{ - struct inodedep *inodedep; - struct worklist *wk; - int error, gotit; - - /* - * If the effective link count is not equal to the actual link - * count, then we must track the difference in an inodedep while - * the inode is (potentially) tossed out of the cache. Otherwise, - * if there is no existing inodedep, then there are no dependencies - * to track. - */ - ACQUIRE_LOCK(&lk); - if (inodedep_lookup(ip->i_fs, ip->i_number, 0, &inodedep) == 0) { - FREE_LOCK(&lk); - if (ip->i_effnlink != DIP(ip, nlink)) - panic("softdep_update_inodeblock: bad link count"); - return; - } - if (inodedep->id_nlinkdelta != DIP(ip, nlink) - ip->i_effnlink) { - FREE_LOCK(&lk); - panic("softdep_update_inodeblock: bad delta"); - } - /* - * Changes have been initiated. Anything depending on these - * changes cannot occur until this inode has been written. - */ - inodedep->id_state &= ~COMPLETE; - if ((inodedep->id_state & ONWORKLIST) == 0) - WORKLIST_INSERT(&bp->b_dep, &inodedep->id_list); - /* - * Any new dependencies associated with the incore inode must - * now be moved to the list associated with the buffer holding - * the in-memory copy of the inode. Once merged process any - * allocdirects that are completed by the merger. - */ - merge_inode_lists(inodedep); - if (TAILQ_FIRST(&inodedep->id_inoupdt) != NULL) - handle_allocdirect_partdone(TAILQ_FIRST(&inodedep->id_inoupdt)); - /* - * Now that the inode has been pushed into the buffer, the - * operations dependent on the inode being written to disk - * can be moved to the id_bufwait so that they will be - * processed when the buffer I/O completes. - */ - while ((wk = LIST_FIRST(&inodedep->id_inowait)) != NULL) { - WORKLIST_REMOVE(wk); - WORKLIST_INSERT(&inodedep->id_bufwait, wk); - } - /* - * Newly allocated inodes cannot be written until the bitmap - * that allocates them have been written (indicated by - * DEPCOMPLETE being set in id_state). If we are doing a - * forced sync (e.g., an fsync on a file), we force the bitmap - * to be written so that the update can be done. - */ - do { - if ((inodedep->id_state & DEPCOMPLETE) != 0 || waitfor == 0) { - FREE_LOCK(&lk); - return; - } - bp = inodedep->id_buf; - gotit = getdirtybuf(bp, MNT_WAIT); - } while (gotit == -1); - FREE_LOCK(&lk); - if (gotit && (error = bwrite(bp)) != 0) - softdep_error("softdep_update_inodeblock: bwrite", error); - if ((inodedep->id_state & DEPCOMPLETE) == 0) - panic("softdep_update_inodeblock: update failed"); -} - -/* - * Merge the new inode dependency list (id_newinoupdt) into the old - * inode dependency list (id_inoupdt). This routine must be called - * with splbio interrupts blocked. - */ -STATIC void -merge_inode_lists(struct inodedep *inodedep) -{ - struct allocdirect *listadp, *newadp; - - splassert(IPL_BIO); - - newadp = TAILQ_FIRST(&inodedep->id_newinoupdt); - for (listadp = TAILQ_FIRST(&inodedep->id_inoupdt); listadp && newadp;) { - if (listadp->ad_lbn < newadp->ad_lbn) { - listadp = TAILQ_NEXT(listadp, ad_next); - continue; - } - TAILQ_REMOVE(&inodedep->id_newinoupdt, newadp, ad_next); - TAILQ_INSERT_BEFORE(listadp, newadp, ad_next); - if (listadp->ad_lbn == newadp->ad_lbn) { - allocdirect_merge(&inodedep->id_inoupdt, newadp, - listadp); - listadp = newadp; - } - newadp = TAILQ_FIRST(&inodedep->id_newinoupdt); - } - TAILQ_CONCAT(&inodedep->id_inoupdt, &inodedep->id_newinoupdt, ad_next); -} - -/* - * If we are doing an fsync, then we must ensure that any directory - * entries for the inode have been written after the inode gets to disk. - */ -/* the "in_core" copy of the inode */ -int -softdep_fsync(struct vnode *vp) -{ - struct inodedep *inodedep; - struct pagedep *pagedep; - struct worklist *wk; - struct diradd *dap; - struct mount *mnt; - struct vnode *pvp; - struct inode *ip; - struct inode *pip; - struct buf *bp; - struct fs *fs; - struct proc *p = CURPROC; /* XXX */ - int error, flushparent; - ufsino_t parentino; - daddr_t lbn; - - ip = VTOI(vp); - fs = ip->i_fs; - ACQUIRE_LOCK(&lk); - if (inodedep_lookup(fs, ip->i_number, 0, &inodedep) == 0) { - FREE_LOCK(&lk); - return (0); - } - if (LIST_FIRST(&inodedep->id_inowait) != NULL || - LIST_FIRST(&inodedep->id_bufwait) != NULL || - TAILQ_FIRST(&inodedep->id_inoupdt) != NULL || - TAILQ_FIRST(&inodedep->id_newinoupdt) != NULL) { - FREE_LOCK(&lk); - panic("softdep_fsync: pending ops"); - } - for (error = 0, flushparent = 0; ; ) { - if ((wk = LIST_FIRST(&inodedep->id_pendinghd)) == NULL) - break; - if (wk->wk_type != D_DIRADD) { - FREE_LOCK(&lk); - panic("softdep_fsync: Unexpected type %s", - TYPENAME(wk->wk_type)); - } - dap = WK_DIRADD(wk); - /* - * Flush our parent if this directory entry has a MKDIR_PARENT - * dependency or is contained in a newly allocated block. - */ - if (dap->da_state & DIRCHG) - pagedep = dap->da_previous->dm_pagedep; - else - pagedep = dap->da_pagedep; - mnt = pagedep->pd_mnt; - parentino = pagedep->pd_ino; - lbn = pagedep->pd_lbn; - if ((dap->da_state & (MKDIR_BODY | COMPLETE)) != COMPLETE) { - FREE_LOCK(&lk); - panic("softdep_fsync: dirty"); - } - if ((dap->da_state & MKDIR_PARENT) || - (pagedep->pd_state & NEWBLOCK)) - flushparent = 1; - else - flushparent = 0; - /* - * If we are being fsync'ed as part of vgone'ing this vnode, - * then we will not be able to release and recover the - * vnode below, so we just have to give up on writing its - * directory entry out. It will eventually be written, just - * not now, but then the user was not asking to have it - * written, so we are not breaking any promises. - */ - mtx_enter(&vnode_mtx); - if (vp->v_lflag & VXLOCK) { - mtx_leave(&vnode_mtx); - break; - } - mtx_leave(&vnode_mtx); - /* - * We prevent deadlock by always fetching inodes from the - * root, moving down the directory tree. Thus, when fetching - * our parent directory, we must unlock ourselves before - * requesting the lock on our parent. See the comment in - * ufs_lookup for details on possible races. - */ - FREE_LOCK(&lk); - VOP_UNLOCK(vp); - error = VFS_VGET(mnt, parentino, &pvp); - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - if (error != 0) - return (error); - /* - * All MKDIR_PARENT dependencies and all the NEWBLOCK pagedeps - * that are contained in direct blocks will be resolved by - * doing a UFS_UPDATE. Pagedeps contained in indirect blocks - * may require a complete sync'ing of the directory. So, we - * try the cheap and fast UFS_UPDATE first, and if that fails, - * then we do the slower VOP_FSYNC of the directory. - */ - pip = VTOI(pvp); - if (flushparent) { - error = UFS_UPDATE(pip, 1); - if (error) { - vput(pvp); - return (error); - } - if (pagedep->pd_state & NEWBLOCK) { - error = VOP_FSYNC(pvp, p->p_ucred, MNT_WAIT, p); - if (error) { - vput(pvp); - return (error); - } - } - } - /* - * Flush directory page containing the inode's name. - */ - error = bread(pvp, lbn, fs->fs_bsize, &bp); - if (error == 0) { - bp->b_bcount = blksize(fs, pip, lbn); - error = bwrite(bp); - } else - brelse(bp); - vput(pvp); - if (error != 0) - return (error); - ACQUIRE_LOCK(&lk); - if (inodedep_lookup(fs, ip->i_number, 0, &inodedep) == 0) - break; - } - FREE_LOCK(&lk); - return (0); -} - -/* - * Flush all the dirty bitmaps associated with the block device - * before flushing the rest of the dirty blocks so as to reduce - * the number of dependencies that will have to be rolled back. - */ -void -softdep_fsync_mountdev(struct vnode *vp, int waitfor) -{ - struct buf *bp, *nbp; - struct worklist *wk; - - if (!vn_isdisk(vp, NULL)) - panic("softdep_fsync_mountdev: vnode not a disk"); - ACQUIRE_LOCK(&lk); - LIST_FOREACH_SAFE(bp, &vp->v_dirtyblkhd, b_vnbufs, nbp) { - /* - * If it is already scheduled, skip to the next buffer. - */ - splassert(IPL_BIO); - if (bp->b_flags & B_BUSY) - continue; - - if ((bp->b_flags & B_DELWRI) == 0) { - FREE_LOCK(&lk); - panic("softdep_fsync_mountdev: not dirty"); - } - /* - * We are only interested in bitmaps with outstanding - * dependencies. - */ - if ((wk = LIST_FIRST(&bp->b_dep)) == NULL || - wk->wk_type != D_BMSAFEMAP) { - continue; - } - bremfree(bp); - buf_acquire(bp); - FREE_LOCK(&lk); - (void) bawrite(bp); - ACQUIRE_LOCK(&lk); - /* - * Since we may have slept during the I/O, we need - * to start from a known point. - */ - nbp = LIST_FIRST(&vp->v_dirtyblkhd); - } - if (waitfor == MNT_WAIT) - drain_output(vp, 1); - FREE_LOCK(&lk); -} - -/* - * This routine is called when we are trying to synchronously flush a - * file. This routine must eliminate any filesystem metadata dependencies - * so that the syncing routine can succeed by pushing the dirty blocks - * associated with the file. If any I/O errors occur, they are returned. - */ -int -softdep_sync_metadata(struct vop_fsync_args *ap) -{ - struct vnode *vp = ap->a_vp; - struct pagedep *pagedep; - struct allocdirect *adp; - struct allocindir *aip; - struct buf *bp, *nbp; - struct worklist *wk; - int i, gotit, error, waitfor; - - /* - * Check whether this vnode is involved in a filesystem - * that is doing soft dependency processing. - */ - if (!vn_isdisk(vp, NULL)) { - if (!DOINGSOFTDEP(vp)) - return (0); - } else - if (vp->v_specmountpoint == NULL || - (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP) == 0) - return (0); - /* - * Ensure that any direct block dependencies have been cleared. - */ - ACQUIRE_LOCK(&lk); - if ((error = flush_inodedep_deps(VTOI(vp)->i_fs, VTOI(vp)->i_number))) { - FREE_LOCK(&lk); - return (error); - } - /* - * For most files, the only metadata dependencies are the - * cylinder group maps that allocate their inode or blocks. - * The block allocation dependencies can be found by traversing - * the dependency lists for any buffers that remain on their - * dirty buffer list. The inode allocation dependency will - * be resolved when the inode is updated with MNT_WAIT. - * This work is done in two passes. The first pass grabs most - * of the buffers and begins asynchronously writing them. The - * only way to wait for these asynchronous writes is to sleep - * on the filesystem vnode which may stay busy for a long time - * if the filesystem is active. So, instead, we make a second - * pass over the dependencies blocking on each write. In the - * usual case we will be blocking against a write that we - * initiated, so when it is done the dependency will have been - * resolved. Thus the second pass is expected to end quickly. - */ - waitfor = MNT_NOWAIT; -top: - /* - * We must wait for any I/O in progress to finish so that - * all potential buffers on the dirty list will be visible. - */ - drain_output(vp, 1); - bp = LIST_FIRST(&vp->v_dirtyblkhd); - gotit = getdirtybuf(bp, MNT_WAIT); - if (gotit == 0) { - FREE_LOCK(&lk); - return (0); - } else if (gotit == -1) - goto top; -loop: - /* - * As we hold the buffer locked, none of its dependencies - * will disappear. - */ - LIST_FOREACH(wk, &bp->b_dep, wk_list) { - switch (wk->wk_type) { - - case D_ALLOCDIRECT: - adp = WK_ALLOCDIRECT(wk); - if (adp->ad_state & DEPCOMPLETE) - break; - nbp = adp->ad_buf; - gotit = getdirtybuf(nbp, waitfor); - if (gotit == 0) - break; - else if (gotit == -1) - goto loop; - FREE_LOCK(&lk); - if (waitfor == MNT_NOWAIT) { - bawrite(nbp); - } else if ((error = VOP_BWRITE(nbp)) != 0) { - bawrite(bp); - return (error); - } - ACQUIRE_LOCK(&lk); - break; - - case D_ALLOCINDIR: - aip = WK_ALLOCINDIR(wk); - if (aip->ai_state & DEPCOMPLETE) - break; - nbp = aip->ai_buf; - gotit = getdirtybuf(nbp, waitfor); - if (gotit == 0) - break; - else if (gotit == -1) - goto loop; - FREE_LOCK(&lk); - if (waitfor == MNT_NOWAIT) { - bawrite(nbp); - } else if ((error = VOP_BWRITE(nbp)) != 0) { - bawrite(bp); - return (error); - } - ACQUIRE_LOCK(&lk); - break; - - case D_INDIRDEP: - restart: - - LIST_FOREACH(aip, &WK_INDIRDEP(wk)->ir_deplisthd, ai_next) { - if (aip->ai_state & DEPCOMPLETE) - continue; - nbp = aip->ai_buf; - if (getdirtybuf(nbp, MNT_WAIT) <= 0) - goto restart; - FREE_LOCK(&lk); - if ((error = VOP_BWRITE(nbp)) != 0) { - bawrite(bp); - return (error); - } - ACQUIRE_LOCK(&lk); - goto restart; - } - break; - - case D_INODEDEP: - if ((error = flush_inodedep_deps(WK_INODEDEP(wk)->id_fs, - WK_INODEDEP(wk)->id_ino)) != 0) { - FREE_LOCK(&lk); - bawrite(bp); - return (error); - } - break; - - case D_PAGEDEP: - /* - * We are trying to sync a directory that may - * have dependencies on both its own metadata - * and/or dependencies on the inodes of any - * recently allocated files. We walk its diradd - * lists pushing out the associated inode. - */ - pagedep = WK_PAGEDEP(wk); - for (i = 0; i < DAHASHSZ; i++) { - if (LIST_FIRST(&pagedep->pd_diraddhd[i]) == - NULL) - continue; - if ((error = - flush_pagedep_deps(vp, pagedep->pd_mnt, - &pagedep->pd_diraddhd[i]))) { - FREE_LOCK(&lk); - bawrite(bp); - return (error); - } - } - break; - - case D_MKDIR: - /* - * This case should never happen if the vnode has - * been properly sync'ed. However, if this function - * is used at a place where the vnode has not yet - * been sync'ed, this dependency can show up. So, - * rather than panic, just flush it. - */ - nbp = WK_MKDIR(wk)->md_buf; - KASSERT(bp != nbp); - gotit = getdirtybuf(nbp, waitfor); - if (gotit == 0) - break; - else if (gotit == -1) - goto loop; - FREE_LOCK(&lk); - if (waitfor == MNT_NOWAIT) { - bawrite(nbp); - } else if ((error = VOP_BWRITE(nbp)) != 0) { - bawrite(bp); - return (error); - } - ACQUIRE_LOCK(&lk); - break; - - case D_BMSAFEMAP: - /* - * This case should never happen if the vnode has - * been properly sync'ed. However, if this function - * is used at a place where the vnode has not yet - * been sync'ed, this dependency can show up. So, - * rather than panic, just flush it. - */ - nbp = WK_BMSAFEMAP(wk)->sm_buf; - if (bp == nbp) - break; - gotit = getdirtybuf(nbp, waitfor); - if (gotit == 0) - break; - else if (gotit == -1) - goto loop; - FREE_LOCK(&lk); - if (waitfor == MNT_NOWAIT) { - bawrite(nbp); - } else if ((error = VOP_BWRITE(nbp)) != 0) { - bawrite(bp); - return (error); - } - ACQUIRE_LOCK(&lk); - break; - - default: - FREE_LOCK(&lk); - panic("softdep_sync_metadata: Unknown type %s", - TYPENAME(wk->wk_type)); - /* NOTREACHED */ - } - } - do { - nbp = LIST_NEXT(bp, b_vnbufs); - gotit = getdirtybuf(nbp, MNT_WAIT); - } while (gotit == -1); - FREE_LOCK(&lk); - bawrite(bp); - ACQUIRE_LOCK(&lk); - if (nbp != NULL) { - bp = nbp; - goto loop; - } - /* - * The brief unlock is to allow any pent up dependency - * processing to be done. Then proceed with the second pass. - */ - if (waitfor == MNT_NOWAIT) { - waitfor = MNT_WAIT; - FREE_LOCK(&lk); - ACQUIRE_LOCK(&lk); - goto top; - } - - /* - * If we have managed to get rid of all the dirty buffers, - * then we are done. For certain directories and block - * devices, we may need to do further work. - * - * We must wait for any I/O in progress to finish so that - * all potential buffers on the dirty list will be visible. - */ - drain_output(vp, 1); - if (LIST_EMPTY(&vp->v_dirtyblkhd)) { - FREE_LOCK(&lk); - return (0); - } - - FREE_LOCK(&lk); - /* - * If we are trying to sync a block device, some of its buffers may - * contain metadata that cannot be written until the contents of some - * partially written files have been written to disk. The only easy - * way to accomplish this is to sync the entire filesystem (luckily - * this happens rarely). - */ - if (vn_isdisk(vp, NULL) && - vp->v_specmountpoint && !VOP_ISLOCKED(vp) && - (error = VFS_SYNC(vp->v_specmountpoint, MNT_WAIT, 0, ap->a_cred, - ap->a_p)) != 0) - return (error); - return (0); -} - -/* - * Flush the dependencies associated with an inodedep. - * Called with splbio blocked. - */ -STATIC int -flush_inodedep_deps(struct fs *fs, ufsino_t ino) -{ - struct inodedep *inodedep; - struct allocdirect *adp; - int gotit, error, waitfor; - struct buf *bp; - - splassert(IPL_BIO); - - /* - * This work is done in two passes. The first pass grabs most - * of the buffers and begins asynchronously writing them. The - * only way to wait for these asynchronous writes is to sleep - * on the filesystem vnode which may stay busy for a long time - * if the filesystem is active. So, instead, we make a second - * pass over the dependencies blocking on each write. In the - * usual case we will be blocking against a write that we - * initiated, so when it is done the dependency will have been - * resolved. Thus the second pass is expected to end quickly. - * We give a brief window at the top of the loop to allow - * any pending I/O to complete. - */ - for (waitfor = MNT_NOWAIT; ; ) { - retry_ino: - FREE_LOCK(&lk); - ACQUIRE_LOCK(&lk); - if (inodedep_lookup(fs, ino, 0, &inodedep) == 0) - return (0); - TAILQ_FOREACH(adp, &inodedep->id_inoupdt, ad_next) { - if (adp->ad_state & DEPCOMPLETE) - continue; - bp = adp->ad_buf; - gotit = getdirtybuf(bp, waitfor); - if (gotit == 0) { - if (waitfor == MNT_NOWAIT) - continue; - break; - } else if (gotit == -1) - goto retry_ino; - FREE_LOCK(&lk); - if (waitfor == MNT_NOWAIT) { - bawrite(bp); - } else if ((error = VOP_BWRITE(bp)) != 0) { - ACQUIRE_LOCK(&lk); - return (error); - } - ACQUIRE_LOCK(&lk); - break; - } - if (adp != NULL) - continue; - retry_newino: - TAILQ_FOREACH(adp, &inodedep->id_newinoupdt, ad_next) { - if (adp->ad_state & DEPCOMPLETE) - continue; - bp = adp->ad_buf; - gotit = getdirtybuf(bp, waitfor); - if (gotit == 0) { - if (waitfor == MNT_NOWAIT) - continue; - break; - } else if (gotit == -1) - goto retry_newino; - FREE_LOCK(&lk); - if (waitfor == MNT_NOWAIT) { - bawrite(bp); - } else if ((error = VOP_BWRITE(bp)) != 0) { - ACQUIRE_LOCK(&lk); - return (error); - } - ACQUIRE_LOCK(&lk); - break; - } - if (adp != NULL) - continue; - /* - * If pass2, we are done, otherwise do pass 2. - */ - if (waitfor == MNT_WAIT) - break; - waitfor = MNT_WAIT; - } - /* - * Try freeing inodedep in case all dependencies have been removed. - */ - if (inodedep_lookup(fs, ino, 0, &inodedep) != 0) - (void) free_inodedep(inodedep); - return (0); -} - -/* - * Eliminate a pagedep dependency by flushing out all its diradd dependencies. - * Called with splbio blocked. - */ -STATIC int -flush_pagedep_deps(struct vnode *pvp, struct mount *mp, - struct diraddhd *diraddhdp) -{ - struct proc *p = CURPROC; /* XXX */ - struct worklist *wk; - struct inodedep *inodedep; - struct ufsmount *ump; - struct diradd *dap; - struct vnode *vp; - int gotit, error = 0; - struct buf *bp; - ufsino_t inum; - - splassert(IPL_BIO); - - ump = VFSTOUFS(mp); - while ((dap = LIST_FIRST(diraddhdp)) != NULL) { - /* - * Flush ourselves if this directory entry - * has a MKDIR_PARENT dependency. - */ - if (dap->da_state & MKDIR_PARENT) { - FREE_LOCK(&lk); - if ((error = UFS_UPDATE(VTOI(pvp), 1))) - break; - ACQUIRE_LOCK(&lk); - /* - * If that cleared dependencies, go on to next. - */ - if (dap != LIST_FIRST(diraddhdp)) - continue; - if (dap->da_state & MKDIR_PARENT) { - FREE_LOCK(&lk); - panic("flush_pagedep_deps: MKDIR_PARENT"); - } - } - /* - * A newly allocated directory must have its "." and - * ".." entries written out before its name can be - * committed in its parent. We do not want or need - * the full semantics of a synchronous VOP_FSYNC as - * that may end up here again, once for each directory - * level in the filesystem. Instead, we push the blocks - * and wait for them to clear. We have to fsync twice - * because the first call may choose to defer blocks - * that still have dependencies, but deferral will - * happen at most once. - */ - inum = dap->da_newinum; - if (dap->da_state & MKDIR_BODY) { - FREE_LOCK(&lk); - if ((error = VFS_VGET(mp, inum, &vp)) != 0) - break; - if ((error=VOP_FSYNC(vp, p->p_ucred, MNT_NOWAIT, p)) || - (error=VOP_FSYNC(vp, p->p_ucred, MNT_NOWAIT, p))) { - vput(vp); - break; - } - drain_output(vp, 0); - /* - * If first block is still dirty with a D_MKDIR - * dependency then it needs to be written now. - */ - for (;;) { - error = 0; - ACQUIRE_LOCK(&lk); - bp = incore(vp, 0); - if (bp == NULL) { - FREE_LOCK(&lk); - break; - } - LIST_FOREACH(wk, &bp->b_dep, wk_list) - if (wk->wk_type == D_MKDIR) - break; - if (wk) { - gotit = getdirtybuf(bp, MNT_WAIT); - FREE_LOCK(&lk); - if (gotit == -1) - continue; - if (gotit && (error = bwrite(bp)) != 0) - break; - } else - FREE_LOCK(&lk); - break; - } - vput(vp); - /* Flushing of first block failed */ - if (error) - break; - ACQUIRE_LOCK(&lk); - /* - * If that cleared dependencies, go on to next. - */ - if (dap != LIST_FIRST(diraddhdp)) - continue; - if (dap->da_state & MKDIR_BODY) { - FREE_LOCK(&lk); - panic("flush_pagedep_deps: MKDIR_BODY"); - } - } - /* - * Flush the inode on which the directory entry depends. - * Having accounted for MKDIR_PARENT and MKDIR_BODY above, - * the only remaining dependency is that the updated inode - * count must get pushed to disk. The inode has already - * been pushed into its inode buffer (via VOP_UPDATE) at - * the time of the reference count change. So we need only - * locate that buffer, ensure that there will be no rollback - * caused by a bitmap dependency, then write the inode buffer. - */ - if (inodedep_lookup(ump->um_fs, inum, 0, &inodedep) == 0) { - FREE_LOCK(&lk); - panic("flush_pagedep_deps: lost inode"); - } - /* - * If the inode still has bitmap dependencies, - * push them to disk. - */ - retry: - if ((inodedep->id_state & DEPCOMPLETE) == 0) { - bp = inodedep->id_buf; - gotit = getdirtybuf(bp, MNT_WAIT); - if (gotit == -1) - goto retry; - FREE_LOCK(&lk); - if (gotit && (error = bwrite(bp)) != 0) - break; - ACQUIRE_LOCK(&lk); - if (dap != LIST_FIRST(diraddhdp)) - continue; - } - /* - * If the inode is still sitting in a buffer waiting - * to be written, push it to disk. - */ - FREE_LOCK(&lk); - if ((error = bread(ump->um_devvp, - fsbtodb(ump->um_fs, ino_to_fsba(ump->um_fs, inum)), - (int)ump->um_fs->fs_bsize, &bp)) != 0) { - brelse(bp); - break; - } - if ((error = bwrite(bp)) != 0) - break; - ACQUIRE_LOCK(&lk); - /* - * If we have failed to get rid of all the dependencies - * then something is seriously wrong. - */ - if (dap == LIST_FIRST(diraddhdp)) { - FREE_LOCK(&lk); - panic("flush_pagedep_deps: flush failed"); - } - } - if (error) - ACQUIRE_LOCK(&lk); - return (error); -} - -/* - * A large burst of file addition or deletion activity can drive the - * memory load excessively high. First attempt to slow things down - * using the techniques below. If that fails, this routine requests - * the offending operations to fall back to running synchronously - * until the memory load returns to a reasonable level. - */ -int -softdep_slowdown(struct vnode *vp) -{ - int max_softdeps_hard; - - max_softdeps_hard = max_softdeps * 11 / 10; - if (num_dirrem < max_softdeps_hard / 2 && - num_inodedep < max_softdeps_hard) - return (0); - stat_sync_limit_hit += 1; - return (1); -} - -/* - * If memory utilization has gotten too high, deliberately slow things - * down and speed up the I/O processing. - */ -STATIC int -request_cleanup(int resource, int islocked) -{ - struct proc *p = CURPROC; - int s; - - /* - * We never hold up the filesystem syncer process. - */ - if (p == filesys_syncer || (p->p_flag & P_SOFTDEP)) - return (0); - /* - * First check to see if the work list has gotten backlogged. - * If it has, co-opt this process to help clean up two entries. - * Because this process may hold inodes locked, we cannot - * handle any remove requests that might block on a locked - * inode as that could lead to deadlock. We set P_SOFTDEP - * to avoid recursively processing the worklist. - */ - if (num_on_worklist > max_softdeps / 10) { - atomic_setbits_int(&p->p_flag, P_SOFTDEP); - if (islocked) - FREE_LOCK(&lk); - process_worklist_item(NULL, NULL, LK_NOWAIT); - process_worklist_item(NULL, NULL, LK_NOWAIT); - atomic_clearbits_int(&p->p_flag, P_SOFTDEP); - stat_worklist_push += 2; - if (islocked) - ACQUIRE_LOCK(&lk); - return(1); - } - /* - * Next, we attempt to speed up the syncer process. If that - * is successful, then we allow the process to continue. - */ - if (speedup_syncer()) - return(0); - /* - * If we are resource constrained on inode dependencies, try - * flushing some dirty inodes. Otherwise, we are constrained - * by file deletions, so try accelerating flushes of directories - * with removal dependencies. We would like to do the cleanup - * here, but we probably hold an inode locked at this point and - * that might deadlock against one that we try to clean. So, - * the best that we can do is request the syncer daemon to do - * the cleanup for us. - */ - switch (resource) { - - case FLUSH_INODES: - stat_ino_limit_push += 1; - req_clear_inodedeps += 1; - stat_countp = &stat_ino_limit_hit; - break; - - case FLUSH_REMOVE: - stat_blk_limit_push += 1; - req_clear_remove += 1; - stat_countp = &stat_blk_limit_hit; - break; - - default: - if (islocked) - FREE_LOCK(&lk); - panic("request_cleanup: unknown type"); - } - /* - * Hopefully the syncer daemon will catch up and awaken us. - * We wait at most tickdelay before proceeding in any case. - */ - if (islocked == 0) - ACQUIRE_LOCK(&lk); - proc_waiting += 1; - if (!timeout_pending(&proc_waiting_timeout)) - timeout_add(&proc_waiting_timeout, tickdelay > 2 ? tickdelay : 2); - - s = FREE_LOCK_INTERLOCKED(&lk); - tsleep_nsec(&proc_waiting, PPAUSE, "softupdate", INFSLP); - ACQUIRE_LOCK_INTERLOCKED(&lk, s); - proc_waiting -= 1; - if (islocked == 0) - FREE_LOCK(&lk); - return (1); -} - -/* - * Awaken processes pausing in request_cleanup and clear proc_waiting - * to indicate that there is no longer a timer running. - */ -void -pause_timer(void *arg) -{ - - *stat_countp += 1; - wakeup_one(&proc_waiting); - if (proc_waiting > 0) - timeout_add(&proc_waiting_timeout, tickdelay > 2 ? tickdelay : 2); -} - -/* - * Flush out a directory with at least one removal dependency in an effort to - * reduce the number of dirrem, freefile, and freeblks dependency structures. - */ -STATIC void -clear_remove(struct proc *p) -{ - struct pagedep_hashhead *pagedephd; - struct pagedep *pagedep; - static int next = 0; - struct mount *mp; - struct vnode *vp; - int error, cnt; - ufsino_t ino; - - ACQUIRE_LOCK(&lk); - for (cnt = 0; cnt <= pagedep_hash; cnt++) { - pagedephd = &pagedep_hashtbl[next++]; - if (next > pagedep_hash) - next = 0; - LIST_FOREACH(pagedep, pagedephd, pd_hash) { - if (LIST_FIRST(&pagedep->pd_dirremhd) == NULL) - continue; - mp = pagedep->pd_mnt; - ino = pagedep->pd_ino; -#if 0 - if (vn_start_write(NULL, &mp, V_NOWAIT) != 0) - continue; -#endif - FREE_LOCK(&lk); - if ((error = VFS_VGET(mp, ino, &vp)) != 0) { - softdep_error("clear_remove: vget", error); -#if 0 - vn_finished_write(mp); -#endif - return; - } - if ((error = VOP_FSYNC(vp, p->p_ucred, MNT_NOWAIT, p))) - softdep_error("clear_remove: fsync", error); - drain_output(vp, 0); - vput(vp); -#if 0 - vn_finished_write(mp); -#endif - return; - } - } - FREE_LOCK(&lk); -} - -/* - * Clear out a block of dirty inodes in an effort to reduce - * the number of inodedep dependency structures. - */ -STATIC void -clear_inodedeps(struct proc *p) -{ - struct inodedep_hashhead *inodedephd; - struct inodedep *inodedep = NULL; - static int next = 0; - struct mount *mp; - struct vnode *vp; - struct fs *fs; - int error, cnt; - ufsino_t firstino, lastino, ino; - - ACQUIRE_LOCK(&lk); - /* - * Pick a random inode dependency to be cleared. - * We will then gather up all the inodes in its block - * that have dependencies and flush them out. - */ - for (cnt = 0; cnt <= inodedep_hash; cnt++) { - inodedephd = &inodedep_hashtbl[next++]; - if (next > inodedep_hash) - next = 0; - if ((inodedep = LIST_FIRST(inodedephd)) != NULL) - break; - } - if (inodedep == NULL) { - FREE_LOCK(&lk); - return; - } - /* - * Ugly code to find mount point given pointer to superblock. - */ - fs = inodedep->id_fs; - TAILQ_FOREACH(mp, &mountlist, mnt_list) - if ((mp->mnt_flag & MNT_SOFTDEP) && fs == VFSTOUFS(mp)->um_fs) - break; - /* - * Find the last inode in the block with dependencies. - */ - firstino = inodedep->id_ino & ~(INOPB(fs) - 1); - for (lastino = firstino + INOPB(fs) - 1; lastino > firstino; lastino--) - if (inodedep_lookup(fs, lastino, 0, &inodedep) != 0) - break; - /* - * Asynchronously push all but the last inode with dependencies. - * Synchronously push the last inode with dependencies to ensure - * that the inode block gets written to free up the inodedeps. - */ - for (ino = firstino; ino <= lastino; ino++) { - if (inodedep_lookup(fs, ino, 0, &inodedep) == 0) - continue; - FREE_LOCK(&lk); -#if 0 - if (vn_start_write(NULL, &mp, V_NOWAIT) != 0) - continue; -#endif - if ((error = VFS_VGET(mp, ino, &vp)) != 0) { - softdep_error("clear_inodedeps: vget", error); -#if 0 - vn_finished_write(mp); -#endif - return; - } - if (ino == lastino) { - if ((error = VOP_FSYNC(vp, p->p_ucred, MNT_WAIT, p))) - softdep_error("clear_inodedeps: fsync1", error); - } else { - if ((error = VOP_FSYNC(vp, p->p_ucred, MNT_NOWAIT, p))) - softdep_error("clear_inodedeps: fsync2", error); - drain_output(vp, 0); - } - vput(vp); -#if 0 - vn_finished_write(mp); -#endif - ACQUIRE_LOCK(&lk); - } - FREE_LOCK(&lk); -} - -/* - * Function to determine if the buffer has outstanding dependencies - * that will cause a roll-back if the buffer is written. If wantcount - * is set, return number of dependencies, otherwise just yes or no. - */ -int -softdep_count_dependencies(struct buf *bp, int wantcount, int islocked) -{ - struct worklist *wk; - struct inodedep *inodedep; - struct indirdep *indirdep; - struct allocindir *aip; - struct pagedep *pagedep; - struct diradd *dap; - int i, retval; - - retval = 0; - if (!islocked) - ACQUIRE_LOCK(&lk); - LIST_FOREACH(wk, &bp->b_dep, wk_list) { - switch (wk->wk_type) { - - case D_INODEDEP: - inodedep = WK_INODEDEP(wk); - if ((inodedep->id_state & DEPCOMPLETE) == 0) { - /* bitmap allocation dependency */ - retval += 1; - if (!wantcount) - goto out; - } - if (TAILQ_FIRST(&inodedep->id_inoupdt)) { - /* direct block pointer dependency */ - retval += 1; - if (!wantcount) - goto out; - } - continue; - - case D_INDIRDEP: - indirdep = WK_INDIRDEP(wk); - - LIST_FOREACH(aip, &indirdep->ir_deplisthd, ai_next) { - /* indirect block pointer dependency */ - retval += 1; - if (!wantcount) - goto out; - } - continue; - - case D_PAGEDEP: - pagedep = WK_PAGEDEP(wk); - for (i = 0; i < DAHASHSZ; i++) { - - LIST_FOREACH(dap, &pagedep->pd_diraddhd[i], da_pdlist) { - /* directory entry dependency */ - retval += 1; - if (!wantcount) - goto out; - } - } - continue; - - case D_BMSAFEMAP: - case D_ALLOCDIRECT: - case D_ALLOCINDIR: - case D_MKDIR: - /* never a dependency on these blocks */ - continue; - - default: - if (!islocked) - FREE_LOCK(&lk); - panic("softdep_check_for_rollback: Unexpected type %s", - TYPENAME(wk->wk_type)); - /* NOTREACHED */ - } - } -out: - if (!islocked) - FREE_LOCK(&lk); - return retval; -} - -/* - * Acquire exclusive access to a buffer. - * Must be called with splbio blocked. - * Returns: - * 1 if the buffer was acquired and is dirty; - * 0 if the buffer was clean, or we would have slept but had MN_NOWAIT; - * -1 if we slept and may try again (but not with this bp). - */ -STATIC int -getdirtybuf(struct buf *bp, int waitfor) -{ - int s; - - if (bp == NULL) - return (0); - - splassert(IPL_BIO); - - if (bp->b_flags & B_BUSY) { - if (waitfor != MNT_WAIT) - return (0); - bp->b_flags |= B_WANTED; - s = FREE_LOCK_INTERLOCKED(&lk); - tsleep_nsec(bp, PRIBIO+1, "sdsdty", INFSLP); - ACQUIRE_LOCK_INTERLOCKED(&lk, s); - return (-1); - } - if ((bp->b_flags & B_DELWRI) == 0) - return (0); - bremfree(bp); - buf_acquire(bp); - return (1); -} - -/* - * Wait for pending output on a vnode to complete. - * Must be called with vnode locked. - */ -STATIC void -drain_output(struct vnode *vp, int islocked) -{ - int s; - - if (!islocked) - ACQUIRE_LOCK(&lk); - - splassert(IPL_BIO); - - while (vp->v_numoutput) { - vp->v_bioflag |= VBIOWAIT; - s = FREE_LOCK_INTERLOCKED(&lk); - tsleep_nsec(&vp->v_numoutput, PRIBIO+1, "drain_output", INFSLP); - ACQUIRE_LOCK_INTERLOCKED(&lk, s); - } - if (!islocked) - FREE_LOCK(&lk); -} - -/* - * Called whenever a buffer that is being invalidated or reallocated - * contains dependencies. This should only happen if an I/O error has - * occurred. The routine is called with the buffer locked. - */ -void -softdep_deallocate_dependencies(struct buf *bp) -{ - - if ((bp->b_flags & B_ERROR) == 0) - panic("softdep_deallocate_dependencies: dangling deps"); - softdep_error(bp->b_vp->v_mount->mnt_stat.f_mntonname, bp->b_error); - panic("softdep_deallocate_dependencies: unrecovered I/O error"); -} - -/* - * Function to handle asynchronous write errors in the filesystem. - */ -void -softdep_error(char *func, int error) -{ - - /* XXX should do something better! */ - printf("%s: got error %d while accessing filesystem\n", func, error); -} - -#ifdef DDB -#include -#include -#include - -void -softdep_print(struct buf *bp, int full, - int (*pr)(const char *, ...) __attribute__((__format__(__kprintf__,1,2)))) -{ - struct worklist *wk; - - (*pr)(" deps:\n"); - LIST_FOREACH(wk, &bp->b_dep, wk_list) - worklist_print(wk, full, pr); -} - -void -worklist_print(struct worklist *wk, int full, - int (*pr)(const char *, ...) __attribute__((__format__(__kprintf__,1,2)))) -{ - struct pagedep *pagedep; - struct inodedep *inodedep; - struct newblk *newblk; - struct bmsafemap *bmsafemap; - struct allocdirect *adp; - struct indirdep *indirdep; - struct allocindir *aip; - struct freefrag *freefrag; - struct freeblks *freeblks; - struct freefile *freefile; - struct diradd *dap; - struct mkdir *mkdir; - struct dirrem *dirrem; - struct newdirblk *newdirblk; - char prefix[33]; - int i; - - for (prefix[i = 2 * MIN(16, full)] = '\0'; i--; prefix[i] = ' ') - ; - - (*pr)("%s%s(%p) state %b\n%s", prefix, TYPENAME(wk->wk_type), wk, - wk->wk_state, DEP_BITS, prefix); - switch (wk->wk_type) { - case D_PAGEDEP: - pagedep = WK_PAGEDEP(wk); - (*pr)("mount %p ino %u lbn %lld\n", pagedep->pd_mnt, - pagedep->pd_ino, (long long)pagedep->pd_lbn); - break; - case D_INODEDEP: - inodedep = WK_INODEDEP(wk); - (*pr)("fs %p ino %u nlinkdelta %u dino %p\n" - "%s bp %p savsz %lld\n", inodedep->id_fs, - inodedep->id_ino, inodedep->id_nlinkdelta, - inodedep->id_un.idu_savedino1, - prefix, inodedep->id_buf, inodedep->id_savedsize); - break; - case D_NEWBLK: - newblk = WK_NEWBLK(wk); - (*pr)("fs %p newblk %lld state %d bmsafemap %p\n", - newblk->nb_fs, (long long)newblk->nb_newblkno, - newblk->nb_state, newblk->nb_bmsafemap); - break; - case D_BMSAFEMAP: - bmsafemap = WK_BMSAFEMAP(wk); - (*pr)("buf %p\n", bmsafemap->sm_buf); - break; - case D_ALLOCDIRECT: - adp = WK_ALLOCDIRECT(wk); - (*pr)("lbn %lld newlbk %lld oldblk %lld newsize %ld olsize " - "%ld\n%s bp %p inodedep %p freefrag %p\n", - (long long)adp->ad_lbn, (long long)adp->ad_newblkno, - (long long)adp->ad_oldblkno, adp->ad_newsize, - adp->ad_oldsize, - prefix, adp->ad_buf, adp->ad_inodedep, adp->ad_freefrag); - break; - case D_INDIRDEP: - indirdep = WK_INDIRDEP(wk); - (*pr)("savedata %p savebp %p\n", indirdep->ir_saveddata, - indirdep->ir_savebp); - break; - case D_ALLOCINDIR: - aip = WK_ALLOCINDIR(wk); - (*pr)("off %d newblk %lld oldblk %lld freefrag %p\n" - "%s indirdep %p buf %p\n", aip->ai_offset, - (long long)aip->ai_newblkno, (long long)aip->ai_oldblkno, - aip->ai_freefrag, prefix, aip->ai_indirdep, aip->ai_buf); - break; - case D_FREEFRAG: - freefrag = WK_FREEFRAG(wk); - (*pr)("vnode %p mp %p blkno %lld fsize %ld ino %u\n", - freefrag->ff_devvp, freefrag->ff_mnt, - (long long)freefrag->ff_blkno, freefrag->ff_fragsize, - freefrag->ff_inum); - break; - case D_FREEBLKS: - freeblks = WK_FREEBLKS(wk); - (*pr)("previno %u devvp %p mp %p oldsz %lld newsz %lld\n" - "%s chkcnt %d uid %d\n", freeblks->fb_previousinum, - freeblks->fb_devvp, freeblks->fb_mnt, freeblks->fb_oldsize, - freeblks->fb_newsize, - prefix, freeblks->fb_chkcnt, freeblks->fb_uid); - break; - case D_FREEFILE: - freefile = WK_FREEFILE(wk); - (*pr)("mode %x oldino %u vnode %p mp %p\n", freefile->fx_mode, - freefile->fx_oldinum, freefile->fx_devvp, freefile->fx_mnt); - break; - case D_DIRADD: - dap = WK_DIRADD(wk); - (*pr)("off %d ino %u da_un %p\n", dap->da_offset, - dap->da_newinum, dap->da_un.dau_previous); - break; - case D_MKDIR: - mkdir = WK_MKDIR(wk); - (*pr)("diradd %p bp %p\n", mkdir->md_diradd, mkdir->md_buf); - break; - case D_DIRREM: - dirrem = WK_DIRREM(wk); - (*pr)("mp %p ino %u dm_un %p\n", dirrem->dm_mnt, - dirrem->dm_oldinum, dirrem->dm_un.dmu_pagedep); - break; - case D_NEWDIRBLK: - newdirblk = WK_NEWDIRBLK(wk); - (*pr)("pagedep %p\n", newdirblk->db_pagedep); - break; - } -} -#endif diff --git a/sys/ufs/ffs/ffs_softdep_stub.c b/sys/ufs/ffs/ffs_softdep_stub.c index 6d7a5e3f4..e69de29bb 100644 --- a/sys/ufs/ffs/ffs_softdep_stub.c +++ b/sys/ufs/ffs/ffs_softdep_stub.c @@ -1,193 +0,0 @@ -/* $OpenBSD: ffs_softdep_stub.c,v 1.18 2013/06/11 16:42:18 deraadt Exp $ */ - -/* - * Copyright 1998 Marshall Kirk McKusick. All Rights Reserved. - * - * The soft updates code is derived from the appendix of a University - * of Michigan technical report (Gregory R. Ganger and Yale N. Patt, - * "Soft Updates: A Solution to the Metadata Update Problem in File - * Systems", CSE-TR-254-95, August 1995). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. None of the names of McKusick, Ganger, or the University of Michigan - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY MARSHALL KIRK MCKUSICK ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL MARSHALL KIRK MCKUSICK BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)ffs_softdep_stub.c 9.1 (McKusick) 7/10/97 - * $FreeBSD: src/sys/ufs/ffs/ffs_softdep_stub.c,v 1.14 2000/08/09 00:41:54 tegge Exp $ - */ - -#ifndef FFS_SOFTUPDATES - -#include -#include -#include -#include -#include -#include -#include - -int -softdep_flushfiles(struct mount *oldmnt, int flags, struct proc *p) -{ - panic("softdep_flushfiles called"); -} - -int -softdep_mount(struct vnode *devvp, struct mount *mp, struct fs *fs, - struct ucred *cred) -{ - return (0); -} - -void -softdep_initialize(void) -{ - return; -} - -#ifndef __OPTIMIZE__ - -void -softdep_setup_inomapdep(struct buf *bp, struct inode *ip, ufsino_t newinum) -{ - panic("softdep_setup_inomapdep called"); -} - -void -softdep_setup_blkmapdep(struct buf *bp, struct fs *fs, daddr_t newblkno) -{ - panic("softdep_setup_blkmapdep called"); -} - -void -softdep_setup_allocdirect(struct inode *ip, daddr_t lbn, daddr_t newblkno, - daddr_t oldblkno, long newsize, long oldsize, struct buf *bp) -{ - panic("softdep_setup_allocdirect called"); -} - -void -softdep_setup_allocindir_page(struct inode *ip, daddr_t lbn, struct buf *bp, - int ptrno, daddr_t newblkno, daddr_t oldblkno, struct buf *nbp) -{ - panic("softdep_setup_allocindir_page called"); -} - -void -softdep_setup_allocindir_meta(struct buf *nbp, struct inode *ip, - struct buf *bp, int ptrno, daddr_t newblkno) -{ - panic("softdep_setup_allocindir_meta called"); -} - -void -softdep_setup_freeblocks(struct inode *ip, off_t length) -{ - panic("softdep_setup_freeblocks called"); -} - -void -softdep_freefile(struct vnode *pvp, ufsino_t ino, mode_t mode) -{ - panic("softdep_freefile called"); -} - -int -softdep_setup_directory_add(struct buf *bp, struct inode *dp, off_t diroffset, - long newinum, struct buf *newdirbp, int isnewblk) -{ - panic("softdep_setup_directory_add called"); - return (0); -} - -void -softdep_change_directoryentry_offset(struct inode *dp, caddr_t base, - caddr_t oldloc, caddr_t newloc, int entrysize) -{ - panic("softdep_change_directoryentry_offset called"); -} - -void -softdep_setup_remove(struct buf *bp, struct inode *dp, struct inode *ip, - int isrmdir) -{ - panic("softdep_setup_remove called"); -} - -void -softdep_setup_directory_change(struct buf *bp, struct inode *dp, - struct inode *ip, long newinum, int isrmdir) -{ - panic("softdep_setup_directory_change called"); -} - -void -softdep_change_linkcnt(struct inode *ip, int nodelay) -{ - panic("softdep_change_linkcnt called"); -} - -void -softdep_load_inodeblock(struct inode *ip) -{ - panic("softdep_load_inodeblock called"); -} - -void -softdep_update_inodeblock(struct inode *ip, struct buf *bp, int waitfor) -{ - panic("softdep_update_inodeblock called"); -} - -#endif - -void -softdep_fsync_mountdev(struct vnode *vp, int waitfor) -{ - return; -} - -int -softdep_flushworklist(struct mount *oldmnt, int *countp, struct proc *p) -{ - *countp = 0; - return (0); -} - -int -softdep_sync_metadata(struct vop_fsync_args *ap) -{ - return (0); -} - -#ifndef __OPTIMIZE__ - -int -softdep_slowdown(struct vnode *vp) -{ - panic("softdep_slowdown called"); -} - -#endif - -#endif /* !FFS_SOFTUPDATES */ diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index f75925e77..313f9f222 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_vfsops.c,v 1.197 2024/01/19 18:58:17 deraadt Exp $ */ +/* $OpenBSD: ffs_vfsops.c,v 1.198 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: ffs_vfsops.c,v 1.19 1996/02/09 22:22:26 christos Exp $ */ /* @@ -213,20 +213,6 @@ ffs_mount(struct mount *mp, const char *path, void *data, int error = 0, flags; int ronly; - /* Ask not for whom the bell tolls */ - if (mp->mnt_flag & MNT_SOFTDEP) { - mp->mnt_flag &= ~MNT_SOFTDEP; - } - - /* - * Soft updates is incompatible with "async", - * so if we are doing softupdates stop the user - * from setting the async flag. - */ - if ((mp->mnt_flag & (MNT_SOFTDEP | MNT_ASYNC)) == - (MNT_SOFTDEP | MNT_ASYNC)) { - return (EINVAL); - } /* * If updating, check whether changing from read-only to * read/write; if there is no device name, that's all we do. @@ -238,16 +224,6 @@ ffs_mount(struct mount *mp, const char *path, void *data, error = 0; ronly = fs->fs_ronly; - /* - * Soft updates won't be set if read/write, - * so "async" will be illegal. - */ - if (ronly == 0 && (mp->mnt_flag & MNT_ASYNC) && - (fs->fs_flags & FS_DOSOFTDEP)) { - error = EINVAL; - goto error_1; - } - if (ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { /* Flush any dirty data */ VFS_SYNC(mp, MNT_WAIT, 0, p->p_ucred, p); @@ -260,46 +236,11 @@ ffs_mount(struct mount *mp, const char *path, void *data, flags |= IGNORECLEAN; if (mp->mnt_flag & MNT_FORCE) flags |= FORCECLOSE; - if (fs->fs_flags & FS_DOSOFTDEP) { - error = softdep_flushfiles(mp, flags, p); - mp->mnt_flag &= ~MNT_SOFTDEP; - } else - error = ffs_flushfiles(mp, flags, p); + error = ffs_flushfiles(mp, flags, p); mp->mnt_flag |= MNT_RDONLY; ronly = 1; } - /* - * Flush soft dependencies if disabling it via an update - * mount. This may leave some items to be processed, - * so don't do this yet XXX. - */ - if ((fs->fs_flags & FS_DOSOFTDEP) && - !(mp->mnt_flag & MNT_SOFTDEP) && - !(mp->mnt_flag & MNT_RDONLY) && fs->fs_ronly == 0) { -#if 0 - flags = WRITECLOSE; - if (mp->mnt_flag & MNT_FORCE) - flags |= FORCECLOSE; - error = softdep_flushfiles(mp, flags, p); -#endif - } - /* - * When upgrading to a softdep mount, we must first flush - * all vnodes. (not done yet -- see above) - */ - if (!(fs->fs_flags & FS_DOSOFTDEP) && - (mp->mnt_flag & MNT_SOFTDEP) && fs->fs_ronly == 0) { -#if 0 - flags = WRITECLOSE; - if (mp->mnt_flag & MNT_FORCE) - flags |= FORCECLOSE; - error = ffs_flushfiles(mp, flags, p); -#else - mp->mnt_flag &= ~MNT_SOFTDEP; -#endif - } - if (!error && (mp->mnt_flag & MNT_RELOAD)) error = ffs_reload(mp, ndp->ni_cnd.cn_cred, p); if (error) @@ -307,19 +248,6 @@ ffs_mount(struct mount *mp, const char *path, void *data, if (ronly && (mp->mnt_flag & MNT_WANTRDWR)) { if (fs->fs_clean == 0) { -#if 0 - /* - * It is safe to mount an unclean file system - * if it was previously mounted with softdep - * but we may lose space and must - * sometimes run fsck manually. - */ - if (fs->fs_flags & FS_DOSOFTDEP) - printf( -"WARNING: %s was not properly unmounted\n", - fs->fs_fsmnt); - else -#endif if (mp->mnt_flag & MNT_FORCE) { printf( "WARNING: %s was not properly unmounted\n", @@ -333,12 +261,6 @@ ffs_mount(struct mount *mp, const char *path, void *data, } } - if ((fs->fs_flags & FS_DOSOFTDEP)) { - error = softdep_mount(devvp, mp, fs, - p->p_ucred); - if (error) - goto error_1; - } fs->fs_contigdirs = malloc((u_long)fs->fs_ncg, M_UFSMNT, M_WAITOK|M_ZERO); @@ -454,9 +376,6 @@ success: if (ronly) free(fs->fs_contigdirs, M_UFSMNT, fs->fs_ncg); } - if (!ronly) { - fs->fs_flags &= ~FS_DOSOFTDEP; - } ffs_sbupdate(ump, MNT_WAIT); #if 0 if (ronly) { @@ -627,8 +546,6 @@ ffs_reload(struct mount *mountp, struct ucred *cred, struct proc *p) space += size; brelse(bp); } - if ((fs->fs_flags & FS_DOSOFTDEP)) - (void) softdep_mount(devvp, mountp, fs, cred); /* * We no longer know anything about clusters per cylinder group. */ @@ -767,19 +684,6 @@ ffs_mountfs(struct vnode *devvp, struct mount *mp, struct proc *p) fs->fs_fmod = 0; fs->fs_flags &= ~FS_UNCLEAN; if (fs->fs_clean == 0) { -#if 0 - /* - * It is safe to mount an unclean file system - * if it was previously mounted with softdep - * but we may lose space and must - * sometimes run fsck manually. - */ - if (fs->fs_flags & FS_DOSOFTDEP) - printf( -"WARNING: %s was not properly unmounted\n", - fs->fs_fsmnt); - else -#endif if (ronly || (mp->mnt_flag & MNT_FORCE)) { printf( "WARNING: %s was not properly unmounted\n", @@ -908,15 +812,8 @@ ffs_mountfs(struct vnode *devvp, struct mount *mp, struct proc *p) if (fs->fs_maxfilesize > maxfilesize) /* XXX */ fs->fs_maxfilesize = maxfilesize; /* XXX */ if (ronly == 0) { - if ((fs->fs_flags & FS_DOSOFTDEP) && - (error = softdep_mount(devvp, mp, fs, cred)) != 0) { - free(fs->fs_csp, M_UFSMNT, 0); - free(fs->fs_contigdirs, M_UFSMNT, fs->fs_ncg); - goto out; - } fs->fs_fmod = 1; fs->fs_clean = 0; - fs->fs_flags &= ~FS_DOSOFTDEP; error = ffs_sbupdate(ump, MNT_WAIT); if (error == EROFS) goto out; @@ -1028,10 +925,7 @@ ffs_unmount(struct mount *mp, int mntflags, struct proc *p) ump = VFSTOUFS(mp); fs = ump->um_fs; - if (mp->mnt_flag & MNT_SOFTDEP) - error = softdep_flushfiles(mp, flags, p); - else - error = ffs_flushfiles(mp, flags, p); + error = ffs_flushfiles(mp, flags, p); if (error != 0) return (error); @@ -1206,7 +1100,7 @@ ffs_sync(struct mount *mp, int waitfor, int stall, struct ucred *cred, struct pr { struct ufsmount *ump = VFSTOUFS(mp); struct fs *fs; - int error, allerror = 0, count, clean, fmod; + int error, allerror = 0, clean, fmod; struct ffs_sync_args fsa; fs = ump->um_fs; @@ -1219,7 +1113,7 @@ ffs_sync(struct mount *mp, int waitfor, int stall, struct ucred *cred, struct pr printf("fs = %s\n", fs->fs_fsmnt); panic("update: rofs mod"); } - loop: + /* * Write back each (modified) inode. */ @@ -1241,13 +1135,6 @@ ffs_sync(struct mount *mp, int waitfor, int stall, struct ucred *cred, struct pr /* * Force stale file system control information to be flushed. */ - if ((ump->um_mountp->mnt_flag & MNT_SOFTDEP) && waitfor == MNT_WAIT) { - if ((error = softdep_flushworklist(ump->um_mountp, &count, p))) - allerror = error; - /* Flushed work items may create new vnodes to clean */ - if (count) - goto loop; - } if (waitfor != MNT_LAZY) { vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); if ((error = VOP_FSYNC(ump->um_devvp, cred, waitfor, p)) != 0) @@ -1387,10 +1274,7 @@ retry: brelse(bp); - if (DOINGSOFTDEP(vp)) - softdep_load_inodeblock(ip); - else - ip->i_effnlink = DIP(ip, nlink); + ip->i_effnlink = DIP(ip, nlink); /* * Initialize the vnode from the inode, check for aliases. @@ -1556,32 +1440,10 @@ ffs_init(struct vfsconf *vfsp) PR_WAITOK, "dino2pl", NULL); #endif - softdep_initialize(); - return (ufs_init(vfsp)); } -#ifdef FFS_SOFTUPDATES -extern int max_softdeps, tickdelay, stat_worklist_push; -extern int stat_blk_limit_push, stat_ino_limit_push, stat_blk_limit_hit; -extern int stat_ino_limit_hit, stat_sync_limit_hit, stat_indir_blk_ptrs; -extern int stat_inode_bitmap, stat_direct_blk_ptrs, stat_dir_entry; -#endif const struct sysctl_bounded_args ffs_vars[] = { -#ifdef FFS_SOFTUPDATES - { FFS_MAX_SOFTDEPS, &max_softdeps, 0, INT_MAX }, - { FFS_SD_TICKDELAY, &tickdelay, 2, INT_MAX }, - { FFS_SD_WORKLIST_PUSH, &stat_worklist_push, SYSCTL_INT_READONLY }, - { FFS_SD_BLK_LIMIT_PUSH, &stat_blk_limit_push, SYSCTL_INT_READONLY }, - { FFS_SD_INO_LIMIT_PUSH, &stat_ino_limit_push, SYSCTL_INT_READONLY }, - { FFS_SD_BLK_LIMIT_HIT, &stat_blk_limit_hit, SYSCTL_INT_READONLY }, - { FFS_SD_INO_LIMIT_HIT, &stat_ino_limit_hit, SYSCTL_INT_READONLY }, - { FFS_SD_SYNC_LIMIT_HIT, &stat_sync_limit_hit, SYSCTL_INT_READONLY }, - { FFS_SD_INDIR_BLK_PTRS, &stat_indir_blk_ptrs, SYSCTL_INT_READONLY }, - { FFS_SD_INODE_BITMAP, &stat_inode_bitmap, SYSCTL_INT_READONLY }, - { FFS_SD_DIRECT_BLK_PTRS, &stat_direct_blk_ptrs, SYSCTL_INT_READONLY }, - { FFS_SD_DIR_ENTRY, &stat_dir_entry, SYSCTL_INT_READONLY }, -#endif #ifdef UFS_DIRHASH { FFS_DIRHASH_DIRSIZE, &ufs_mindirhashsize, 0, INT_MAX }, { FFS_DIRHASH_MAXMEM, &ufs_dirhashmaxmem, 0, INT_MAX }, diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c index 3c68537ed..d5c619d0f 100644 --- a/sys/ufs/ffs/ffs_vnops.c +++ b/sys/ufs/ffs/ffs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_vnops.c,v 1.101 2024/01/09 03:16:00 guenther Exp $ */ +/* $OpenBSD: ffs_vnops.c,v 1.102 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: ffs_vnops.c,v 1.7 1996/05/11 18:27:24 mycroft Exp $ */ /* @@ -420,11 +420,6 @@ ffs_fsync(void *v) struct buf *bp, *nbp; int s, error, passes, skipmeta; - if (vp->v_type == VBLK && - vp->v_specmountpoint != NULL && - (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP)) - softdep_fsync_mountdev(vp, ap->a_waitfor); - /* * Flush all dirty buffers associated with a vnode. */ @@ -452,13 +447,6 @@ loop: panic("ffs_fsync: not dirty"); if (skipmeta && bp->b_lblkno < 0) continue; - if (ap->a_waitfor != MNT_WAIT && - LIST_FIRST(&bp->b_dep) != NULL && - (bp->b_flags & B_DEFERRED) == 0 && - buf_countdeps(bp, 0, 1)) { - bp->b_flags |= B_DEFERRED; - continue; - } bremfree(bp); buf_acquire(bp); @@ -492,8 +480,7 @@ loop: * with the vnode has been written. */ splx(s); - if ((error = softdep_sync_metadata(ap)) != 0) - return (error); + /* XXX softdep was here. reconsider this locking dance */ s = splbio(); if (!LIST_EMPTY(&vp->v_dirtyblkhd)) { /* diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h index 78846259c..96b4af13f 100644 --- a/sys/ufs/ffs/fs.h +++ b/sys/ufs/ffs/fs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fs.h,v 1.44 2022/01/11 03:13:59 jsg Exp $ */ +/* $OpenBSD: fs.h,v 1.45 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: fs.h,v 1.6 1995/04/12 21:21:02 mycroft Exp $ */ /* @@ -328,7 +328,6 @@ struct fs { * Filesystem flags. */ #define FS_UNCLEAN 0x01 /* filesystem not clean at mount */ -#define FS_DOSOFTDEP 0x02 /* filesystem using soft dependencies */ /* * The following flag is used to detect a FFS1 file system that had its flags * moved to the new (FFS2) location for compatibility. diff --git a/sys/ufs/ffs/softdep.h b/sys/ufs/ffs/softdep.h index 4a18d9350..e69de29bb 100644 --- a/sys/ufs/ffs/softdep.h +++ b/sys/ufs/ffs/softdep.h @@ -1,590 +0,0 @@ -/* $OpenBSD: softdep.h,v 1.18 2018/04/01 12:02:00 dhill Exp $ */ - -/* - * Copyright 1998, 2000 Marshall Kirk McKusick. All Rights Reserved. - * - * The soft updates code is derived from the appendix of a University - * of Michigan technical report (Gregory R. Ganger and Yale N. Patt, - * "Soft Updates: A Solution to the Metadata Update Problem in File - * Systems", CSE-TR-254-95, August 1995). - * - * Further information about soft updates can be obtained from: - * - * Marshall Kirk McKusick http://www.mckusick.com/softdep/ - * 1614 Oxford Street mckusick@mckusick.com - * Berkeley, CA 94709-1608 +1-510-843-9542 - * USA - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY MARSHALL KIRK MCKUSICK ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL MARSHALL KIRK MCKUSICK BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)softdep.h 9.7 (McKusick) 6/21/00 - * $FreeBSD: src/sys/ufs/ffs/softdep.h,v 1.10 2000/06/22 00:29:53 mckusick Exp $ - */ - -#include - -/* - * Allocation dependencies are handled with undo/redo on the in-memory - * copy of the data. A particular data dependency is eliminated when - * it is ALLCOMPLETE: that is ATTACHED, DEPCOMPLETE, and COMPLETE. - * - * ATTACHED means that the data is not currently being written to - * disk. UNDONE means that the data has been rolled back to a safe - * state for writing to the disk. When the I/O completes, the data is - * restored to its current form and the state reverts to ATTACHED. - * The data must be locked throughout the rollback, I/O, and roll - * forward so that the rolled back information is never visible to - * user processes. The COMPLETE flag indicates that the item has been - * written. For example, a dependency that requires that an inode be - * written will be marked COMPLETE after the inode has been written - * to disk. The DEPCOMPLETE flag indicates the completion of any other - * dependencies such as the writing of a cylinder group map has been - * completed. A dependency structure may be freed only when both it - * and its dependencies have completed and any rollbacks that are in - * progress have finished as indicated by the set of ALLCOMPLETE flags - * all being set. The two MKDIR flags indicate additional dependencies - * that must be done when creating a new directory. MKDIR_BODY is - * cleared when the directory data block containing the "." and ".." - * entries has been written. MKDIR_PARENT is cleared when the parent - * inode with the increased link count for ".." has been written. When - * both MKDIR flags have been cleared, the DEPCOMPLETE flag is set to - * indicate that the directory dependencies have been completed. The - * writing of the directory inode itself sets the COMPLETE flag which - * then allows the directory entry for the new directory to be written - * to disk. The RMDIR flag marks a dirrem structure as representing - * the removal of a directory rather than a file. When the removal - * dependencies are completed, additional work needs to be done - * (truncation of the "." and ".." entries, an additional decrement - * of the associated inode, and a decrement of the parent inode). The - * DIRCHG flag marks a diradd structure as representing the changing - * of an existing entry rather than the addition of a new one. When - * the update is complete the dirrem associated with the inode for - * the old name must be added to the worklist to do the necessary - * reference count decrement. The GOINGAWAY flag indicates that the - * data structure is frozen from further change until its dependencies - * have been completed and its resources freed after which it will be - * discarded. The IOSTARTED flag prevents multiple calls to the I/O - * start routine from doing multiple rollbacks. The SPACECOUNTED flag - * says that the files space has been accounted to the pending free - * space count. The NEWBLOCK flag marks pagedep structures that have - * just been allocated, so must be claimed by the inode before all - * dependencies are complete. The ONWORKLIST flag shows whether the - * structure is currently linked onto a worklist. - * - */ -#define ATTACHED 0x0001 -#define UNDONE 0x0002 -#define COMPLETE 0x0004 -#define DEPCOMPLETE 0x0008 -#define MKDIR_PARENT 0x0010 /* diradd & mkdir only */ -#define MKDIR_BODY 0x0020 /* diradd & mkdir only */ -#define RMDIR 0x0040 /* dirrem only */ -#define DIRCHG 0x0080 /* diradd & dirrem only */ -#define GOINGAWAY 0x0100 /* indirdep only */ -#define IOSTARTED 0x0200 /* inodedep & pagedep only */ -#define SPACECOUNTED 0x0400 /* inodedep only */ -#define NEWBLOCK 0x0800 /* pagedep only */ -#define UFS1FMT 0x2000 /* indirdep only */ -#define ONWORKLIST 0x8000 - -#define ALLCOMPLETE (ATTACHED | COMPLETE | DEPCOMPLETE) - -#define DEP_BITS "\020\01ATTACHED\02UNDONE\03COMPLETE\04DEPCOMPLETE" \ - "\05MKDIR_PARENT\06MKDIR_BODY\07RMDIR\010DIRCHG\011GOINGAWAY" \ - "\012IOSTARTED\013SPACECOUNTED\014NEWBLOCK\016UFS1FMT\020ONWORKLIST" - -/* - * The workitem queue. - * - * It is sometimes useful and/or necessary to clean up certain dependencies - * in the background rather than during execution of an application process - * or interrupt service routine. To realize this, we append dependency - * structures corresponding to such tasks to a "workitem" queue. In a soft - * updates implementation, most pending workitems should not wait for more - * than a couple of seconds, so the filesystem syncer process awakens once - * per second to process the items on the queue. - */ - -/* LIST_HEAD(workhead, worklist); -- declared in buf.h */ - -/* - * Each request can be linked onto a work queue through its worklist structure. - * To avoid the need for a pointer to the structure itself, this structure - * MUST be declared FIRST in each type in which it appears! If more than one - * worklist is needed in the structure, then a wk_data field must be added - * and the macros below changed to use it. - */ -struct worklist { - LIST_ENTRY(worklist) wk_list; /* list of work requests */ - unsigned short wk_type; /* type of request */ - unsigned short wk_state; /* state flags */ -}; -#define WK_DATA(wk) ((void *)(wk)) -#define WK_PAGEDEP(wk) ((struct pagedep *)(wk)) -#define WK_INODEDEP(wk) ((struct inodedep *)(wk)) -#define WK_NEWBLK(wk) ((struct newblk *)(wk)) -#define WK_BMSAFEMAP(wk) ((struct bmsafemap *)(wk)) -#define WK_ALLOCDIRECT(wk) ((struct allocdirect *)(wk)) -#define WK_INDIRDEP(wk) ((struct indirdep *)(wk)) -#define WK_ALLOCINDIR(wk) ((struct allocindir *)(wk)) -#define WK_FREEFRAG(wk) ((struct freefrag *)(wk)) -#define WK_FREEBLKS(wk) ((struct freeblks *)(wk)) -#define WK_FREEFILE(wk) ((struct freefile *)(wk)) -#define WK_DIRADD(wk) ((struct diradd *)(wk)) -#define WK_MKDIR(wk) ((struct mkdir *)(wk)) -#define WK_DIRREM(wk) ((struct dirrem *)(wk)) -#define WK_NEWDIRBLK(wk) ((struct newdirblk *)(wk)) - -/* - * Various types of lists - */ -LIST_HEAD(dirremhd, dirrem); -LIST_HEAD(diraddhd, diradd); -LIST_HEAD(newblkhd, newblk); -LIST_HEAD(inodedephd, inodedep); -LIST_HEAD(allocindirhd, allocindir); -LIST_HEAD(allocdirecthd, allocdirect); -TAILQ_HEAD(allocdirectlst, allocdirect); - -/* - * The "pagedep" structure tracks the various dependencies related to - * a particular directory page. If a directory page has any dependencies, - * it will have a pagedep linked to its associated buffer. The - * pd_dirremhd list holds the list of dirrem requests which decrement - * inode reference counts. These requests are processed after the - * directory page with the corresponding zero'ed entries has been - * written. The pd_diraddhd list maintains the list of diradd requests - * which cannot be committed until their corresponding inode has been - * written to disk. Because a directory may have many new entries - * being created, several lists are maintained hashed on bits of the - * offset of the entry into the directory page to keep the lists from - * getting too long. Once a new directory entry has been cleared to - * be written, it is moved to the pd_pendinghd list. After the new - * entry has been written to disk it is removed from the pd_pendinghd - * list, any removed operations are done, and the dependency structure - * is freed. - */ -#define DAHASHSZ 6 -#define DIRADDHASH(offset) (((offset) >> 2) % DAHASHSZ) -struct pagedep { - struct worklist pd_list; /* page buffer */ -# define pd_state pd_list.wk_state /* check for multiple I/O starts */ - LIST_ENTRY(pagedep) pd_hash; /* hashed lookup */ - struct mount *pd_mnt; /* associated mount point */ - ufsino_t pd_ino; /* associated file */ - daddr_t pd_lbn; /* block within file */ - struct dirremhd pd_dirremhd; /* dirrem's waiting for page */ - struct diraddhd pd_diraddhd[DAHASHSZ]; /* diradd dir entry updates */ - struct diraddhd pd_pendinghd; /* directory entries awaiting write */ -}; - -/* - * The "inodedep" structure tracks the set of dependencies associated - * with an inode. One task that it must manage is delayed operations - * (i.e., work requests that must be held until the inodedep's associated - * inode has been written to disk). Getting an inode from its incore - * state to the disk requires two steps to be taken by the filesystem - * in this order: first the inode must be copied to its disk buffer by - * the VOP_UPDATE operation; second the inode's buffer must be written - * to disk. To ensure that both operations have happened in the required - * order, the inodedep maintains two lists. Delayed operations are - * placed on the id_inowait list. When the VOP_UPDATE is done, all - * operations on the id_inowait list are moved to the id_bufwait list. - * When the buffer is written, the items on the id_bufwait list can be - * safely moved to the work queue to be processed. A second task of the - * inodedep structure is to track the status of block allocation within - * the inode. Each block that is allocated is represented by an - * "allocdirect" structure (see below). It is linked onto the id_newinoupdt - * list until both its contents and its allocation in the cylinder - * group map have been written to disk. Once these dependencies have been - * satisfied, it is removed from the id_newinoupdt list and any followup - * actions such as releasing the previous block or fragment are placed - * on the id_inowait list. When an inode is updated (a VOP_UPDATE is - * done), the "inodedep" structure is linked onto the buffer through - * its worklist. Thus, it will be notified when the buffer is about - * to be written and when it is done. At the update time, all the - * elements on the id_newinoupdt list are moved to the id_inoupdt list - * since those changes are now relevant to the copy of the inode in the - * buffer. Also at update time, the tasks on the id_inowait list are - * moved to the id_bufwait list so that they will be executed when - * the updated inode has been written to disk. When the buffer containing - * the inode is written to disk, any updates listed on the id_inoupdt - * list are rolled back as they are not yet safe. Following the write, - * the changes are once again rolled forward and any actions on the - * id_bufwait list are processed (since those actions are now safe). - * The entries on the id_inoupdt and id_newinoupdt lists must be kept - * sorted by logical block number to speed the calculation of the size - * of the rolled back inode (see explanation in initiate_write_inodeblock). - * When a directory entry is created, it is represented by a diradd. - * The diradd is added to the id_inowait list as it cannot be safely - * written to disk until the inode that it represents is on disk. After - * the inode is written, the id_bufwait list is processed and the diradd - * entries are moved to the id_pendinghd list where they remain until - * the directory block containing the name has been written to disk. - * The purpose of keeping the entries on the id_pendinghd list is so that - * the softdep_fsync function can find and push the inode's directory - * name(s) as part of the fsync operation for that file. - */ -struct inodedep { - struct worklist id_list; /* buffer holding inode block */ -# define id_state id_list.wk_state /* inode dependency state */ - LIST_ENTRY(inodedep) id_hash; /* hashed lookup */ - struct fs *id_fs; /* associated filesystem */ - ufsino_t id_ino; /* dependent inode */ - nlink_t id_nlinkdelta; /* saved effective link count */ - union { /* Saved UFS1/UFS2 dinode contents */ - struct ufs1_dinode *idu_savedino1; - struct ufs2_dinode *idu_savedino2; - } id_un; - size_t id_unsize; /* size of dinode contents union */ - LIST_ENTRY(inodedep) id_deps; /* bmsafemap's list of inodedep's */ - struct buf *id_buf; /* related bmsafemap (if pending) */ - off_t id_savedsize; /* file size saved during rollback */ - struct workhead id_pendinghd; /* entries awaiting directory write */ - struct workhead id_bufwait; /* operations after inode written */ - struct workhead id_inowait; /* operations waiting inode update */ - struct allocdirectlst id_inoupdt; /* updates before inode written */ - struct allocdirectlst id_newinoupdt; /* updates when inode written */ -}; - -#define id_savedino1 id_un.idu_savedino1 -#define id_savedino2 id_un.idu_savedino2 - -/* - * A "newblk" structure is attached to a bmsafemap structure when a block - * or fragment is allocated from a cylinder group. Its state is set to - * DEPCOMPLETE when its cylinder group map is written. It is consumed by - * an associated allocdirect or allocindir allocation which will attach - * themselves to the bmsafemap structure if the newblk's DEPCOMPLETE flag - * is not set (i.e., its cylinder group map has not been written). - */ -struct newblk { - LIST_ENTRY(newblk) nb_hash; /* hashed lookup */ - struct fs *nb_fs; /* associated filesystem */ - daddr_t nb_newblkno; /* allocated block number */ - int nb_state; /* state of bitmap dependency */ - LIST_ENTRY(newblk) nb_deps; /* bmsafemap's list of newblk's */ - struct bmsafemap *nb_bmsafemap; /* associated bmsafemap */ -}; - -/* - * A "bmsafemap" structure maintains a list of dependency structures - * that depend on the update of a particular cylinder group map. - * It has lists for newblks, allocdirects, allocindirs, and inodedeps. - * It is attached to the buffer of a cylinder group block when any of - * these things are allocated from the cylinder group. It is freed - * after the cylinder group map is written and the state of its - * dependencies are updated with DEPCOMPLETE to indicate that it has - * been processed. - */ -struct bmsafemap { - struct worklist sm_list; /* cylgrp buffer */ - struct buf *sm_buf; /* associated buffer */ - struct allocdirecthd sm_allocdirecthd; /* allocdirect deps */ - struct allocindirhd sm_allocindirhd; /* allocindir deps */ - struct inodedephd sm_inodedephd; /* inodedep deps */ - struct newblkhd sm_newblkhd; /* newblk deps */ -}; - -/* - * An "allocdirect" structure is attached to an "inodedep" when a new block - * or fragment is allocated and pointed to by the inode described by - * "inodedep". The worklist is linked to the buffer that holds the block. - * When the block is first allocated, it is linked to the bmsafemap - * structure associated with the buffer holding the cylinder group map - * from which it was allocated. When the cylinder group map is written - * to disk, ad_state has the DEPCOMPLETE flag set. When the block itself - * is written, the COMPLETE flag is set. Once both the cylinder group map - * and the data itself have been written, it is safe to write the inode - * that claims the block. If there was a previous fragment that had been - * allocated before the file was increased in size, the old fragment may - * be freed once the inode claiming the new block is written to disk. - * This ad_fragfree request is attached to the id_inowait list of the - * associated inodedep (pointed to by ad_inodedep) for processing after - * the inode is written. When a block is allocated to a directory, an - * fsync of a file whose name is within that block must ensure not only - * that the block containing the file name has been written, but also - * that the on-disk inode references that block. When a new directory - * block is created, we allocate a newdirblk structure which is linked - * to the associated allocdirect (on its ad_newdirblk list). When the - * allocdirect has been satisfied, the newdirblk structure is moved to - * the inodedep id_bufwait list of its directory to await the inode - * being written. When the inode is written, the directory entries are - * fully committed and can be deleted from their pagedep->id_pendinghd - * and inodedep->id_pendinghd lists. - */ -struct allocdirect { - struct worklist ad_list; /* buffer holding block */ -# define ad_state ad_list.wk_state /* block pointer state */ - TAILQ_ENTRY(allocdirect) ad_next; /* inodedep's list of allocdirect's */ - daddr_t ad_lbn; /* block within file */ - daddr_t ad_newblkno; /* new value of block pointer */ - daddr_t ad_oldblkno; /* old value of block pointer */ - long ad_newsize; /* size of new block */ - long ad_oldsize; /* size of old block */ - LIST_ENTRY(allocdirect) ad_deps; /* bmsafemap's list of allocdirect's */ - struct buf *ad_buf; /* cylgrp buffer (if pending) */ - struct inodedep *ad_inodedep; /* associated inodedep */ - struct freefrag *ad_freefrag; /* fragment to be freed (if any) */ - struct workhead ad_newdirblk; /* dir block to notify when written */ -}; - -/* - * A single "indirdep" structure manages all allocation dependencies for - * pointers in an indirect block. The up-to-date state of the indirect - * block is stored in ir_savedata. The set of pointers that may be safely - * written to the disk is stored in ir_safecopy. The state field is used - * only to track whether the buffer is currently being written (in which - * case it is not safe to update ir_safecopy). Ir_deplisthd contains the - * list of allocindir structures, one for each block that needs to be - * written to disk. Once the block and its bitmap allocation have been - * written the safecopy can be updated to reflect the allocation and the - * allocindir structure freed. If ir_state indicates that an I/O on the - * indirect block is in progress when ir_safecopy is to be updated, the - * update is deferred by placing the allocindir on the ir_donehd list. - * When the I/O on the indirect block completes, the entries on the - * ir_donehd list are processed by updating their corresponding ir_safecopy - * pointers and then freeing the allocindir structure. - */ -struct indirdep { - struct worklist ir_list; /* buffer holding indirect block */ -# define ir_state ir_list.wk_state /* indirect block pointer state */ - caddr_t ir_saveddata; /* buffer cache contents */ - struct buf *ir_savebp; /* buffer holding safe copy */ - struct allocindirhd ir_donehd; /* done waiting to update safecopy */ - struct allocindirhd ir_deplisthd; /* allocindir deps for this block */ -}; - -/* - * An "allocindir" structure is attached to an "indirdep" when a new block - * is allocated and pointed to by the indirect block described by the - * "indirdep". The worklist is linked to the buffer that holds the new block. - * When the block is first allocated, it is linked to the bmsafemap - * structure associated with the buffer holding the cylinder group map - * from which it was allocated. When the cylinder group map is written - * to disk, ai_state has the DEPCOMPLETE flag set. When the block itself - * is written, the COMPLETE flag is set. Once both the cylinder group map - * and the data itself have been written, it is safe to write the entry in - * the indirect block that claims the block; the "allocindir" dependency - * can then be freed as it is no longer applicable. - */ -struct allocindir { - struct worklist ai_list; /* buffer holding indirect block */ -# define ai_state ai_list.wk_state /* indirect block pointer state */ - LIST_ENTRY(allocindir) ai_next; /* indirdep's list of allocindir's */ - int ai_offset; /* pointer offset in indirect block */ - daddr_t ai_newblkno; /* new block pointer value */ - daddr_t ai_oldblkno; /* old block pointer value */ - struct freefrag *ai_freefrag; /* block to be freed when complete */ - struct indirdep *ai_indirdep; /* address of associated indirdep */ - LIST_ENTRY(allocindir) ai_deps; /* bmsafemap's list of allocindir's */ - struct buf *ai_buf; /* cylgrp buffer (if pending) */ -}; - -/* - * A "freefrag" structure is attached to an "inodedep" when a previously - * allocated fragment is replaced with a larger fragment, rather than extended. - * The "freefrag" structure is constructed and attached when the replacement - * block is first allocated. It is processed after the inode claiming the - * bigger block that replaces it has been written to disk. Note that the - * ff_state field is used to store the uid, so may lose data. However, - * the uid is used only in printing an error message, so is not critical. - * Keeping it in a short keeps the data structure down to 32 bytes. - */ -struct freefrag { - struct worklist ff_list; /* id_inowait or delayed worklist */ -# define ff_state ff_list.wk_state /* owning user; should be uid_t */ - struct vnode *ff_devvp; /* filesystem device vnode */ - struct mount *ff_mnt; /* associated mount point */ - daddr_t ff_blkno; /* fragment physical block number */ - long ff_fragsize; /* size of fragment being deleted */ - ufsino_t ff_inum; /* owning inode number */ -}; - -/* - * A "freeblks" structure is attached to an "inodedep" when the - * corresponding file's length is reduced to zero. It records all - * the information needed to free the blocks of a file after its - * zero'ed inode has been written to disk. - */ -struct freeblks { - struct worklist fb_list; /* id_inowait or delayed worklist */ -# define fb_state fb_list.wk_state /* inode and dirty block state */ - ufsino_t fb_previousinum; /* inode of previous owner of blocks */ - struct vnode *fb_devvp; /* filesystem device vnode */ - struct mount *fb_mnt; /* associated mount point */ - off_t fb_oldsize; /* previous file size */ - off_t fb_newsize; /* new file size */ - int fb_chkcnt; /* used to check cnt of blks released */ - uid_t fb_uid; /* uid of previous owner of blocks */ - daddr_t fb_dblks[NDADDR]; /* direct blk ptrs to deallocate */ - daddr_t fb_iblks[NIADDR]; /* indirect blk ptrs to deallocate */ -}; - -/* - * A "freefile" structure is attached to an inode when its - * link count is reduced to zero. It marks the inode as free in - * the cylinder group map after the zero'ed inode has been written - * to disk and any associated blocks and fragments have been freed. - */ -struct freefile { - struct worklist fx_list; /* id_inowait or delayed worklist */ - mode_t fx_mode; /* mode of inode */ - ufsino_t fx_oldinum; /* inum of the unlinked file */ - struct vnode *fx_devvp; /* filesystem device vnode */ - struct mount *fx_mnt; /* associated mount point */ -}; - -/* - * A "diradd" structure is linked to an "inodedep" id_inowait list when a - * new directory entry is allocated that references the inode described - * by "inodedep". When the inode itself is written (either the initial - * allocation for new inodes or with the increased link count for - * existing inodes), the COMPLETE flag is set in da_state. If the entry - * is for a newly allocated inode, the "inodedep" structure is associated - * with a bmsafemap which prevents the inode from being written to disk - * until the cylinder group has been updated. Thus the da_state COMPLETE - * flag cannot be set until the inode bitmap dependency has been removed. - * When creating a new file, it is safe to write the directory entry that - * claims the inode once the referenced inode has been written. Since - * writing the inode clears the bitmap dependencies, the DEPCOMPLETE flag - * in the diradd can be set unconditionally when creating a file. When - * creating a directory, there are two additional dependencies described by - * mkdir structures (see their description below). When these dependencies - * are resolved the DEPCOMPLETE flag is set in the diradd structure. - * If there are multiple links created to the same inode, there will be - * a separate diradd structure created for each link. The diradd is - * linked onto the pg_diraddhd list of the pagedep for the directory - * page that contains the entry. When a directory page is written, - * the pg_diraddhd list is traversed to rollback any entries that are - * not yet ready to be written to disk. If a directory entry is being - * changed (by rename) rather than added, the DIRCHG flag is set and - * the da_previous entry points to the entry that will be "removed" - * once the new entry has been committed. During rollback, entries - * with da_previous are replaced with the previous inode number rather - * than zero. - * - * The overlaying of da_pagedep and da_previous is done to keep the - * structure down to 32 bytes in size on a 32-bit machine. If a - * da_previous entry is present, the pointer to its pagedep is available - * in the associated dirrem entry. If the DIRCHG flag is set, the - * da_previous entry is valid; if not set the da_pagedep entry is valid. - * The DIRCHG flag never changes; it is set when the structure is created - * if appropriate and is never cleared. - */ -struct diradd { - struct worklist da_list; /* id_inowait or id_pendinghd list */ -# define da_state da_list.wk_state /* state of the new directory entry */ - LIST_ENTRY(diradd) da_pdlist; /* pagedep holding directory block */ - doff_t da_offset; /* offset of new dir entry in dir blk */ - ufsino_t da_newinum; /* inode number for the new dir entry */ - union { - struct dirrem *dau_previous; /* entry being replaced in dir change */ - struct pagedep *dau_pagedep; /* pagedep dependency for addition */ - } da_un; -}; -#define da_previous da_un.dau_previous -#define da_pagedep da_un.dau_pagedep - -/* - * Two "mkdir" structures are needed to track the additional dependencies - * associated with creating a new directory entry. Normally a directory - * addition can be committed as soon as the newly referenced inode has been - * written to disk with its increased link count. When a directory is - * created there are two additional dependencies: writing the directory - * data block containing the "." and ".." entries (MKDIR_BODY) and writing - * the parent inode with the increased link count for ".." (MKDIR_PARENT). - * These additional dependencies are tracked by two mkdir structures that - * reference the associated "diradd" structure. When they have completed, - * they set the DEPCOMPLETE flag on the diradd so that it knows that its - * extra dependencies have been completed. The md_state field is used only - * to identify which type of dependency the mkdir structure is tracking. - * It is not used in the mainline code for any purpose other than consistency - * checking. All the mkdir structures in the system are linked together on - * a list. This list is needed so that a diradd can find its associated - * mkdir structures and deallocate them if it is prematurely freed (as for - * example if a mkdir is immediately followed by a rmdir of the same directory). - * Here, the free of the diradd must traverse the list to find the associated - * mkdir structures that reference it. The deletion would be faster if the - * diradd structure were simply augmented to have two pointers that referenced - * the associated mkdir's. However, this would increase the size of the diradd - * structure from 32 to 64-bits to speed a very infrequent operation. - */ -struct mkdir { - struct worklist md_list; /* id_inowait or buffer holding dir */ -# define md_state md_list.wk_state /* type: MKDIR_PARENT or MKDIR_BODY */ - struct diradd *md_diradd; /* associated diradd */ - struct buf *md_buf; /* MKDIR_BODY: buffer holding dir */ - LIST_ENTRY(mkdir) md_mkdirs; /* list of all mkdirs */ -}; -LIST_HEAD(mkdirlist, mkdir) mkdirlisthd; - -/* - * A "dirrem" structure describes an operation to decrement the link - * count on an inode. The dirrem structure is attached to the pg_dirremhd - * list of the pagedep for the directory page that contains the entry. - * It is processed after the directory page with the deleted entry has - * been written to disk. - * - * The overlaying of dm_pagedep and dm_dirinum is done to keep the - * structure down to 32 bytes in size on a 32-bit machine. It works - * because they are never used concurrently. - */ -struct dirrem { - struct worklist dm_list; /* delayed worklist */ -# define dm_state dm_list.wk_state /* state of the old directory entry */ - LIST_ENTRY(dirrem) dm_next; /* pagedep's list of dirrem's */ - struct mount *dm_mnt; /* associated mount point */ - ufsino_t dm_oldinum; /* inum of the removed dir entry */ - union { - struct pagedep *dmu_pagedep; /* pagedep dependency for remove */ - ufsino_t dmu_dirinum; /* parent inode number (for rmdir) */ - } dm_un; -}; -#define dm_pagedep dm_un.dmu_pagedep -#define dm_dirinum dm_un.dmu_dirinum - - -/* - * A "newdirblk" structure tracks the progress of a newly allocated - * directory block from its creation until it is claimed by its on-disk - * inode. When a block is allocated to a directory, an fsync of a file - * whose name is within that block must ensure not only that the block - * containing the file name has been written, but also that the on-disk - * inode references that block. When a new directory block is created, - * we allocate a newdirblk structure which is linked to the associated - * allocdirect (on its ad_newdirblk list). When the allocdirect has been - * satisfied, the newdirblk structure is moved to the inodedep id_bufwait - * list of its directory to await the inode being written. When the inode - * is written, the directory entries are fully committed and can be - * deleted from their pagedep->id_pendinghd and inodedep->id_pendinghd - * lists. Note that we could track directory blocks allocated to indirect - * blocks using a similar scheme with the allocindir structures. Rather - * than adding this level of complexity, we simply write those newly - * allocated indirect blocks synchronously as such allocations are rare. - */ -struct newdirblk { - struct worklist db_list;/* id_inowait or pg_newdirblk */ -# define db_state db_list.wk_state /* unused */ - struct pagedep *db_pagedep;/* associated pagedep */ -}; diff --git a/sys/ufs/ufs/inode.h b/sys/ufs/ufs/inode.h index d09b52f73..4682acf4a 100644 --- a/sys/ufs/ufs/inode.h +++ b/sys/ufs/ufs/inode.h @@ -1,4 +1,4 @@ -/* $OpenBSD: inode.h,v 1.53 2020/06/24 22:03:45 cheloha Exp $ */ +/* $OpenBSD: inode.h,v 1.54 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: inode.h,v 1.8 1995/06/15 23:22:50 cgd Exp $ */ /* @@ -332,11 +332,6 @@ struct indir { } while (0) /* Determine if soft dependencies are being done */ -#ifdef FFS_SOFTUPDATES -#define DOINGSOFTDEP(vp) ((vp)->v_mount->mnt_flag & MNT_SOFTDEP) -#else -#define DOINGSOFTDEP(vp) (0) -#endif #define DOINGASYNC(vp) ((vp)->v_mount->mnt_flag & MNT_ASYNC) /* This overlays the fid structure (see mount.h). */ diff --git a/sys/ufs/ufs/ufs_extern.h b/sys/ufs/ufs/ufs_extern.h index 750dcd07c..0a3c480f8 100644 --- a/sys/ufs/ufs/ufs_extern.h +++ b/sys/ufs/ufs/ufs_extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_extern.h,v 1.38 2022/06/26 05:20:43 visa Exp $ */ +/* $OpenBSD: ufs_extern.h,v 1.39 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: ufs_extern.h,v 1.5 1996/02/09 22:36:03 christos Exp $ */ /*- @@ -132,18 +132,3 @@ int ufs_check_export(struct mount *, struct mbuf *, int *, void ufs_itimes(struct vnode *); int ufs_makeinode(int, struct vnode *, struct vnode **, struct componentname *); - - -/* - * Soft dependency function prototypes. - */ -int softdep_setup_directory_add(struct buf *, struct inode *, off_t, - long, struct buf *, int); -void softdep_change_directoryentry_offset(struct inode *, caddr_t, - caddr_t, caddr_t, int); -void softdep_setup_remove(struct buf *,struct inode *, struct inode *, - int); -void softdep_setup_directory_change(struct buf *, struct inode *, - struct inode *, long, int); -void softdep_change_linkcnt(struct inode *, int); -int softdep_slowdown(struct vnode *); diff --git a/sys/ufs/ufs/ufs_inode.c b/sys/ufs/ufs/ufs_inode.c index cc3b8b832..4ea385d04 100644 --- a/sys/ufs/ufs/ufs_inode.c +++ b/sys/ufs/ufs/ufs_inode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_inode.c,v 1.44 2020/02/27 09:10:31 mpi Exp $ */ +/* $OpenBSD: ufs_inode.c,v 1.45 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: ufs_inode.c,v 1.7 1996/05/11 18:27:52 mycroft Exp $ */ /* @@ -88,21 +88,6 @@ ufs_inactive(void *v) DIP_ASSIGN(ip, mode, 0); ip->i_flag |= IN_CHANGE | IN_UPDATE; - /* - * Setting the mode to zero needs to wait for the inode to be - * written just as does a change to the link count. So, rather - * than creating a new entry point to do the same thing, we - * just use softdep_change_linkcnt(). Also, we can't let - * softdep co-opt us to help on its worklist, as we may end up - * trying to recycle vnodes and getting to this same point a - * couple of times, blowing the kernel stack. However, this - * could be optimized by checking if we are coming from - * vrele(), vput() or vclean() (by checking for VXLOCK) and - * just avoiding the co-opt to happen in the last case. - */ - if (DOINGSOFTDEP(vp)) - softdep_change_linkcnt(ip, 1); - UFS_INODE_FREE(ip, ip->i_number, mode); } diff --git a/sys/ufs/ufs/ufs_lookup.c b/sys/ufs/ufs/ufs_lookup.c index aa8365f64..0c1d68b3d 100644 --- a/sys/ufs/ufs/ufs_lookup.c +++ b/sys/ufs/ufs/ufs_lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_lookup.c,v 1.60 2024/01/09 03:15:59 guenther Exp $ */ +/* $OpenBSD: ufs_lookup.c,v 1.61 2024/02/03 18:51:58 beck Exp $ */ /* $NetBSD: ufs_lookup.c,v 1.7 1996/02/09 22:36:06 christos Exp $ */ /* @@ -700,12 +700,9 @@ ufs_direnter(struct vnode *dvp, struct vnode *tvp, struct direct *dirp, if (dp->i_offset & (DIRBLKSIZ - 1)) panic("ufs_direnter: newblk"); flags = B_CLRBUF; - if (!DOINGSOFTDEP(dvp)) - flags |= B_SYNC; + flags |= B_SYNC; if ((error = UFS_BUF_ALLOC(dp, (off_t)dp->i_offset, DIRBLKSIZ, cr, flags, &bp)) != 0) { - if (DOINGSOFTDEP(dvp) && newdirbp != NULL) - bdwrite(newdirbp); return (error); } DIP_ASSIGN(dp, size, dp->i_offset + DIRBLKSIZ); @@ -725,45 +722,8 @@ ufs_direnter(struct vnode *dvp, struct vnode *tvp, struct direct *dirp, } #endif - if (DOINGSOFTDEP(dvp)) { - /* - * Ensure that the entire newly allocated block is a - * valid directory so that future growth within the - * block does not have to ensure that the block is - * written before the inode. - */ - blkoff += DIRBLKSIZ; - while (blkoff < bp->b_bcount) { - ((struct direct *) - (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ; - blkoff += DIRBLKSIZ; - } - if (softdep_setup_directory_add(bp, dp, dp->i_offset, - dirp->d_ino, newdirbp, 1) == 0) { - bdwrite(bp); - return (UFS_UPDATE(dp, 0)); - } - /* We have just allocated a directory block in an - * indirect block. Rather than tracking when it gets - * claimed by the inode, we simply do a VOP_FSYNC - * now to ensure that it is there (in case the user - * does a future fsync). Note that we have to unlock - * the inode for the entry that we just entered, as - * the VOP_FSYNC may need to lock other inodes which - * can lead to deadlock if we also hold a lock on - * the newly entered node. - */ - if ((error = VOP_BWRITE(bp))) - return (error); - if (tvp != NULL) - VOP_UNLOCK(tvp); - error = VOP_FSYNC(dvp, p->p_ucred, MNT_WAIT, p); - if (tvp != NULL) - vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY); - return (error); - } error = VOP_BWRITE(bp); - ret = UFS_UPDATE(dp, !DOINGSOFTDEP(dvp)); + ret = UFS_UPDATE(dp, 1); if (error == 0) return (ret); return (error); @@ -792,8 +752,6 @@ ufs_direnter(struct vnode *dvp, struct vnode *tvp, struct direct *dirp, */ if ((error = UFS_BUFATOFF(dp, (off_t)dp->i_offset, &dirbuf, &bp)) != 0) { - if (DOINGSOFTDEP(dvp) && newdirbp != NULL) - bdwrite(newdirbp); return (error); } /* @@ -836,11 +794,7 @@ ufs_direnter(struct vnode *dvp, struct vnode *tvp, struct direct *dirp, dp->i_offset + ((char *)nep - dirbuf), dp->i_offset + ((char *)ep - dirbuf)); #endif - if (DOINGSOFTDEP(dvp)) - softdep_change_directoryentry_offset(dp, dirbuf, - (caddr_t)nep, (caddr_t)ep, dsize); - else - memmove(ep, nep, dsize); + memmove(ep, nep, dsize); } /* * Here, `ep' points to a directory entry containing `dsize' in-use @@ -876,14 +830,7 @@ ufs_direnter(struct vnode *dvp, struct vnode *tvp, struct direct *dirp, dp->i_offset & ~(DIRBLKSIZ - 1)); #endif - if (DOINGSOFTDEP(dvp)) { - (void)softdep_setup_directory_add(bp, dp, - dp->i_offset + (caddr_t)ep - dirbuf, - dirp->d_ino, newdirbp, 0); - bdwrite(bp); - } else { - error = VOP_BWRITE(bp); - } + error = VOP_BWRITE(bp); dp->i_flag |= IN_CHANGE | IN_UPDATE; /* @@ -960,30 +907,17 @@ ufs_dirremove(struct vnode *dvp, struct inode *ip, int flags, int isrmdir) ((dp->i_offset - dp->i_count) & (DIRBLKSIZ - 1)), dp->i_offset & ~(DIRBLKSIZ - 1)); #endif - if (DOINGSOFTDEP(dvp)) { - if (ip) { - ip->i_effnlink--; - softdep_change_linkcnt(ip, 0); - softdep_setup_remove(bp, dp, ip, isrmdir); - } - if (softdep_slowdown(dvp)) { - error = bwrite(bp); - } else { - bdwrite(bp); - error = 0; - } - } else { - if (ip) { - ip->i_effnlink--; - DIP_ADD(ip, nlink, -1); - ip->i_flag |= IN_CHANGE; - } - if (DOINGASYNC(dvp) && dp->i_count != 0) { - bdwrite(bp); - error = 0; - } else - error = bwrite(bp); + if (ip) { + ip->i_effnlink--; + DIP_ADD(ip, nlink, -1); + ip->i_flag |= IN_CHANGE; } + if (DOINGASYNC(dvp) && dp->i_count != 0) { + bdwrite(bp); + error = 0; + } else + error = bwrite(bp); + dp->i_flag |= IN_CHANGE | IN_UPDATE; return (error); } @@ -1008,19 +942,13 @@ ufs_dirrewrite(struct inode *dp, struct inode *oip, ufsino_t newinum, ep->d_ino = newinum; ep->d_type = newtype; oip->i_effnlink--; - if (DOINGSOFTDEP(vdp)) { - softdep_change_linkcnt(oip, 0); - softdep_setup_directory_change(bp, dp, oip, newinum, isrmdir); + DIP_ADD(oip, nlink, -1); + oip->i_flag |= IN_CHANGE; + if (DOINGASYNC(vdp)) { bdwrite(bp); + error = 0; } else { - DIP_ADD(oip, nlink, -1); - oip->i_flag |= IN_CHANGE; - if (DOINGASYNC(vdp)) { - bdwrite(bp); - error = 0; - } else { - error = VOP_BWRITE(bp); - } + error = VOP_BWRITE(bp); } dp->i_flag |= IN_CHANGE | IN_UPDATE; return (error); diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c index 151f4dff2..c4a2ae601 100644 --- a/sys/ufs/ufs/ufs_vnops.c +++ b/sys/ufs/ufs/ufs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_vnops.c,v 1.159 2024/01/09 03:15:59 guenther Exp $ */ +/* $OpenBSD: ufs_vnops.c,v 1.160 2024/02/03 18:51:59 beck Exp $ */ /* $NetBSD: ufs_vnops.c,v 1.18 1996/05/11 18:28:04 mycroft Exp $ */ /* @@ -109,7 +109,7 @@ ufs_itimes(struct vnode *vp) } #endif - if ((vp->v_type == VBLK || vp->v_type == VCHR) && !DOINGSOFTDEP(vp)) + if ((vp->v_type == VBLK || vp->v_type == VCHR)) ip->i_flag |= IN_LAZYMOD; else ip->i_flag |= IN_MODIFIED; @@ -649,9 +649,7 @@ ufs_link(void *v) ip->i_effnlink++; DIP_ADD(ip, nlink, 1); ip->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(vp)) - softdep_change_linkcnt(ip, 0); - if ((error = UFS_UPDATE(ip, !DOINGSOFTDEP(vp))) == 0) { + if ((error = UFS_UPDATE(ip, 1)) == 0) { ufs_makedirentry(ip, cnp, &newdir); error = ufs_direnter(dvp, vp, &newdir, cnp, NULL); } @@ -659,8 +657,6 @@ ufs_link(void *v) ip->i_effnlink--; DIP_ADD(ip, nlink, -1); ip->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(vp)) - softdep_change_linkcnt(ip, 0); } pool_put(&namei_pool, cnp->cn_pnbuf); VN_KNOTE(vp, NOTE_LINK); @@ -846,9 +842,7 @@ abortit: ip->i_effnlink++; DIP_ADD(ip, nlink, 1); ip->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(fvp)) - softdep_change_linkcnt(ip, 0); - if ((error = UFS_UPDATE(ip, !DOINGSOFTDEP(fvp))) != 0) { + if ((error = UFS_UPDATE(ip, 1)) != 0) { VOP_UNLOCK(fvp); goto bad; } @@ -916,15 +910,11 @@ abortit: dp->i_effnlink++; DIP_ADD(dp, nlink, 1); dp->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(tdvp)) - softdep_change_linkcnt(dp, 0); - if ((error = UFS_UPDATE(dp, !DOINGSOFTDEP(tdvp))) + if ((error = UFS_UPDATE(dp, 1)) != 0) { dp->i_effnlink--; DIP_ADD(dp, nlink, -1); dp->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(tdvp)) - softdep_change_linkcnt(dp, 0); goto bad; } } @@ -934,8 +924,6 @@ abortit: dp->i_effnlink--; DIP_ADD(dp, nlink, -1); dp->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(tdvp)) - softdep_change_linkcnt(dp, 0); (void)UFS_UPDATE(dp, 1); } goto bad; @@ -991,14 +979,10 @@ abortit: if (doingdirectory) { if (!newparent) { dp->i_effnlink--; - if (DOINGSOFTDEP(tdvp)) - softdep_change_linkcnt(dp, 0); } xp->i_effnlink--; - if (DOINGSOFTDEP(tvp)) - softdep_change_linkcnt(xp, 0); } - if (doingdirectory && !DOINGSOFTDEP(tvp)) { + if (doingdirectory) { /* * Truncate inode. The only stuff left in the directory * is "." and "..". The "." reference is inconsequential @@ -1101,8 +1085,6 @@ out: DIP_ADD(ip, nlink, -1); ip->i_flag |= IN_CHANGE; ip->i_flag &= ~IN_RENAME; - if (DOINGSOFTDEP(fvp)) - softdep_change_linkcnt(ip, 0); vput(fvp); } else vrele(fvp); @@ -1124,7 +1106,7 @@ ufs_mkdir(void *v) struct buf *bp; struct direct newdir; struct dirtemplate dirtemplate; - int error, dmode, blkoff; + int error, dmode; #ifdef DIAGNOSTIC if ((cnp->cn_flags & HASBUF) == 0) @@ -1164,8 +1146,6 @@ ufs_mkdir(void *v) tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */ ip->i_effnlink = 2; DIP_ASSIGN(ip, nlink, 2); - if (DOINGSOFTDEP(tvp)) - softdep_change_linkcnt(ip, 0); /* * Bump link count in parent directory to reflect work done below. @@ -1175,9 +1155,7 @@ ufs_mkdir(void *v) dp->i_effnlink++; DIP_ADD(dp, nlink, 1); dp->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(dvp)) - softdep_change_linkcnt(dp, 0); - if ((error = UFS_UPDATE(dp, !DOINGSOFTDEP(dvp))) != 0) + if ((error = UFS_UPDATE(dp, 1)) != 0) goto bad; /* @@ -1194,21 +1172,7 @@ ufs_mkdir(void *v) ip->i_flag |= IN_CHANGE | IN_UPDATE; uvm_vnp_setsize(tvp, DIP(ip, size)); memcpy(bp->b_data, &dirtemplate, sizeof(dirtemplate)); - if (DOINGSOFTDEP(tvp)) { - /* - * Ensure that the entire newly allocated block is a - * valid directory so that future growth within the - * block does not have to ensure that the block is - * written before the inode - */ - blkoff = DIRBLKSIZ; - while (blkoff < bp->b_bcount) { - ((struct direct *) - (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ; - blkoff += DIRBLKSIZ; - } - } - if ((error = UFS_UPDATE(ip, !DOINGSOFTDEP(tvp))) != 0) { + if ((error = UFS_UPDATE(ip, 1)) != 0) { (void)VOP_BWRITE(bp); goto bad; } @@ -1224,7 +1188,7 @@ ufs_mkdir(void *v) * an appropriate ordering dependency to the buffer which ensures that * the buffer is written before the new name is written in the parent. */ - if (!DOINGSOFTDEP(dvp) && ((error = VOP_BWRITE(bp)) != 0)) + if ((error = VOP_BWRITE(bp)) != 0) goto bad; ufs_makedirentry(ip, cnp, &newdir); error = ufs_direnter(dvp, tvp, &newdir, cnp, bp); @@ -1237,8 +1201,6 @@ bad: dp->i_effnlink--; DIP_ADD(dp, nlink, -1); dp->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(dvp)) - softdep_change_linkcnt(dp, 0); /* * No need to do an explicit VOP_TRUNCATE here, vrele will * do this for us because we set the link count to 0. @@ -1246,8 +1208,6 @@ bad: ip->i_effnlink = 0; DIP_ASSIGN(ip, nlink, 0); ip->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(tvp)) - softdep_change_linkcnt(ip, 0); vput(tvp); } out: @@ -1300,17 +1260,9 @@ ufs_rmdir(void *v) */ dp->i_effnlink--; ip->i_effnlink--; - if (DOINGSOFTDEP(vp)) { - softdep_change_linkcnt(dp, 0); - softdep_change_linkcnt(ip, 0); - } if ((error = ufs_dirremove(dvp, ip, cnp->cn_flags, 1)) != 0) { dp->i_effnlink++; ip->i_effnlink++; - if (DOINGSOFTDEP(vp)) { - softdep_change_linkcnt(dp, 0); - softdep_change_linkcnt(ip, 0); - } goto out; } @@ -1319,20 +1271,15 @@ ufs_rmdir(void *v) /* * Truncate inode. The only stuff left in the directory is "." and * "..". The "." reference is inconsequential since we are quashing - * it. The soft dependency code will arrange to do these operations - * after the parent directory entry has been deleted on disk, so - * when running with that code we avoid doing them now. + * it. */ - if (!DOINGSOFTDEP(vp)) { - int ioflag; + DIP_ADD(dp, nlink, -1); + dp->i_flag |= IN_CHANGE; + DIP_ADD(ip, nlink, -1); + ip->i_flag |= IN_CHANGE; + error = UFS_TRUNCATE(ip, (off_t)0, DOINGASYNC(vp) ? 0 : IO_SYNC, + cnp->cn_cred); - DIP_ADD(dp, nlink, -1); - dp->i_flag |= IN_CHANGE; - DIP_ADD(ip, nlink, -1); - ip->i_flag |= IN_CHANGE; - ioflag = DOINGASYNC(vp) ? 0 : IO_SYNC; - error = UFS_TRUNCATE(ip, (off_t)0, ioflag, cnp->cn_cred); - } cache_purge(vp); #ifdef UFS_DIRHASH /* Kill any active hash; i_effnlink == 0, so it will not come back. */ @@ -1816,8 +1763,6 @@ ufs_makeinode(int mode, struct vnode *dvp, struct vnode **vpp, tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */ ip->i_effnlink = 1; DIP_ASSIGN(ip, nlink, 1); - if (DOINGSOFTDEP(tvp)) - softdep_change_linkcnt(ip, 0); if ((DIP(ip, mode) & ISGID) && !groupmember(DIP(ip, gid), cnp->cn_cred) && !vnoperm(dvp) && @@ -1827,7 +1772,7 @@ ufs_makeinode(int mode, struct vnode *dvp, struct vnode **vpp, /* * Make sure inode goes to disk before directory entry. */ - if ((error = UFS_UPDATE(ip, !DOINGSOFTDEP(tvp))) != 0) + if ((error = UFS_UPDATE(ip, 1)) != 0) goto bad; ufs_makedirentry(ip, cnp, &newdir); @@ -1848,8 +1793,6 @@ bad: ip->i_effnlink = 0; DIP_ASSIGN(ip, nlink, 0); ip->i_flag |= IN_CHANGE; - if (DOINGSOFTDEP(tvp)) - softdep_change_linkcnt(ip, 0); tvp->v_type = VNON; vput(tvp); diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c index 842e25626..4a1d59fff 100644 --- a/sys/uvm/uvm_swap.c +++ b/sys/uvm/uvm_swap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_swap.c,v 1.168 2023/12/05 15:50:45 claudio Exp $ */ +/* $OpenBSD: uvm_swap.c,v 1.169 2024/02/03 18:51:59 beck Exp $ */ /* $NetBSD: uvm_swap.c,v 1.40 2000/11/17 11:39:39 mrg Exp $ */ /* @@ -1277,7 +1277,6 @@ sw_reg_strategy(struct swapdev *sdp, struct buf *bp, int bn) nbp->vb_buf.b_iodone = sw_reg_iodone; nbp->vb_buf.b_vp = NULLVP; nbp->vb_buf.b_vnbufs.le_next = NOLIST; - LIST_INIT(&nbp->vb_buf.b_dep); /* * set b_dirtyoff/end and b_validoff/end. this is @@ -1863,7 +1862,6 @@ uvm_swap_io(struct vm_page **pps, int startslot, int npages, int flags) bp->b_data = (caddr_t)kva; bp->b_bq = NULL; bp->b_blkno = startblk; - LIST_INIT(&bp->b_dep); s = splbio(); bp->b_vp = NULL; buf_replacevnode(bp, swapdev_vp); diff --git a/usr.bin/openssl/openssl.c b/usr.bin/openssl/openssl.c index e5ff31a2c..7a42b70f2 100644 --- a/usr.bin/openssl/openssl.c +++ b/usr.bin/openssl/openssl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: openssl.c,v 1.35 2023/06/11 13:02:10 jsg Exp $ */ +/* $OpenBSD: openssl.c,v 1.36 2024/02/03 15:58:34 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -211,12 +211,6 @@ FUNCTION functions[] = { #endif /* Message Digests. */ -#ifndef OPENSSL_NO_GOST - { FUNC_TYPE_MD, "gost-mac", dgst_main }, - { FUNC_TYPE_MD, "md_gost94", dgst_main }, - { FUNC_TYPE_MD, "streebog256", dgst_main }, - { FUNC_TYPE_MD, "streebog512", dgst_main }, -#endif #ifndef OPENSSL_NO_MD4 { FUNC_TYPE_MD, "md4", dgst_main }, #endif diff --git a/usr.sbin/bgpd/rde_peer.c b/usr.sbin/bgpd/rde_peer.c index d8a25bfa8..84e952620 100644 --- a/usr.sbin/bgpd/rde_peer.c +++ b/usr.sbin/bgpd/rde_peer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_peer.c,v 1.34 2023/11/07 11:17:35 claudio Exp $ */ +/* $OpenBSD: rde_peer.c,v 1.35 2024/02/03 09:26:52 jsg Exp $ */ /* * Copyright (c) 2019 Claudio Jeker @@ -47,7 +47,7 @@ peer_has_as4byte(struct rde_peer *peer) int peer_has_add_path(struct rde_peer *peer, uint8_t aid, int mode) { - if (aid > AID_MAX) + if (aid >= AID_MAX) return 0; if (aid == AID_UNSPEC) { /* check if at capability is set for at least one AID */ diff --git a/usr.sbin/rpki-client/cert.c b/usr.sbin/rpki-client/cert.c index e528e927a..7e743dc90 100644 --- a/usr.sbin/rpki-client/cert.c +++ b/usr.sbin/rpki-client/cert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cert.c,v 1.123 2024/02/01 15:11:38 tb Exp $ */ +/* $OpenBSD: cert.c,v 1.124 2024/02/03 14:43:15 tb Exp $ */ /* * Copyright (c) 2022 Theo Buehler * Copyright (c) 2021 Job Snijders @@ -737,8 +737,7 @@ struct cert * cert_parse_pre(const char *fn, const unsigned char *der, size_t len) { const unsigned char *oder; - int extsz; - size_t i; + int i; X509 *x = NULL; X509_EXTENSION *ext = NULL; const X509_ALGOR *palg; @@ -810,10 +809,7 @@ cert_parse_pre(const char *fn, const unsigned char *der, size_t len) /* Look for X509v3 extensions. */ - if ((extsz = X509_get_ext_count(x)) < 0) - errx(1, "X509_get_ext_count"); - - for (i = 0; i < (size_t)extsz; i++) { + for (i = 0; i < X509_get_ext_count(x); i++) { ext = X509_get_ext(x, i); assert(ext != NULL); obj = X509_EXTENSION_get_object(ext); @@ -942,7 +938,7 @@ cert_parse_pre(const char *fn, const unsigned char *der, size_t len) p.fn); goto out; } - for (i = 0; i < p.res->asz; i++) { + for (i = 0; (size_t)i < p.res->asz; i++) { if (p.res->as[i].type == CERT_AS_INHERIT) { warnx("%s: inherit elements not allowed in EE" " cert", p.fn); diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 0264ce646..2f472c9a1 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.202 2024/02/01 15:11:38 tb Exp $ */ +/* $OpenBSD: extern.h,v 1.203 2024/02/03 14:30:47 job Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -219,7 +219,6 @@ struct mft { size_t filesz; /* number of filenames */ unsigned int repoid; int talid; - int stale; /* if a stale manifest */ }; /* @@ -527,7 +526,6 @@ enum stype { STYPE_OK, STYPE_FAIL, STYPE_INVALID, - STYPE_STALE, STYPE_BGPSEC, STYPE_TOTAL, STYPE_UNIQUE, @@ -548,7 +546,6 @@ struct repotalstats { uint32_t certs_fail; /* invalid certificate */ uint32_t mfts; /* total number of manifests */ uint32_t mfts_fail; /* failing syntactic parse */ - uint32_t mfts_stale; /* stale manifests */ uint32_t roas; /* route origin authorizations */ uint32_t roas_fail; /* failing syntactic parse */ uint32_t roas_invalid; /* invalid resources */ diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index f91a9d693..94ddc3d1c 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.247 2023/10/13 12:06:49 job Exp $ */ +/* $OpenBSD: main.c,v 1.248 2024/02/03 14:30:47 job Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -621,10 +621,7 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, break; } mft = mft_read(b); - if (!mft->stale) - queue_add_from_mft(mft); - else - repo_stat_inc(rp, talid, type, STYPE_STALE); + queue_add_from_mft(mft); mft_free(mft); break; case RTYPE_CRL: @@ -732,7 +729,6 @@ sum_stats(const struct repo *rp, const struct repotalstats *in, void *arg) out->mfts += in->mfts; out->mfts_fail += in->mfts_fail; - out->mfts_stale += in->mfts_stale; out->certs += in->certs; out->certs_fail += in->certs_fail; out->roas += in->roas; @@ -1451,9 +1447,8 @@ main(int argc, char *argv[]) stats.repo_tal_stats.certs, stats.repo_tal_stats.certs_fail); printf("Trust Anchor Locators: %u (%u invalid)\n", stats.tals, talsz - stats.tals); - printf("Manifests: %u (%u failed parse, %u stale)\n", - stats.repo_tal_stats.mfts, stats.repo_tal_stats.mfts_fail, - stats.repo_tal_stats.mfts_stale); + printf("Manifests: %u (%u failed parse)\n", + stats.repo_tal_stats.mfts, stats.repo_tal_stats.mfts_fail); printf("Certificate revocation lists: %u\n", stats.repo_tal_stats.crls); printf("Ghostbuster records: %u\n", stats.repo_tal_stats.gbrs); printf("Trust Anchor Keys: %u\n", stats.repo_tal_stats.taks); diff --git a/usr.sbin/rpki-client/mft.c b/usr.sbin/rpki-client/mft.c index 57323f0a5..86c29ab7b 100644 --- a/usr.sbin/rpki-client/mft.c +++ b/usr.sbin/rpki-client/mft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mft.c,v 1.103 2024/02/02 19:26:49 job Exp $ */ +/* $OpenBSD: mft.c,v 1.104 2024/02/03 14:30:47 job Exp $ */ /* * Copyright (c) 2022 Theo Buehler * Copyright (c) 2019 Kristaps Dzonsons @@ -342,10 +342,7 @@ mft_parse_econtent(const unsigned char *d, size_t dsz, struct parse *p) /* * Parse the objects that have been published in the manifest. - * This conforms to RFC 6486. - * Note that if the MFT is stale, all referenced objects are stripped - * from the parsed content. - * The MFT content is otherwise returned. + * Return mft if it conforms to RFC 6486, otherwise NULL. */ struct mft * mft_parse(X509 **x509, const char *fn, int talid, const unsigned char *der, @@ -476,7 +473,6 @@ mft_buffer(struct ibuf *b, const struct mft *p) { size_t i; - io_simple_buffer(b, &p->stale, sizeof(p->stale)); io_simple_buffer(b, &p->repoid, sizeof(p->repoid)); io_simple_buffer(b, &p->talid, sizeof(p->talid)); io_str_buffer(b, p->path); @@ -509,7 +505,6 @@ mft_read(struct ibuf *b) if ((p = calloc(1, sizeof(struct mft))) == NULL) err(1, NULL); - io_read_buf(b, &p->stale, sizeof(p->stale)); io_read_buf(b, &p->repoid, sizeof(p->repoid)); io_read_buf(b, &p->talid, sizeof(p->talid)); io_read_str(b, &p->path); diff --git a/usr.sbin/rpki-client/output-json.c b/usr.sbin/rpki-client/output-json.c index ddb8b8cda..eb074ef50 100644 --- a/usr.sbin/rpki-client/output-json.c +++ b/usr.sbin/rpki-client/output-json.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-json.c,v 1.40 2023/06/26 18:39:53 job Exp $ */ +/* $OpenBSD: output-json.c,v 1.41 2024/02/03 14:30:47 job Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * @@ -64,7 +64,6 @@ outputheader_json(struct stats *st) json_do_int("manifests", st->repo_tal_stats.mfts); json_do_int("failedmanifests", st->repo_tal_stats.mfts_fail); - json_do_int("stalemanifests", st->repo_tal_stats.mfts_stale); json_do_int("crls", st->repo_tal_stats.crls); json_do_int("gbrs", st->repo_tal_stats.gbrs); json_do_int("repositories", st->repos); @@ -78,6 +77,9 @@ outputheader_json(struct stats *st) json_do_int("cachedir_del_superfluous_files", st->repo_stats.del_extra_files); + /* XXX: remove in rpki-client 9.0 */ + json_do_int("stalemanifests", 0); + json_do_end(); } diff --git a/usr.sbin/rpki-client/output-ometric.c b/usr.sbin/rpki-client/output-ometric.c index 350cf0294..48713be16 100644 --- a/usr.sbin/rpki-client/output-ometric.c +++ b/usr.sbin/rpki-client/output-ometric.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-ometric.c,v 1.5 2023/06/29 14:33:35 tb Exp $ */ +/* $OpenBSD: output-ometric.c,v 1.6 2024/02/03 14:30:47 job Exp $ */ /* * Copyright (c) 2022 Claudio Jeker * @@ -47,7 +47,9 @@ set_common_stats(const struct repotalstats *in, struct ometric *metric, OKV("type", "state"), OKV("manifest", "valid"), ol); ometric_set_int_with_labels(metric, in->mfts_fail, OKV("type", "state"), OKV("manifest", "failed parse"), ol); - ometric_set_int_with_labels(metric, in->mfts_stale, + + /* XXX: remove in rpki-client 9.0 */ + ometric_set_int_with_labels(metric, 0, OKV("type", "state"), OKV("manifest", "stale"), ol); ometric_set_int_with_labels(metric, in->roas, diff --git a/usr.sbin/rpki-client/output.c b/usr.sbin/rpki-client/output.c index 659476d35..e875698eb 100644 --- a/usr.sbin/rpki-client/output.c +++ b/usr.sbin/rpki-client/output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output.c,v 1.31 2023/04/26 16:32:41 claudio Exp $ */ +/* $OpenBSD: output.c,v 1.32 2024/02/03 14:30:47 job Exp $ */ /* * Copyright (c) 2019 Theo de Raadt * @@ -233,13 +233,12 @@ outputheader(FILE *out, struct stats *st) if (fprintf(out, " ]\n" - "# Manifests: %u (%u failed parse, %u stale)\n" + "# Manifests: %u (%u failed parse)\n" "# Certificate revocation lists: %u\n" "# Ghostbuster records: %u\n" "# Repositories: %u\n" "# VRP Entries: %u (%u unique)\n", st->repo_tal_stats.mfts, st->repo_tal_stats.mfts_fail, - st->repo_tal_stats.mfts_stale, st->repo_tal_stats.crls, st->repo_tal_stats.gbrs, st->repos, diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index 529c3a90b..e1ef9b973 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.126 2024/02/02 22:09:56 tb Exp $ */ +/* $OpenBSD: parser.c,v 1.128 2024/02/03 14:30:47 job Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -314,13 +314,13 @@ proc_parser_mft_pre(struct entity *entp, char *file, struct crl **crl, if (now < mft->thisupdate) { warnx("%s: manifest not yet valid %s", file, time2str(mft->thisupdate)); - mft->stale = 1; + goto err; } /* check that now is not after until */ if (now > mft->nextupdate) { warnx("%s: manifest expired on %s", file, time2str(mft->nextupdate)); - mft->stale = 1; + goto err; } /* if there is nothing to compare to, return now */ @@ -416,9 +416,7 @@ proc_parser_mft(struct entity *entp, struct mft **mp, char **crlfile, warnx("%s: failed fetch, continuing with #%s " "from cache", file2, mft2->seqnum); - if (proc_parser_mft_check(file2, mft2)) { - *mp = mft2; - } else { + if (!proc_parser_mft_check(file2, mft2)) { mft_free(mft2); mft2 = NULL; @@ -434,6 +432,7 @@ proc_parser_mft(struct entity *entp, struct mft **mp, char **crlfile, free(crl1file); free(file1); + *mp = mft2; crl = crl2; file = file2; *crlfile = crl2file; diff --git a/usr.sbin/rpki-client/repo.c b/usr.sbin/rpki-client/repo.c index 28aa13ef9..f1bf22ba5 100644 --- a/usr.sbin/rpki-client/repo.c +++ b/usr.sbin/rpki-client/repo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repo.c,v 1.51 2023/07/20 05:18:31 claudio Exp $ */ +/* $OpenBSD: repo.c,v 1.52 2024/02/03 14:30:47 job Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -1428,8 +1428,6 @@ repo_stat_inc(struct repo *rp, int talid, enum rtype type, enum stype subtype) rp->stats[talid].mfts++; if (subtype == STYPE_FAIL) rp->stats[talid].mfts_fail++; - if (subtype == STYPE_STALE) - rp->stats[talid].mfts_stale++; break; case RTYPE_ROA: switch (subtype) { diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index f6d44673d..2e5297d27 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.297 2024/02/02 20:54:27 millert Exp $ */ +/* $OpenBSD: parse.y,v 1.298 2024/02/03 15:50:00 op Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -670,7 +670,6 @@ dispatcher_local_option dispatcher_local_options dispatcher_local: MBOX { dsp->u.local.is_mbox = 1; - asprintf(&dsp->u.local.command, "/usr/libexec/mail.local -f %%{mbox.from} -- %%{user.username}"); } dispatcher_local_options | MAILDIR { asprintf(&dsp->u.local.command, "/usr/libexec/mail.maildir"); diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index f7965b534..ecf289705 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.348 2024/02/02 22:02:12 gilles Exp $ */ +/* $OpenBSD: smtpd.c,v 1.349 2024/02/03 15:50:00 op Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -1437,6 +1437,9 @@ forkmda(struct mproc *p, uint64_t id, struct deliver *deliver) return; } + if (dsp->u.local.is_mbox && dsp->u.local.command != NULL) + fatalx("serious memory corruption in privileged process"); + if (pipe(pipefd) == -1) { (void)snprintf(ebuf, sizeof ebuf, "pipe: %s", strerror(errno)); m_create(p_dispatcher, IMSG_MDA_DONE, 0, 0, -1); diff --git a/usr.sbin/smtpd/smtpd.conf.5 b/usr.sbin/smtpd/smtpd.conf.5 index 9f2a5f5e3..257ad172d 100644 --- a/usr.sbin/smtpd/smtpd.conf.5 +++ b/usr.sbin/smtpd/smtpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpd.conf.5,v 1.266 2023/12/03 11:52:16 op Exp $ +.\" $OpenBSD: smtpd.conf.5,v 1.268 2024/02/03 20:46:57 jmc Exp $ .\" .\" Copyright (c) 2008 Janne Johansson .\" Copyright (c) 2009 Jacek Masiulaniec @@ -17,7 +17,7 @@ .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .\" -.Dd $Mdocdate: December 3 2023 $ +.Dd $Mdocdate: February 3 2024 $ .Dt SMTPD.CONF 5 .Os .Sh NAME @@ -193,6 +193,10 @@ is in charge of handling delivery for all virtual users. This option is not usable with the .Cm mbox delivery method. +.Pp +Only the delivery user's +.Pa .forward +file will be processed. .It Cm userbase Pf < Ar table Ns > Use the mapping .Ar table diff --git a/usr.sbin/vmd/vionet.c b/usr.sbin/vmd/vionet.c index b973577fa..5f7e146b3 100644 --- a/usr.sbin/vmd/vionet.c +++ b/usr.sbin/vmd/vionet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vionet.c,v 1.8 2024/01/30 23:01:49 dv Exp $ */ +/* $OpenBSD: vionet.c,v 1.9 2024/02/03 21:41:35 dv Exp $ */ /* * Copyright (c) 2023 Dave Voutila @@ -622,7 +622,12 @@ vionet_notifyq(struct virtio_dev *dev) struct vionet_dev *vionet = &dev->vionet; switch (vionet->cfg.queue_notify) { - case TXQ: return vionet_notify_tx(dev); + case RXQ: + event_add(&ev_tap, NULL); + event_add(&ev_inject, NULL); + break; + case TXQ: + return vionet_notify_tx(dev); default: /* * Catch the unimplemented queue ID 2 (control queue) as @@ -1027,16 +1032,10 @@ handle_io_write(struct viodev_msg *msg, struct virtio_dev *dev) vionet->vq[TXQ].last_avail = 0; vionet->vq[TXQ].notified_avail = 0; virtio_deassert_pic_irq(dev, msg->vcpu); + + event_del(&ev_tap); + event_del(&ev_inject); } - event_del(&ev_tap); - event_del(&ev_inject); - if (vionet->cfg.device_status - & VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK) { - event_add(&ev_tap, NULL); - event_add(&ev_inject, NULL); - } - break; - default: break; } return (intr);