Skip to content

Commit 2043b98

Browse files
Ben HillisCopilot
andcommitted
Resolve merge conflicts: bump session error codes to slots 7-8
WSLC_E_CONTAINER_NOT_RUNNING and WSLC_E_CONTAINER_IS_RUNNING took slots 5-6 on the target branch. Move WSLC_E_SESSION_RESERVED and WSLC_E_INVALID_SESSION_NAME to slots 7-8 to avoid collisions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2 parents 65e4d11 + 0d7171d commit 2043b98

File tree

21 files changed

+629
-114
lines changed

21 files changed

+629
-114
lines changed

diagnostics/collect-wsl-logs.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ if ($Dump)
304304
$dumpFolder = Join-Path (Resolve-Path "$folder") dumps
305305
New-Item -ItemType "directory" -Path "$dumpFolder"
306306

307-
$executables = "wsl", "wslservice", "wslhost", "msrdc", "dllhost"
307+
$executables = "wsl", "wslservice", "wslhost", "wslcsession", "wslrelay", "wslg", "msrdc", "dllhost"
308308
foreach($process in Get-Process | Where-Object { $executables -contains $_.ProcessName})
309309
{
310310
$dumpFile = "$dumpFolder/$($process.ProcessName).$($process.Id).dmp"

localization/strings/en-US/Resources.resw

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,18 @@ Usage:
19651965
<value>Unknown command: '{}'</value>
19661966
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
19671967
</data>
1968+
<data name="MessageWslcCannotRemoveRunningContainer" xml:space="preserve">
1969+
<value>Container '{}' is running and cannot be removed. Either stop the container before removing or use forced remove (-f).</value>
1970+
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
1971+
</data>
1972+
<data name="MessageWslcContainerNotRunning" xml:space="preserve">
1973+
<value>Container '{}' is not running.</value>
1974+
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
1975+
</data>
1976+
<data name="MessageWslcContainerIsRunning" xml:space="preserve">
1977+
<value>Container '{}' is running.</value>
1978+
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
1979+
</data>
19681980
<data name="WSLCCLI_UnrecognizedCommandError" xml:space="preserve">
19691981
<value>Unrecognized command: '{}'</value>
19701982
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
@@ -2211,7 +2223,7 @@ For privacy information about this product please visit https://aka.ms/privacy.<
22112223
<value>Run a container.</value>
22122224
</data>
22132225
<data name="WSLCCLI_ContainerRunLongDesc" xml:space="preserve">
2214-
<value>Runs a container. By default, the container is started in the background; use --detach to run in the foreground.</value>
2226+
<value>Runs a container. By default, the container is started in the foreground; use --detach to run in the background.</value>
22152227
<comment>{Locked="--detach "}Command line arguments, file names and string inserts should not be translated</comment>
22162228
</data>
22172229
<data name="WSLCCLI_ContainerStartDesc" xml:space="preserve">

nuget/Microsoft.WSL.Containers.nuspec.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<version>${WSL_NUGET_PACKAGE_VERSION}</version>
66
<authors>Microsoft</authors>
77
<projectUrl>https://github.com/microsoft/WSL</projectUrl>
8-
<description>WSL Containers SDK</description>
8+
<description>WSL Containers SDK (Preview - API subject to breaking changes)</description>
99
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
1010
<tags>WSL</tags>
1111
<language>en-us</language>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# WSL Containers
22

3-
This package contains the `WSLCApi.h` header which defines the WSL Containers interface.
3+
> **⚠️ Preview:** This SDK is currently in preview and is subject to breaking changes
4+
> in future releases without prior notice. Do not rely on API stability for production
5+
> workloads.
6+
7+
This package contains the `wslcsdk.h` header which defines the WSL Containers interface.

src/shared/inc/defs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ Module Name:
1616

1717
#if defined(_MSC_VER)
1818
#define THROW_INVALID_ARG_IF(condition) THROW_HR_IF(E_INVALIDARG, condition)
19+
20+
#define THROW_IF_FAILED_EXCEPT(result, accepted) \
21+
do \
22+
{ \
23+
auto _result = (result); \
24+
if (FAILED(_result) && _result != (accepted)) \
25+
{ \
26+
THROW_HR(_result); \
27+
} \
28+
} while (0)
29+
1930
#elif defined(__GNUC__)
2031
#define THROW_INVALID_ARG_IF(condition) THROW_ERRNO_IF(EINVAL, condition)
2132
#define _stricmp strcasecmp

src/windows/WslcSDK/wslcsdk.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,16 +1263,16 @@ try
12631263
}
12641264
CATCH_RETURN();
12651265

1266-
STDAPI WslcDeleteSessionImage(_In_ WslcSession session, _In_z_ PCSTR NameOrId, _Outptr_opt_result_z_ PWSTR* errorMessage)
1266+
STDAPI WslcDeleteSessionImage(_In_ WslcSession session, _In_z_ PCSTR nameOrId, _Outptr_opt_result_z_ PWSTR* errorMessage)
12671267
try
12681268
{
12691269
ErrorInfoWrapper errorInfoWrapper{errorMessage};
12701270
auto internalType = CheckAndGetInternalType(session);
12711271
RETURN_HR_IF_NULL(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), internalType->session);
1272-
RETURN_HR_IF_NULL(E_POINTER, NameOrId);
1272+
RETURN_HR_IF_NULL(E_POINTER, nameOrId);
12731273

12741274
WSLCDeleteImageOptions options{};
1275-
options.Image = NameOrId;
1275+
options.Image = nameOrId;
12761276
// TODO: Flags? (Force and NoPrune)
12771277

12781278
wil::unique_cotaskmem_array_ptr<WSLCDeletedImageInformation> deletedImageInformation;

src/windows/WslcSDK/wslcsdk.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Module Name:
1010
1111
This file contains the public WSL Container SDK api definitions.
1212
13+
PREVIEW NOTICE: This API is currently in preview and is subject to breaking
14+
changes in future releases without prior notice. Do not rely on API stability
15+
for production workloads. Features, function signatures, and behaviors may
16+
change between releases during the preview period.
17+
1318
--*/
1419
#pragma once
1520
#include <winsock2.h>
@@ -204,7 +209,7 @@ STDAPI WslcReleaseContainer(_In_ WslcContainer container);
204209

205210
#define WSLC_CONTAINER_ID_BUFFER_SIZE 65 // 64 hex chars + null terminator
206211

207-
STDAPI WslcGetContainerID(WslcContainer container, CHAR containerId[WSLC_CONTAINER_ID_BUFFER_SIZE]);
212+
STDAPI WslcGetContainerID(_In_ WslcContainer container, _Out_writes_(WSLC_CONTAINER_ID_BUFFER_SIZE) CHAR containerId[WSLC_CONTAINER_ID_BUFFER_SIZE]);
208213

209214
STDAPI WslcGetContainerInitProcess(_In_ WslcContainer container, _Out_ WslcProcess* initProcess);
210215

@@ -284,7 +289,7 @@ typedef enum WslcProcessIOHandle
284289
// Parameters:
285290
// ioHandle
286291
// The WslcProcessIOHandle that the IO callback is for.
287-
// Only STDOUT and STDERR will recieve callbacks.
292+
// Only STDOUT and STDERR will receive callbacks.
288293
//
289294
// data
290295
// Pointer to a buffer containing the bytes read. The buffer is owned
@@ -450,7 +455,7 @@ typedef struct WslcImageInfo
450455
uint64_t createdTimestamp;
451456
} WslcImageInfo;
452457

453-
STDAPI WslcDeleteSessionImage(_In_ WslcSession session, _In_z_ PCSTR NameOrId, _Outptr_opt_result_z_ PWSTR* errorMessage);
458+
STDAPI WslcDeleteSessionImage(_In_ WslcSession session, _In_z_ PCSTR nameOrId, _Outptr_opt_result_z_ PWSTR* errorMessage);
454459

455460
// Retrieves the list of container images
456461
// Parameters:

src/windows/common/wslutil.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ static const std::map<HRESULT, LPCWSTR> g_commonErrors{
150150
X_WIN32(ERROR_INVALID_STATE),
151151
X(WSLC_E_IMAGE_NOT_FOUND),
152152
X(WSLC_E_CONTAINER_NOT_FOUND),
153+
X(WSLC_E_VOLUME_NOT_FOUND),
154+
X(WSLC_E_CONTAINER_NOT_RUNNING),
155+
X(WSLC_E_CONTAINER_IS_RUNNING),
153156
X(WSLC_E_SESSION_RESERVED),
154157
X(WSLC_E_INVALID_SESSION_NAME),
155158
X_WIN32(RPC_S_SERVER_UNAVAILABLE),

src/windows/inc/docker_schema.h

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -206,34 +206,6 @@ struct InspectExec
206206
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(InspectExec, Pid, ExitCode, Running);
207207
};
208208

209-
struct PruneContainerLabelFilter
210-
{
211-
std::map<std::string, bool> presentLabels;
212-
std::map<std::string, bool> absentLabels;
213-
std::optional<std::uint64_t> until;
214-
};
215-
216-
inline void to_json(nlohmann::json& j, const PruneContainerLabelFilter& object)
217-
{
218-
j = nlohmann::json{};
219-
if (!object.presentLabels.empty())
220-
{
221-
j["label"] = object.presentLabels;
222-
}
223-
224-
if (!object.absentLabels.empty())
225-
{
226-
j["label!"] = object.absentLabels;
227-
}
228-
229-
// This is required because docker crashes if 'until' is null.
230-
// TODO: Open a PR to fix this directly in moby.
231-
if (object.until.has_value())
232-
{
233-
j["until"] = nlohmann::json{{std::to_string(object.until.value()), true}};
234-
}
235-
}
236-
237209
struct PruneContainerResult
238210
{
239211
std::optional<std::vector<std::string>> ContainersDeleted; // Null if no containers were deleted.
@@ -262,6 +234,14 @@ struct DeletedImage
262234
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(DeletedImage, Untagged, Deleted);
263235
};
264236

237+
struct PruneImageResult
238+
{
239+
std::optional<std::vector<DeletedImage>> ImagesDeleted;
240+
uint64_t SpaceReclaimed{};
241+
242+
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(PruneImageResult, ImagesDeleted, SpaceReclaimed);
243+
};
244+
265245
struct ImportStatus
266246
{
267247
std::string status;

src/windows/service/inc/wslc.idl

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,12 @@ typedef struct _WSLCVolumeInformation
560560
char Type[64];
561561
} WSLCVolumeInformation;
562562

563-
typedef struct _WSLCContainerPruneFilter
563+
typedef struct _WSLCPruneLabelFilter
564564
{
565565
LPCSTR Key;
566566
[unique] LPCSTR Value;
567567
BOOL Present;
568-
} WSLCContainerPruneFilter;
568+
} WSLCPruneLabelFilter;
569569

570570
typedef struct _WSLCPruneContainersResults
571571
{
@@ -574,6 +574,26 @@ typedef struct _WSLCPruneContainersResults
574574
ULONGLONG SpaceReclaimed;
575575
} WSLCPruneContainersResults;
576576

577+
typedef enum _WSLCPruneImagesFlags
578+
{
579+
WSLCPruneImagesFlagsNone = 0,
580+
WSLCPruneImagesFlagsDanglingTrue = 1, // Only prune dangling (untagged) images.
581+
WSLCPruneImagesFlagsDanglingFalse = 2, // Prune all images not used by any container.
582+
// Note: If neither dangling flag is set, no dangling filter is passed (Docker defaults to dangling-only).
583+
} WSLCPruneImagesFlags;
584+
585+
cpp_quote("#define WSLCPruneImagesFlagsValid (WSLCPruneImagesFlagsDanglingTrue | WSLCPruneImagesFlagsDanglingFalse)")
586+
587+
cpp_quote("DEFINE_ENUM_FLAG_OPERATORS(WSLCPruneImagesFlags);")
588+
589+
typedef struct _WSLCPruneImagesOptions
590+
{
591+
DWORD Flags; // WSLCPruneImagesFlags
592+
ULONGLONG Until;
593+
[unique, size_is(LabelsCount)] const WSLCPruneLabelFilter* Labels;
594+
ULONG LabelsCount;
595+
} WSLCPruneImagesOptions;
596+
577597
typedef enum _WSLCSessionState
578598
{
579599
WSLCSessionStateRunning = 0,
@@ -615,6 +635,7 @@ interface IWSLCSession : IUnknown
615635
HRESULT DeleteImage([in] const WSLCDeleteImageOptions* Options, [out, size_is(, *Count)] WSLCDeletedImageInformation** DeletedImages, [out] ULONG* Count);
616636
HRESULT TagImage([in] const WSLCTagImageOptions* Options);
617637
HRESULT InspectImage([in] LPCSTR ImageNameOrId, [out] LPSTR* Output);
638+
HRESULT PruneImages([in, unique] const WSLCPruneImagesOptions* Options, [out, size_is(, *DeletedImagesCount)] WSLCDeletedImageInformation** DeletedImages, [out] ULONG* DeletedImagesCount, [out] ULONGLONG* SpaceReclaimed);
618639

619640
// Container management.
620641
HRESULT CreateContainer([in] const WSLCContainerOptions* Options, [out] IWSLCContainer** Container);
@@ -623,7 +644,7 @@ interface IWSLCSession : IUnknown
623644
[out] ULONG* Count,
624645
[out, size_is(, *PortsCount)] WSLCContainerPortMapping** Ports,
625646
[out] ULONG* PortsCount);
626-
HRESULT PruneContainers([in, unique, size_is(FiltersCount)] WSLCContainerPruneFilter* Filters, [in] DWORD FiltersCount, [in] ULONGLONG Until, [out] WSLCPruneContainersResults* Result);
647+
HRESULT PruneContainers([in, unique, size_is(FiltersCount)] WSLCPruneLabelFilter* Filters, [in] DWORD FiltersCount, [in] ULONGLONG Until, [out] WSLCPruneContainersResults* Result);
627648

628649
// Create a process at the VM level. This is meant for debugging.
629650
HRESULT CreateRootNamespaceProcess([in, ref] LPCSTR Executable, [in, ref] const WSLCProcessOptions* Options, [out] IWSLCProcess** Process, [out] int* Errno);
@@ -740,5 +761,7 @@ cpp_quote("#define WSLC_E_IMAGE_NOT_FOUND MAKE_HRESULT(SEVERITY_ERROR, FACILITY_
740761
cpp_quote("#define WSLC_E_CONTAINER_PREFIX_AMBIGUOUS MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 2) /* 0x80040602 */")
741762
cpp_quote("#define WSLC_E_CONTAINER_NOT_FOUND MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 3) /* 0x80040603 */")
742763
cpp_quote("#define WSLC_E_VOLUME_NOT_FOUND MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 4) /* 0x80040604 */")
743-
cpp_quote("#define WSLC_E_SESSION_RESERVED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 5) /* 0x80040605 */")
744-
cpp_quote("#define WSLC_E_INVALID_SESSION_NAME MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 6) /* 0x80040606 */")
764+
cpp_quote("#define WSLC_E_CONTAINER_NOT_RUNNING MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 5) /* 0x80040605 */")
765+
cpp_quote("#define WSLC_E_CONTAINER_IS_RUNNING MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 6) /* 0x80040606 */")
766+
cpp_quote("#define WSLC_E_SESSION_RESERVED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 7) /* 0x80040607 */")
767+
cpp_quote("#define WSLC_E_INVALID_SESSION_NAME MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSLC_E_BASE + 8) /* 0x80040608 */")

0 commit comments

Comments
 (0)